diff --git a/resource-manager/synapse/2021-06-01/bigdatapools/README.md b/resource-manager/synapse/2021-06-01/bigdatapools/README.md new file mode 100644 index 00000000000..706e14f7eb2 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/bigdatapools/README.md @@ -0,0 +1,103 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/synapse/2021-06-01/bigdatapools` Documentation + +The `bigdatapools` SDK allows for interaction with the Azure Resource Manager Service `synapse` (API Version `2021-06-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/synapse/2021-06-01/bigdatapools" +``` + + +### Client Initialization + +```go +client := bigdatapools.NewBigDataPoolsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `BigDataPoolsClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := bigdatapools.NewBigDataPoolID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "bigDataPoolValue") + +payload := bigdatapools.BigDataPoolResourceInfo{ + // ... +} + + +if err := client.CreateOrUpdateThenPoll(ctx, id, payload, bigdatapools.DefaultCreateOrUpdateOperationOptions()); err != nil { + // handle the error +} +``` + + +### Example Usage: `BigDataPoolsClient.Delete` + +```go +ctx := context.TODO() +id := bigdatapools.NewBigDataPoolID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "bigDataPoolValue") + +if err := client.DeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `BigDataPoolsClient.Get` + +```go +ctx := context.TODO() +id := bigdatapools.NewBigDataPoolID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "bigDataPoolValue") + +read, err := client.Get(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `BigDataPoolsClient.ListByWorkspace` + +```go +ctx := context.TODO() +id := bigdatapools.NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue") + +// alternatively `client.ListByWorkspace(ctx, id)` can be used to do batched pagination +items, err := client.ListByWorkspaceComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `BigDataPoolsClient.Update` + +```go +ctx := context.TODO() +id := bigdatapools.NewBigDataPoolID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "bigDataPoolValue") + +payload := bigdatapools.BigDataPoolPatchInfo{ + // ... +} + + +read, err := client.Update(ctx, id, payload) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` diff --git a/resource-manager/synapse/2021-06-01/bigdatapools/client.go b/resource-manager/synapse/2021-06-01/bigdatapools/client.go new file mode 100644 index 00000000000..30e5e16fff7 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/bigdatapools/client.go @@ -0,0 +1,26 @@ +package bigdatapools + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type BigDataPoolsClient struct { + Client *resourcemanager.Client +} + +func NewBigDataPoolsClientWithBaseURI(sdkApi sdkEnv.Api) (*BigDataPoolsClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "bigdatapools", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating BigDataPoolsClient: %+v", err) + } + + return &BigDataPoolsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/synapse/2021-06-01/bigdatapools/constants.go b/resource-manager/synapse/2021-06-01/bigdatapools/constants.go new file mode 100644 index 00000000000..38d5aac84cd --- /dev/null +++ b/resource-manager/synapse/2021-06-01/bigdatapools/constants.go @@ -0,0 +1,154 @@ +package bigdatapools + +import ( + "encoding/json" + "fmt" + "strings" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ConfigurationType string + +const ( + ConfigurationTypeArtifact ConfigurationType = "Artifact" + ConfigurationTypeFile ConfigurationType = "File" +) + +func PossibleValuesForConfigurationType() []string { + return []string{ + string(ConfigurationTypeArtifact), + string(ConfigurationTypeFile), + } +} + +func (s *ConfigurationType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseConfigurationType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseConfigurationType(input string) (*ConfigurationType, error) { + vals := map[string]ConfigurationType{ + "artifact": ConfigurationTypeArtifact, + "file": ConfigurationTypeFile, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ConfigurationType(input) + return &out, nil +} + +type NodeSize string + +const ( + NodeSizeLarge NodeSize = "Large" + NodeSizeMedium NodeSize = "Medium" + NodeSizeNone NodeSize = "None" + NodeSizeSmall NodeSize = "Small" + NodeSizeXLarge NodeSize = "XLarge" + NodeSizeXXLarge NodeSize = "XXLarge" + NodeSizeXXXLarge NodeSize = "XXXLarge" +) + +func PossibleValuesForNodeSize() []string { + return []string{ + string(NodeSizeLarge), + string(NodeSizeMedium), + string(NodeSizeNone), + string(NodeSizeSmall), + string(NodeSizeXLarge), + string(NodeSizeXXLarge), + string(NodeSizeXXXLarge), + } +} + +func (s *NodeSize) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseNodeSize(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseNodeSize(input string) (*NodeSize, error) { + vals := map[string]NodeSize{ + "large": NodeSizeLarge, + "medium": NodeSizeMedium, + "none": NodeSizeNone, + "small": NodeSizeSmall, + "xlarge": NodeSizeXLarge, + "xxlarge": NodeSizeXXLarge, + "xxxlarge": NodeSizeXXXLarge, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := NodeSize(input) + return &out, nil +} + +type NodeSizeFamily string + +const ( + NodeSizeFamilyHardwareAcceleratedFPGA NodeSizeFamily = "HardwareAcceleratedFPGA" + NodeSizeFamilyHardwareAcceleratedGPU NodeSizeFamily = "HardwareAcceleratedGPU" + NodeSizeFamilyMemoryOptimized NodeSizeFamily = "MemoryOptimized" + NodeSizeFamilyNone NodeSizeFamily = "None" +) + +func PossibleValuesForNodeSizeFamily() []string { + return []string{ + string(NodeSizeFamilyHardwareAcceleratedFPGA), + string(NodeSizeFamilyHardwareAcceleratedGPU), + string(NodeSizeFamilyMemoryOptimized), + string(NodeSizeFamilyNone), + } +} + +func (s *NodeSizeFamily) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseNodeSizeFamily(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseNodeSizeFamily(input string) (*NodeSizeFamily, error) { + vals := map[string]NodeSizeFamily{ + "hardwareacceleratedfpga": NodeSizeFamilyHardwareAcceleratedFPGA, + "hardwareacceleratedgpu": NodeSizeFamilyHardwareAcceleratedGPU, + "memoryoptimized": NodeSizeFamilyMemoryOptimized, + "none": NodeSizeFamilyNone, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := NodeSizeFamily(input) + return &out, nil +} diff --git a/resource-manager/synapse/2021-06-01/bigdatapools/id_bigdatapool.go b/resource-manager/synapse/2021-06-01/bigdatapools/id_bigdatapool.go new file mode 100644 index 00000000000..d999500d35b --- /dev/null +++ b/resource-manager/synapse/2021-06-01/bigdatapools/id_bigdatapool.go @@ -0,0 +1,134 @@ +package bigdatapools + +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 = &BigDataPoolId{} + +// BigDataPoolId is a struct representing the Resource ID for a Big Data Pool +type BigDataPoolId struct { + SubscriptionId string + ResourceGroupName string + WorkspaceName string + BigDataPoolName string +} + +// NewBigDataPoolID returns a new BigDataPoolId struct +func NewBigDataPoolID(subscriptionId string, resourceGroupName string, workspaceName string, bigDataPoolName string) BigDataPoolId { + return BigDataPoolId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + WorkspaceName: workspaceName, + BigDataPoolName: bigDataPoolName, + } +} + +// ParseBigDataPoolID parses 'input' into a BigDataPoolId +func ParseBigDataPoolID(input string) (*BigDataPoolId, error) { + parser := resourceids.NewParserFromResourceIdType(&BigDataPoolId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := BigDataPoolId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseBigDataPoolIDInsensitively parses 'input' case-insensitively into a BigDataPoolId +// note: this method should only be used for API response data and not user input +func ParseBigDataPoolIDInsensitively(input string) (*BigDataPoolId, error) { + parser := resourceids.NewParserFromResourceIdType(&BigDataPoolId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := BigDataPoolId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *BigDataPoolId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.WorkspaceName, ok = input.Parsed["workspaceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "workspaceName", input) + } + + if id.BigDataPoolName, ok = input.Parsed["bigDataPoolName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "bigDataPoolName", input) + } + + return nil +} + +// ValidateBigDataPoolID checks that 'input' can be parsed as a Big Data Pool ID +func ValidateBigDataPoolID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseBigDataPoolID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Big Data Pool ID +func (id BigDataPoolId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Synapse/workspaces/%s/bigDataPools/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.WorkspaceName, id.BigDataPoolName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Big Data Pool ID +func (id BigDataPoolId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftSynapse", "Microsoft.Synapse", "Microsoft.Synapse"), + resourceids.StaticSegment("staticWorkspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceName", "workspaceValue"), + resourceids.StaticSegment("staticBigDataPools", "bigDataPools", "bigDataPools"), + resourceids.UserSpecifiedSegment("bigDataPoolName", "bigDataPoolValue"), + } +} + +// String returns a human-readable description of this Big Data Pool ID +func (id BigDataPoolId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Workspace Name: %q", id.WorkspaceName), + fmt.Sprintf("Big Data Pool Name: %q", id.BigDataPoolName), + } + return fmt.Sprintf("Big Data Pool (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/synapse/2021-06-01/bigdatapools/id_bigdatapool_test.go b/resource-manager/synapse/2021-06-01/bigdatapools/id_bigdatapool_test.go new file mode 100644 index 00000000000..0d880bda013 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/bigdatapools/id_bigdatapool_test.go @@ -0,0 +1,327 @@ +package bigdatapools + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &BigDataPoolId{} + +func TestNewBigDataPoolID(t *testing.T) { + id := NewBigDataPoolID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "bigDataPoolValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.WorkspaceName != "workspaceValue" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceName'", id.WorkspaceName, "workspaceValue") + } + + if id.BigDataPoolName != "bigDataPoolValue" { + t.Fatalf("Expected %q but got %q for Segment 'BigDataPoolName'", id.BigDataPoolName, "bigDataPoolValue") + } +} + +func TestFormatBigDataPoolID(t *testing.T) { + actual := NewBigDataPoolID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "bigDataPoolValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/bigDataPools/bigDataPoolValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseBigDataPoolID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *BigDataPoolId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/bigDataPools", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/bigDataPools/bigDataPoolValue", + Expected: &BigDataPoolId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + BigDataPoolName: "bigDataPoolValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/bigDataPools/bigDataPoolValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseBigDataPoolID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + if actual.BigDataPoolName != v.Expected.BigDataPoolName { + t.Fatalf("Expected %q but got %q for BigDataPoolName", v.Expected.BigDataPoolName, actual.BigDataPoolName) + } + + } +} + +func TestParseBigDataPoolIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *BigDataPoolId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/bigDataPools", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/bIgDaTaPoOlS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/bigDataPools/bigDataPoolValue", + Expected: &BigDataPoolId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + BigDataPoolName: "bigDataPoolValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/bigDataPools/bigDataPoolValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/bIgDaTaPoOlS/bIgDaTaPoOlVaLuE", + Expected: &BigDataPoolId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + WorkspaceName: "wOrKsPaCeVaLuE", + BigDataPoolName: "bIgDaTaPoOlVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/bIgDaTaPoOlS/bIgDaTaPoOlVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseBigDataPoolIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + if actual.BigDataPoolName != v.Expected.BigDataPoolName { + t.Fatalf("Expected %q but got %q for BigDataPoolName", v.Expected.BigDataPoolName, actual.BigDataPoolName) + } + + } +} + +func TestSegmentsForBigDataPoolId(t *testing.T) { + segments := BigDataPoolId{}.Segments() + if len(segments) == 0 { + t.Fatalf("BigDataPoolId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/synapse/2021-06-01/bigdatapools/id_workspace.go b/resource-manager/synapse/2021-06-01/bigdatapools/id_workspace.go new file mode 100644 index 00000000000..10d7c169d05 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/bigdatapools/id_workspace.go @@ -0,0 +1,125 @@ +package bigdatapools + +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 = &WorkspaceId{} + +// WorkspaceId is a struct representing the Resource ID for a Workspace +type WorkspaceId struct { + SubscriptionId string + ResourceGroupName string + WorkspaceName string +} + +// NewWorkspaceID returns a new WorkspaceId struct +func NewWorkspaceID(subscriptionId string, resourceGroupName string, workspaceName string) WorkspaceId { + return WorkspaceId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + WorkspaceName: workspaceName, + } +} + +// ParseWorkspaceID parses 'input' into a WorkspaceId +func ParseWorkspaceID(input string) (*WorkspaceId, error) { + parser := resourceids.NewParserFromResourceIdType(&WorkspaceId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := WorkspaceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseWorkspaceIDInsensitively parses 'input' case-insensitively into a WorkspaceId +// note: this method should only be used for API response data and not user input +func ParseWorkspaceIDInsensitively(input string) (*WorkspaceId, error) { + parser := resourceids.NewParserFromResourceIdType(&WorkspaceId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := WorkspaceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *WorkspaceId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.WorkspaceName, ok = input.Parsed["workspaceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "workspaceName", input) + } + + return nil +} + +// ValidateWorkspaceID checks that 'input' can be parsed as a Workspace ID +func ValidateWorkspaceID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseWorkspaceID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Workspace ID +func (id WorkspaceId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Synapse/workspaces/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.WorkspaceName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Workspace ID +func (id WorkspaceId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftSynapse", "Microsoft.Synapse", "Microsoft.Synapse"), + resourceids.StaticSegment("staticWorkspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceName", "workspaceValue"), + } +} + +// String returns a human-readable description of this Workspace ID +func (id WorkspaceId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Workspace Name: %q", id.WorkspaceName), + } + return fmt.Sprintf("Workspace (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/synapse/2021-06-01/bigdatapools/id_workspace_test.go b/resource-manager/synapse/2021-06-01/bigdatapools/id_workspace_test.go new file mode 100644 index 00000000000..a81c6ef4f51 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/bigdatapools/id_workspace_test.go @@ -0,0 +1,282 @@ +package bigdatapools + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &WorkspaceId{} + +func TestNewWorkspaceID(t *testing.T) { + id := NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.WorkspaceName != "workspaceValue" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceName'", id.WorkspaceName, "workspaceValue") + } +} + +func TestFormatWorkspaceID(t *testing.T) { + actual := NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseWorkspaceID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkspaceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue", + Expected: &WorkspaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkspaceID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + } +} + +func TestParseWorkspaceIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkspaceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue", + Expected: &WorkspaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE", + Expected: &WorkspaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + WorkspaceName: "wOrKsPaCeVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkspaceIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + } +} + +func TestSegmentsForWorkspaceId(t *testing.T) { + segments := WorkspaceId{}.Segments() + if len(segments) == 0 { + t.Fatalf("WorkspaceId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/synapse/2021-06-01/bigdatapools/method_createorupdate.go b/resource-manager/synapse/2021-06-01/bigdatapools/method_createorupdate.go new file mode 100644 index 00000000000..10d64aeb44f --- /dev/null +++ b/resource-manager/synapse/2021-06-01/bigdatapools/method_createorupdate.go @@ -0,0 +1,103 @@ +package bigdatapools + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOrUpdateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *BigDataPoolResourceInfo +} + +type CreateOrUpdateOperationOptions struct { + Force *bool +} + +func DefaultCreateOrUpdateOperationOptions() CreateOrUpdateOperationOptions { + return CreateOrUpdateOperationOptions{} +} + +func (o CreateOrUpdateOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o CreateOrUpdateOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o CreateOrUpdateOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Force != nil { + out.Append("force", fmt.Sprintf("%v", *o.Force)) + } + return &out +} + +// CreateOrUpdate ... +func (c BigDataPoolsClient) CreateOrUpdate(ctx context.Context, id BigDataPoolId, input BigDataPoolResourceInfo, options CreateOrUpdateOperationOptions) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + OptionsObject: options, + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// CreateOrUpdateThenPoll performs CreateOrUpdate then polls until it's completed +func (c BigDataPoolsClient) CreateOrUpdateThenPoll(ctx context.Context, id BigDataPoolId, input BigDataPoolResourceInfo, options CreateOrUpdateOperationOptions) error { + result, err := c.CreateOrUpdate(ctx, id, input, options) + if err != nil { + return fmt.Errorf("performing CreateOrUpdate: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after CreateOrUpdate: %+v", err) + } + + return nil +} diff --git a/resource-manager/synapse/2021-06-01/bigdatapools/method_delete.go b/resource-manager/synapse/2021-06-01/bigdatapools/method_delete.go new file mode 100644 index 00000000000..a3eac0d5ab6 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/bigdatapools/method_delete.go @@ -0,0 +1,72 @@ +package bigdatapools + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *BigDataPoolResourceInfo +} + +// Delete ... +func (c BigDataPoolsClient) Delete(ctx context.Context, id BigDataPoolId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// DeleteThenPoll performs Delete then polls until it's completed +func (c BigDataPoolsClient) DeleteThenPoll(ctx context.Context, id BigDataPoolId) error { + result, err := c.Delete(ctx, id) + if err != nil { + return fmt.Errorf("performing Delete: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after Delete: %+v", err) + } + + return nil +} diff --git a/resource-manager/synapse/2021-06-01/bigdatapools/method_get.go b/resource-manager/synapse/2021-06-01/bigdatapools/method_get.go new file mode 100644 index 00000000000..22cb8344536 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/bigdatapools/method_get.go @@ -0,0 +1,51 @@ +package bigdatapools + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *BigDataPoolResourceInfo +} + +// Get ... +func (c BigDataPoolsClient) Get(ctx context.Context, id BigDataPoolId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/synapse/2021-06-01/bigdatapools/method_listbyworkspace.go b/resource-manager/synapse/2021-06-01/bigdatapools/method_listbyworkspace.go new file mode 100644 index 00000000000..9655bdb8212 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/bigdatapools/method_listbyworkspace.go @@ -0,0 +1,91 @@ +package bigdatapools + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListByWorkspaceOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]BigDataPoolResourceInfo +} + +type ListByWorkspaceCompleteResult struct { + LatestHttpResponse *http.Response + Items []BigDataPoolResourceInfo +} + +// ListByWorkspace ... +func (c BigDataPoolsClient) ListByWorkspace(ctx context.Context, id WorkspaceId) (result ListByWorkspaceOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/bigDataPools", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]BigDataPoolResourceInfo `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByWorkspaceComplete retrieves all the results into a single object +func (c BigDataPoolsClient) ListByWorkspaceComplete(ctx context.Context, id WorkspaceId) (ListByWorkspaceCompleteResult, error) { + return c.ListByWorkspaceCompleteMatchingPredicate(ctx, id, BigDataPoolResourceInfoOperationPredicate{}) +} + +// ListByWorkspaceCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c BigDataPoolsClient) ListByWorkspaceCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, predicate BigDataPoolResourceInfoOperationPredicate) (result ListByWorkspaceCompleteResult, err error) { + items := make([]BigDataPoolResourceInfo, 0) + + resp, err := c.ListByWorkspace(ctx, id) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByWorkspaceCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/synapse/2021-06-01/bigdatapools/method_update.go b/resource-manager/synapse/2021-06-01/bigdatapools/method_update.go new file mode 100644 index 00000000000..893bd725301 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/bigdatapools/method_update.go @@ -0,0 +1,55 @@ +package bigdatapools + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type UpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *BigDataPoolResourceInfo +} + +// Update ... +func (c BigDataPoolsClient) Update(ctx context.Context, id BigDataPoolId, input BigDataPoolPatchInfo) (result UpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPatch, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/synapse/2021-06-01/bigdatapools/model_autopauseproperties.go b/resource-manager/synapse/2021-06-01/bigdatapools/model_autopauseproperties.go new file mode 100644 index 00000000000..5d3ee3623d6 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/bigdatapools/model_autopauseproperties.go @@ -0,0 +1,9 @@ +package bigdatapools + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AutoPauseProperties struct { + DelayInMinutes *int64 `json:"delayInMinutes,omitempty"` + Enabled *bool `json:"enabled,omitempty"` +} diff --git a/resource-manager/synapse/2021-06-01/bigdatapools/model_autoscaleproperties.go b/resource-manager/synapse/2021-06-01/bigdatapools/model_autoscaleproperties.go new file mode 100644 index 00000000000..d8f89801277 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/bigdatapools/model_autoscaleproperties.go @@ -0,0 +1,10 @@ +package bigdatapools + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AutoScaleProperties struct { + Enabled *bool `json:"enabled,omitempty"` + MaxNodeCount *int64 `json:"maxNodeCount,omitempty"` + MinNodeCount *int64 `json:"minNodeCount,omitempty"` +} diff --git a/resource-manager/synapse/2021-06-01/bigdatapools/model_bigdatapoolpatchinfo.go b/resource-manager/synapse/2021-06-01/bigdatapools/model_bigdatapoolpatchinfo.go new file mode 100644 index 00000000000..2663aa973d1 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/bigdatapools/model_bigdatapoolpatchinfo.go @@ -0,0 +1,8 @@ +package bigdatapools + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type BigDataPoolPatchInfo struct { + Tags *map[string]string `json:"tags,omitempty"` +} diff --git a/resource-manager/synapse/2021-06-01/bigdatapools/model_bigdatapoolresourceinfo.go b/resource-manager/synapse/2021-06-01/bigdatapools/model_bigdatapoolresourceinfo.go new file mode 100644 index 00000000000..4cd84c64887 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/bigdatapools/model_bigdatapoolresourceinfo.go @@ -0,0 +1,13 @@ +package bigdatapools + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type BigDataPoolResourceInfo struct { + Id *string `json:"id,omitempty"` + Location string `json:"location"` + Name *string `json:"name,omitempty"` + Properties *BigDataPoolResourceProperties `json:"properties,omitempty"` + Tags *map[string]string `json:"tags,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/synapse/2021-06-01/bigdatapools/model_bigdatapoolresourceproperties.go b/resource-manager/synapse/2021-06-01/bigdatapools/model_bigdatapoolresourceproperties.go new file mode 100644 index 00000000000..f67610c4016 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/bigdatapools/model_bigdatapoolresourceproperties.go @@ -0,0 +1,56 @@ +package bigdatapools + +import ( + "time" + + "github.com/hashicorp/go-azure-helpers/lang/dates" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type BigDataPoolResourceProperties struct { + AutoPause *AutoPauseProperties `json:"autoPause,omitempty"` + AutoScale *AutoScaleProperties `json:"autoScale,omitempty"` + CacheSize *int64 `json:"cacheSize,omitempty"` + CreationDate *string `json:"creationDate,omitempty"` + CustomLibraries *[]LibraryInfo `json:"customLibraries,omitempty"` + DefaultSparkLogFolder *string `json:"defaultSparkLogFolder,omitempty"` + DynamicExecutorAllocation *DynamicExecutorAllocation `json:"dynamicExecutorAllocation,omitempty"` + IsAutotuneEnabled *bool `json:"isAutotuneEnabled,omitempty"` + IsComputeIsolationEnabled *bool `json:"isComputeIsolationEnabled,omitempty"` + LastSucceededTimestamp *string `json:"lastSucceededTimestamp,omitempty"` + LibraryRequirements *LibraryRequirements `json:"libraryRequirements,omitempty"` + NodeCount *int64 `json:"nodeCount,omitempty"` + NodeSize *NodeSize `json:"nodeSize,omitempty"` + NodeSizeFamily *NodeSizeFamily `json:"nodeSizeFamily,omitempty"` + ProvisioningState *string `json:"provisioningState,omitempty"` + SessionLevelPackagesEnabled *bool `json:"sessionLevelPackagesEnabled,omitempty"` + SparkConfigProperties *SparkConfigProperties `json:"sparkConfigProperties,omitempty"` + SparkEventsFolder *string `json:"sparkEventsFolder,omitempty"` + SparkVersion *string `json:"sparkVersion,omitempty"` +} + +func (o *BigDataPoolResourceProperties) GetCreationDateAsTime() (*time.Time, error) { + if o.CreationDate == nil { + return nil, nil + } + return dates.ParseAsFormat(o.CreationDate, "2006-01-02T15:04:05Z07:00") +} + +func (o *BigDataPoolResourceProperties) SetCreationDateAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.CreationDate = &formatted +} + +func (o *BigDataPoolResourceProperties) GetLastSucceededTimestampAsTime() (*time.Time, error) { + if o.LastSucceededTimestamp == nil { + return nil, nil + } + return dates.ParseAsFormat(o.LastSucceededTimestamp, "2006-01-02T15:04:05Z07:00") +} + +func (o *BigDataPoolResourceProperties) SetLastSucceededTimestampAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.LastSucceededTimestamp = &formatted +} diff --git a/resource-manager/synapse/2021-06-01/bigdatapools/model_dynamicexecutorallocation.go b/resource-manager/synapse/2021-06-01/bigdatapools/model_dynamicexecutorallocation.go new file mode 100644 index 00000000000..d713c7c2a57 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/bigdatapools/model_dynamicexecutorallocation.go @@ -0,0 +1,10 @@ +package bigdatapools + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DynamicExecutorAllocation struct { + Enabled *bool `json:"enabled,omitempty"` + MaxExecutors *int64 `json:"maxExecutors,omitempty"` + MinExecutors *int64 `json:"minExecutors,omitempty"` +} diff --git a/resource-manager/synapse/2021-06-01/bigdatapools/model_libraryinfo.go b/resource-manager/synapse/2021-06-01/bigdatapools/model_libraryinfo.go new file mode 100644 index 00000000000..70691f95e1e --- /dev/null +++ b/resource-manager/synapse/2021-06-01/bigdatapools/model_libraryinfo.go @@ -0,0 +1,32 @@ +package bigdatapools + +import ( + "time" + + "github.com/hashicorp/go-azure-helpers/lang/dates" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type LibraryInfo struct { + ContainerName *string `json:"containerName,omitempty"` + CreatorId *string `json:"creatorId,omitempty"` + Name *string `json:"name,omitempty"` + Path *string `json:"path,omitempty"` + ProvisioningStatus *string `json:"provisioningStatus,omitempty"` + Type *string `json:"type,omitempty"` + UploadedTimestamp *string `json:"uploadedTimestamp,omitempty"` +} + +func (o *LibraryInfo) GetUploadedTimestampAsTime() (*time.Time, error) { + if o.UploadedTimestamp == nil { + return nil, nil + } + return dates.ParseAsFormat(o.UploadedTimestamp, "2006-01-02T15:04:05Z07:00") +} + +func (o *LibraryInfo) SetUploadedTimestampAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.UploadedTimestamp = &formatted +} diff --git a/resource-manager/synapse/2021-06-01/bigdatapools/model_libraryrequirements.go b/resource-manager/synapse/2021-06-01/bigdatapools/model_libraryrequirements.go new file mode 100644 index 00000000000..d388a5d06bd --- /dev/null +++ b/resource-manager/synapse/2021-06-01/bigdatapools/model_libraryrequirements.go @@ -0,0 +1,28 @@ +package bigdatapools + +import ( + "time" + + "github.com/hashicorp/go-azure-helpers/lang/dates" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type LibraryRequirements struct { + Content *string `json:"content,omitempty"` + Filename *string `json:"filename,omitempty"` + Time *string `json:"time,omitempty"` +} + +func (o *LibraryRequirements) GetTimeAsTime() (*time.Time, error) { + if o.Time == nil { + return nil, nil + } + return dates.ParseAsFormat(o.Time, "2006-01-02T15:04:05Z07:00") +} + +func (o *LibraryRequirements) SetTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.Time = &formatted +} diff --git a/resource-manager/synapse/2021-06-01/bigdatapools/model_sparkconfigproperties.go b/resource-manager/synapse/2021-06-01/bigdatapools/model_sparkconfigproperties.go new file mode 100644 index 00000000000..01eccd0d476 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/bigdatapools/model_sparkconfigproperties.go @@ -0,0 +1,29 @@ +package bigdatapools + +import ( + "time" + + "github.com/hashicorp/go-azure-helpers/lang/dates" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SparkConfigProperties struct { + ConfigurationType *ConfigurationType `json:"configurationType,omitempty"` + Content *string `json:"content,omitempty"` + Filename *string `json:"filename,omitempty"` + Time *string `json:"time,omitempty"` +} + +func (o *SparkConfigProperties) GetTimeAsTime() (*time.Time, error) { + if o.Time == nil { + return nil, nil + } + return dates.ParseAsFormat(o.Time, "2006-01-02T15:04:05Z07:00") +} + +func (o *SparkConfigProperties) SetTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.Time = &formatted +} diff --git a/resource-manager/synapse/2021-06-01/bigdatapools/predicates.go b/resource-manager/synapse/2021-06-01/bigdatapools/predicates.go new file mode 100644 index 00000000000..3033495921f --- /dev/null +++ b/resource-manager/synapse/2021-06-01/bigdatapools/predicates.go @@ -0,0 +1,32 @@ +package bigdatapools + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type BigDataPoolResourceInfoOperationPredicate struct { + Id *string + Location *string + Name *string + Type *string +} + +func (p BigDataPoolResourceInfoOperationPredicate) Matches(input BigDataPoolResourceInfo) bool { + + if p.Id != nil && (input.Id == nil || *p.Id != *input.Id) { + return false + } + + if p.Location != nil && *p.Location != input.Location { + return false + } + + if p.Name != nil && (input.Name == nil || *p.Name != *input.Name) { + return false + } + + if p.Type != nil && (input.Type == nil || *p.Type != *input.Type) { + return false + } + + return true +} diff --git a/resource-manager/synapse/2021-06-01/bigdatapools/version.go b/resource-manager/synapse/2021-06-01/bigdatapools/version.go new file mode 100644 index 00000000000..77b7fbc7f8d --- /dev/null +++ b/resource-manager/synapse/2021-06-01/bigdatapools/version.go @@ -0,0 +1,12 @@ +package bigdatapools + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2021-06-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/bigdatapools/%s", defaultApiVersion) +} diff --git a/resource-manager/synapse/2021-06-01/client.go b/resource-manager/synapse/2021-06-01/client.go new file mode 100644 index 00000000000..8e2d39b6655 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/client.go @@ -0,0 +1,505 @@ +package v2021_06_01 + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/resource-manager/synapse/2021-06-01/bigdatapools" + "github.com/hashicorp/go-azure-sdk/resource-manager/synapse/2021-06-01/databasevulnerabilityassesmentrulebaselines" + "github.com/hashicorp/go-azure-sdk/resource-manager/synapse/2021-06-01/integrationruntime" + "github.com/hashicorp/go-azure-sdk/resource-manager/synapse/2021-06-01/integrationruntimes" + "github.com/hashicorp/go-azure-sdk/resource-manager/synapse/2021-06-01/ipfirewallrules" + "github.com/hashicorp/go-azure-sdk/resource-manager/synapse/2021-06-01/keys" + "github.com/hashicorp/go-azure-sdk/resource-manager/synapse/2021-06-01/libraries" + "github.com/hashicorp/go-azure-sdk/resource-manager/synapse/2021-06-01/operations" + "github.com/hashicorp/go-azure-sdk/resource-manager/synapse/2021-06-01/privateendpointconnections" + "github.com/hashicorp/go-azure-sdk/resource-manager/synapse/2021-06-01/privatelinkhubprivatelinkresources" + "github.com/hashicorp/go-azure-sdk/resource-manager/synapse/2021-06-01/privatelinkhubs" + "github.com/hashicorp/go-azure-sdk/resource-manager/synapse/2021-06-01/privatelinkresources" + "github.com/hashicorp/go-azure-sdk/resource-manager/synapse/2021-06-01/recoverablesqlpools" + "github.com/hashicorp/go-azure-sdk/resource-manager/synapse/2021-06-01/restorabledroppedsqlpools" + "github.com/hashicorp/go-azure-sdk/resource-manager/synapse/2021-06-01/sensitivitylabels" + "github.com/hashicorp/go-azure-sdk/resource-manager/synapse/2021-06-01/sqlpools" + "github.com/hashicorp/go-azure-sdk/resource-manager/synapse/2021-06-01/sqlpoolsbackup" + "github.com/hashicorp/go-azure-sdk/resource-manager/synapse/2021-06-01/sqlpoolsblobauditing" + "github.com/hashicorp/go-azure-sdk/resource-manager/synapse/2021-06-01/sqlpoolsconnectionpolicies" + "github.com/hashicorp/go-azure-sdk/resource-manager/synapse/2021-06-01/sqlpoolsdatabasevulnerabilityassesmentrulebaselines" + "github.com/hashicorp/go-azure-sdk/resource-manager/synapse/2021-06-01/sqlpoolsdatamaskingpolicies" + "github.com/hashicorp/go-azure-sdk/resource-manager/synapse/2021-06-01/sqlpoolsdatamaskingrules" + "github.com/hashicorp/go-azure-sdk/resource-manager/synapse/2021-06-01/sqlpoolsgeobackuppolicies" + "github.com/hashicorp/go-azure-sdk/resource-manager/synapse/2021-06-01/sqlpoolsmaintenancewindowoptions" + "github.com/hashicorp/go-azure-sdk/resource-manager/synapse/2021-06-01/sqlpoolsmaintenancewindows" + "github.com/hashicorp/go-azure-sdk/resource-manager/synapse/2021-06-01/sqlpoolsoperations" + "github.com/hashicorp/go-azure-sdk/resource-manager/synapse/2021-06-01/sqlpoolsreplicationlinks" + "github.com/hashicorp/go-azure-sdk/resource-manager/synapse/2021-06-01/sqlpoolsrestorepoints" + "github.com/hashicorp/go-azure-sdk/resource-manager/synapse/2021-06-01/sqlpoolsschemas" + "github.com/hashicorp/go-azure-sdk/resource-manager/synapse/2021-06-01/sqlpoolssecurityalertpolicies" + "github.com/hashicorp/go-azure-sdk/resource-manager/synapse/2021-06-01/sqlpoolssensitivitylabels" + "github.com/hashicorp/go-azure-sdk/resource-manager/synapse/2021-06-01/sqlpoolssqlpoolcolumns" + "github.com/hashicorp/go-azure-sdk/resource-manager/synapse/2021-06-01/sqlpoolssqlpoolschemas" + "github.com/hashicorp/go-azure-sdk/resource-manager/synapse/2021-06-01/sqlpoolssqlpooltables" + "github.com/hashicorp/go-azure-sdk/resource-manager/synapse/2021-06-01/sqlpoolssqlpooluseractivities" + "github.com/hashicorp/go-azure-sdk/resource-manager/synapse/2021-06-01/sqlpoolssqlpoolvulnerabilityassesmentrulebaselines" + "github.com/hashicorp/go-azure-sdk/resource-manager/synapse/2021-06-01/sqlpoolssqlpoolvulnerabilityassessmentscans" + "github.com/hashicorp/go-azure-sdk/resource-manager/synapse/2021-06-01/sqlpoolstables" + "github.com/hashicorp/go-azure-sdk/resource-manager/synapse/2021-06-01/sqlpoolstransparentdataencryption" + "github.com/hashicorp/go-azure-sdk/resource-manager/synapse/2021-06-01/sqlpoolsusages" + "github.com/hashicorp/go-azure-sdk/resource-manager/synapse/2021-06-01/sqlpoolsvulnerabilityassessments" + "github.com/hashicorp/go-azure-sdk/resource-manager/synapse/2021-06-01/sqlpoolsvulnerabilityassessmentscansexecute" + "github.com/hashicorp/go-azure-sdk/resource-manager/synapse/2021-06-01/sqlpoolsvulnerabilityassessmentscansexport" + "github.com/hashicorp/go-azure-sdk/resource-manager/synapse/2021-06-01/sqlpoolsworkloadclassifiers" + "github.com/hashicorp/go-azure-sdk/resource-manager/synapse/2021-06-01/sqlpoolsworkloadgroups" + "github.com/hashicorp/go-azure-sdk/resource-manager/synapse/2021-06-01/workspaceazureadonlyauthentications" + "github.com/hashicorp/go-azure-sdk/resource-manager/synapse/2021-06-01/workspacemanagedsqlserver" + "github.com/hashicorp/go-azure-sdk/resource-manager/synapse/2021-06-01/workspacemanagedsqlserverblobauditing" + "github.com/hashicorp/go-azure-sdk/resource-manager/synapse/2021-06-01/workspacemanagedsqlserverdedicatedsqlminimaltlssettings" + "github.com/hashicorp/go-azure-sdk/resource-manager/synapse/2021-06-01/workspacemanagedsqlserversecurityalertpolicies" + "github.com/hashicorp/go-azure-sdk/resource-manager/synapse/2021-06-01/workspacemanagedsqlserverserverencryptionprotector" + "github.com/hashicorp/go-azure-sdk/resource-manager/synapse/2021-06-01/workspacemanagedsqlserverservervulnerabilityassessments" + "github.com/hashicorp/go-azure-sdk/resource-manager/synapse/2021-06-01/workspacemanagedsqlserversqlusages" + "github.com/hashicorp/go-azure-sdk/resource-manager/synapse/2021-06-01/workspaces" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +type Client struct { + BigDataPools *bigdatapools.BigDataPoolsClient + DatabaseVulnerabilityAssesmentRuleBaselines *databasevulnerabilityassesmentrulebaselines.DatabaseVulnerabilityAssesmentRuleBaselinesClient + IPFirewallRules *ipfirewallrules.IPFirewallRulesClient + IntegrationRuntime *integrationruntime.IntegrationRuntimeClient + IntegrationRuntimes *integrationruntimes.IntegrationRuntimesClient + Keys *keys.KeysClient + Libraries *libraries.LibrariesClient + Operations *operations.OperationsClient + PrivateEndpointConnections *privateendpointconnections.PrivateEndpointConnectionsClient + PrivateLinkHubPrivateLinkResources *privatelinkhubprivatelinkresources.PrivateLinkHubPrivateLinkResourcesClient + PrivateLinkHubs *privatelinkhubs.PrivateLinkHubsClient + PrivateLinkResources *privatelinkresources.PrivateLinkResourcesClient + RecoverableSqlPools *recoverablesqlpools.RecoverableSqlPoolsClient + RestorableDroppedSqlPools *restorabledroppedsqlpools.RestorableDroppedSqlPoolsClient + SensitivityLabels *sensitivitylabels.SensitivityLabelsClient + SqlPools *sqlpools.SqlPoolsClient + SqlPoolsBackup *sqlpoolsbackup.SqlPoolsBackupClient + SqlPoolsBlobAuditing *sqlpoolsblobauditing.SqlPoolsBlobAuditingClient + SqlPoolsConnectionPolicies *sqlpoolsconnectionpolicies.SqlPoolsConnectionPoliciesClient + SqlPoolsDataMaskingPolicies *sqlpoolsdatamaskingpolicies.SqlPoolsDataMaskingPoliciesClient + SqlPoolsDataMaskingRules *sqlpoolsdatamaskingrules.SqlPoolsDataMaskingRulesClient + SqlPoolsDatabaseVulnerabilityAssesmentRuleBaselines *sqlpoolsdatabasevulnerabilityassesmentrulebaselines.SqlPoolsDatabaseVulnerabilityAssesmentRuleBaselinesClient + SqlPoolsGeoBackupPolicies *sqlpoolsgeobackuppolicies.SqlPoolsGeoBackupPoliciesClient + SqlPoolsMaintenanceWindowOptions *sqlpoolsmaintenancewindowoptions.SqlPoolsMaintenanceWindowOptionsClient + SqlPoolsMaintenanceWindows *sqlpoolsmaintenancewindows.SqlPoolsMaintenanceWindowsClient + SqlPoolsOperations *sqlpoolsoperations.SqlPoolsOperationsClient + SqlPoolsReplicationLinks *sqlpoolsreplicationlinks.SqlPoolsReplicationLinksClient + SqlPoolsRestorePoints *sqlpoolsrestorepoints.SqlPoolsRestorePointsClient + SqlPoolsSchemas *sqlpoolsschemas.SqlPoolsSchemasClient + SqlPoolsSecurityAlertPolicies *sqlpoolssecurityalertpolicies.SqlPoolsSecurityAlertPoliciesClient + SqlPoolsSensitivityLabels *sqlpoolssensitivitylabels.SqlPoolsSensitivityLabelsClient + SqlPoolsSqlPoolColumns *sqlpoolssqlpoolcolumns.SqlPoolsSqlPoolColumnsClient + SqlPoolsSqlPoolSchemas *sqlpoolssqlpoolschemas.SqlPoolsSqlPoolSchemasClient + SqlPoolsSqlPoolTables *sqlpoolssqlpooltables.SqlPoolsSqlPoolTablesClient + SqlPoolsSqlPoolUserActivities *sqlpoolssqlpooluseractivities.SqlPoolsSqlPoolUserActivitiesClient + SqlPoolsSqlPoolVulnerabilityAssesmentRuleBaselines *sqlpoolssqlpoolvulnerabilityassesmentrulebaselines.SqlPoolsSqlPoolVulnerabilityAssesmentRuleBaselinesClient + SqlPoolsSqlPoolVulnerabilityAssessmentScans *sqlpoolssqlpoolvulnerabilityassessmentscans.SqlPoolsSqlPoolVulnerabilityAssessmentScansClient + SqlPoolsTables *sqlpoolstables.SqlPoolsTablesClient + SqlPoolsTransparentDataEncryption *sqlpoolstransparentdataencryption.SqlPoolsTransparentDataEncryptionClient + SqlPoolsUsages *sqlpoolsusages.SqlPoolsUsagesClient + SqlPoolsVulnerabilityAssessmentScansExecute *sqlpoolsvulnerabilityassessmentscansexecute.SqlPoolsVulnerabilityAssessmentScansExecuteClient + SqlPoolsVulnerabilityAssessmentScansExport *sqlpoolsvulnerabilityassessmentscansexport.SqlPoolsVulnerabilityAssessmentScansExportClient + SqlPoolsVulnerabilityAssessments *sqlpoolsvulnerabilityassessments.SqlPoolsVulnerabilityAssessmentsClient + SqlPoolsWorkloadClassifiers *sqlpoolsworkloadclassifiers.SqlPoolsWorkloadClassifiersClient + SqlPoolsWorkloadGroups *sqlpoolsworkloadgroups.SqlPoolsWorkloadGroupsClient + WorkspaceAzureADOnlyAuthentications *workspaceazureadonlyauthentications.WorkspaceAzureADOnlyAuthenticationsClient + WorkspaceManagedSqlServer *workspacemanagedsqlserver.WorkspaceManagedSqlServerClient + WorkspaceManagedSqlServerBlobAuditing *workspacemanagedsqlserverblobauditing.WorkspaceManagedSqlServerBlobAuditingClient + WorkspaceManagedSqlServerDedicatedSQLminimalTlsSettings *workspacemanagedsqlserverdedicatedsqlminimaltlssettings.WorkspaceManagedSqlServerDedicatedSQLminimalTlsSettingsClient + WorkspaceManagedSqlServerSecurityAlertPolicies *workspacemanagedsqlserversecurityalertpolicies.WorkspaceManagedSqlServerSecurityAlertPoliciesClient + WorkspaceManagedSqlServerServerEncryptionProtector *workspacemanagedsqlserverserverencryptionprotector.WorkspaceManagedSqlServerServerEncryptionProtectorClient + WorkspaceManagedSqlServerServerVulnerabilityAssessments *workspacemanagedsqlserverservervulnerabilityassessments.WorkspaceManagedSqlServerServerVulnerabilityAssessmentsClient + WorkspaceManagedSqlServerSqlUsages *workspacemanagedsqlserversqlusages.WorkspaceManagedSqlServerSqlUsagesClient + Workspaces *workspaces.WorkspacesClient +} + +func NewClientWithBaseURI(sdkApi sdkEnv.Api, configureFunc func(c *resourcemanager.Client)) (*Client, error) { + bigDataPoolsClient, err := bigdatapools.NewBigDataPoolsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building BigDataPools client: %+v", err) + } + configureFunc(bigDataPoolsClient.Client) + + databaseVulnerabilityAssesmentRuleBaselinesClient, err := databasevulnerabilityassesmentrulebaselines.NewDatabaseVulnerabilityAssesmentRuleBaselinesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building DatabaseVulnerabilityAssesmentRuleBaselines client: %+v", err) + } + configureFunc(databaseVulnerabilityAssesmentRuleBaselinesClient.Client) + + iPFirewallRulesClient, err := ipfirewallrules.NewIPFirewallRulesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building IPFirewallRules client: %+v", err) + } + configureFunc(iPFirewallRulesClient.Client) + + integrationRuntimeClient, err := integrationruntime.NewIntegrationRuntimeClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building IntegrationRuntime client: %+v", err) + } + configureFunc(integrationRuntimeClient.Client) + + integrationRuntimesClient, err := integrationruntimes.NewIntegrationRuntimesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building IntegrationRuntimes client: %+v", err) + } + configureFunc(integrationRuntimesClient.Client) + + keysClient, err := keys.NewKeysClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building Keys client: %+v", err) + } + configureFunc(keysClient.Client) + + librariesClient, err := libraries.NewLibrariesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building Libraries client: %+v", err) + } + configureFunc(librariesClient.Client) + + operationsClient, err := operations.NewOperationsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building Operations client: %+v", err) + } + configureFunc(operationsClient.Client) + + privateEndpointConnectionsClient, err := privateendpointconnections.NewPrivateEndpointConnectionsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building PrivateEndpointConnections client: %+v", err) + } + configureFunc(privateEndpointConnectionsClient.Client) + + privateLinkHubPrivateLinkResourcesClient, err := privatelinkhubprivatelinkresources.NewPrivateLinkHubPrivateLinkResourcesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building PrivateLinkHubPrivateLinkResources client: %+v", err) + } + configureFunc(privateLinkHubPrivateLinkResourcesClient.Client) + + privateLinkHubsClient, err := privatelinkhubs.NewPrivateLinkHubsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building PrivateLinkHubs client: %+v", err) + } + configureFunc(privateLinkHubsClient.Client) + + privateLinkResourcesClient, err := privatelinkresources.NewPrivateLinkResourcesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building PrivateLinkResources client: %+v", err) + } + configureFunc(privateLinkResourcesClient.Client) + + recoverableSqlPoolsClient, err := recoverablesqlpools.NewRecoverableSqlPoolsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building RecoverableSqlPools client: %+v", err) + } + configureFunc(recoverableSqlPoolsClient.Client) + + restorableDroppedSqlPoolsClient, err := restorabledroppedsqlpools.NewRestorableDroppedSqlPoolsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building RestorableDroppedSqlPools client: %+v", err) + } + configureFunc(restorableDroppedSqlPoolsClient.Client) + + sensitivityLabelsClient, err := sensitivitylabels.NewSensitivityLabelsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building SensitivityLabels client: %+v", err) + } + configureFunc(sensitivityLabelsClient.Client) + + sqlPoolsBackupClient, err := sqlpoolsbackup.NewSqlPoolsBackupClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building SqlPoolsBackup client: %+v", err) + } + configureFunc(sqlPoolsBackupClient.Client) + + sqlPoolsBlobAuditingClient, err := sqlpoolsblobauditing.NewSqlPoolsBlobAuditingClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building SqlPoolsBlobAuditing client: %+v", err) + } + configureFunc(sqlPoolsBlobAuditingClient.Client) + + sqlPoolsClient, err := sqlpools.NewSqlPoolsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building SqlPools client: %+v", err) + } + configureFunc(sqlPoolsClient.Client) + + sqlPoolsConnectionPoliciesClient, err := sqlpoolsconnectionpolicies.NewSqlPoolsConnectionPoliciesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building SqlPoolsConnectionPolicies client: %+v", err) + } + configureFunc(sqlPoolsConnectionPoliciesClient.Client) + + sqlPoolsDataMaskingPoliciesClient, err := sqlpoolsdatamaskingpolicies.NewSqlPoolsDataMaskingPoliciesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building SqlPoolsDataMaskingPolicies client: %+v", err) + } + configureFunc(sqlPoolsDataMaskingPoliciesClient.Client) + + sqlPoolsDataMaskingRulesClient, err := sqlpoolsdatamaskingrules.NewSqlPoolsDataMaskingRulesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building SqlPoolsDataMaskingRules client: %+v", err) + } + configureFunc(sqlPoolsDataMaskingRulesClient.Client) + + sqlPoolsDatabaseVulnerabilityAssesmentRuleBaselinesClient, err := sqlpoolsdatabasevulnerabilityassesmentrulebaselines.NewSqlPoolsDatabaseVulnerabilityAssesmentRuleBaselinesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building SqlPoolsDatabaseVulnerabilityAssesmentRuleBaselines client: %+v", err) + } + configureFunc(sqlPoolsDatabaseVulnerabilityAssesmentRuleBaselinesClient.Client) + + sqlPoolsGeoBackupPoliciesClient, err := sqlpoolsgeobackuppolicies.NewSqlPoolsGeoBackupPoliciesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building SqlPoolsGeoBackupPolicies client: %+v", err) + } + configureFunc(sqlPoolsGeoBackupPoliciesClient.Client) + + sqlPoolsMaintenanceWindowOptionsClient, err := sqlpoolsmaintenancewindowoptions.NewSqlPoolsMaintenanceWindowOptionsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building SqlPoolsMaintenanceWindowOptions client: %+v", err) + } + configureFunc(sqlPoolsMaintenanceWindowOptionsClient.Client) + + sqlPoolsMaintenanceWindowsClient, err := sqlpoolsmaintenancewindows.NewSqlPoolsMaintenanceWindowsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building SqlPoolsMaintenanceWindows client: %+v", err) + } + configureFunc(sqlPoolsMaintenanceWindowsClient.Client) + + sqlPoolsOperationsClient, err := sqlpoolsoperations.NewSqlPoolsOperationsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building SqlPoolsOperations client: %+v", err) + } + configureFunc(sqlPoolsOperationsClient.Client) + + sqlPoolsReplicationLinksClient, err := sqlpoolsreplicationlinks.NewSqlPoolsReplicationLinksClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building SqlPoolsReplicationLinks client: %+v", err) + } + configureFunc(sqlPoolsReplicationLinksClient.Client) + + sqlPoolsRestorePointsClient, err := sqlpoolsrestorepoints.NewSqlPoolsRestorePointsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building SqlPoolsRestorePoints client: %+v", err) + } + configureFunc(sqlPoolsRestorePointsClient.Client) + + sqlPoolsSchemasClient, err := sqlpoolsschemas.NewSqlPoolsSchemasClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building SqlPoolsSchemas client: %+v", err) + } + configureFunc(sqlPoolsSchemasClient.Client) + + sqlPoolsSecurityAlertPoliciesClient, err := sqlpoolssecurityalertpolicies.NewSqlPoolsSecurityAlertPoliciesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building SqlPoolsSecurityAlertPolicies client: %+v", err) + } + configureFunc(sqlPoolsSecurityAlertPoliciesClient.Client) + + sqlPoolsSensitivityLabelsClient, err := sqlpoolssensitivitylabels.NewSqlPoolsSensitivityLabelsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building SqlPoolsSensitivityLabels client: %+v", err) + } + configureFunc(sqlPoolsSensitivityLabelsClient.Client) + + sqlPoolsSqlPoolColumnsClient, err := sqlpoolssqlpoolcolumns.NewSqlPoolsSqlPoolColumnsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building SqlPoolsSqlPoolColumns client: %+v", err) + } + configureFunc(sqlPoolsSqlPoolColumnsClient.Client) + + sqlPoolsSqlPoolSchemasClient, err := sqlpoolssqlpoolschemas.NewSqlPoolsSqlPoolSchemasClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building SqlPoolsSqlPoolSchemas client: %+v", err) + } + configureFunc(sqlPoolsSqlPoolSchemasClient.Client) + + sqlPoolsSqlPoolTablesClient, err := sqlpoolssqlpooltables.NewSqlPoolsSqlPoolTablesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building SqlPoolsSqlPoolTables client: %+v", err) + } + configureFunc(sqlPoolsSqlPoolTablesClient.Client) + + sqlPoolsSqlPoolUserActivitiesClient, err := sqlpoolssqlpooluseractivities.NewSqlPoolsSqlPoolUserActivitiesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building SqlPoolsSqlPoolUserActivities client: %+v", err) + } + configureFunc(sqlPoolsSqlPoolUserActivitiesClient.Client) + + sqlPoolsSqlPoolVulnerabilityAssesmentRuleBaselinesClient, err := sqlpoolssqlpoolvulnerabilityassesmentrulebaselines.NewSqlPoolsSqlPoolVulnerabilityAssesmentRuleBaselinesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building SqlPoolsSqlPoolVulnerabilityAssesmentRuleBaselines client: %+v", err) + } + configureFunc(sqlPoolsSqlPoolVulnerabilityAssesmentRuleBaselinesClient.Client) + + sqlPoolsSqlPoolVulnerabilityAssessmentScansClient, err := sqlpoolssqlpoolvulnerabilityassessmentscans.NewSqlPoolsSqlPoolVulnerabilityAssessmentScansClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building SqlPoolsSqlPoolVulnerabilityAssessmentScans client: %+v", err) + } + configureFunc(sqlPoolsSqlPoolVulnerabilityAssessmentScansClient.Client) + + sqlPoolsTablesClient, err := sqlpoolstables.NewSqlPoolsTablesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building SqlPoolsTables client: %+v", err) + } + configureFunc(sqlPoolsTablesClient.Client) + + sqlPoolsTransparentDataEncryptionClient, err := sqlpoolstransparentdataencryption.NewSqlPoolsTransparentDataEncryptionClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building SqlPoolsTransparentDataEncryption client: %+v", err) + } + configureFunc(sqlPoolsTransparentDataEncryptionClient.Client) + + sqlPoolsUsagesClient, err := sqlpoolsusages.NewSqlPoolsUsagesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building SqlPoolsUsages client: %+v", err) + } + configureFunc(sqlPoolsUsagesClient.Client) + + sqlPoolsVulnerabilityAssessmentScansExecuteClient, err := sqlpoolsvulnerabilityassessmentscansexecute.NewSqlPoolsVulnerabilityAssessmentScansExecuteClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building SqlPoolsVulnerabilityAssessmentScansExecute client: %+v", err) + } + configureFunc(sqlPoolsVulnerabilityAssessmentScansExecuteClient.Client) + + sqlPoolsVulnerabilityAssessmentScansExportClient, err := sqlpoolsvulnerabilityassessmentscansexport.NewSqlPoolsVulnerabilityAssessmentScansExportClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building SqlPoolsVulnerabilityAssessmentScansExport client: %+v", err) + } + configureFunc(sqlPoolsVulnerabilityAssessmentScansExportClient.Client) + + sqlPoolsVulnerabilityAssessmentsClient, err := sqlpoolsvulnerabilityassessments.NewSqlPoolsVulnerabilityAssessmentsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building SqlPoolsVulnerabilityAssessments client: %+v", err) + } + configureFunc(sqlPoolsVulnerabilityAssessmentsClient.Client) + + sqlPoolsWorkloadClassifiersClient, err := sqlpoolsworkloadclassifiers.NewSqlPoolsWorkloadClassifiersClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building SqlPoolsWorkloadClassifiers client: %+v", err) + } + configureFunc(sqlPoolsWorkloadClassifiersClient.Client) + + sqlPoolsWorkloadGroupsClient, err := sqlpoolsworkloadgroups.NewSqlPoolsWorkloadGroupsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building SqlPoolsWorkloadGroups client: %+v", err) + } + configureFunc(sqlPoolsWorkloadGroupsClient.Client) + + workspaceAzureADOnlyAuthenticationsClient, err := workspaceazureadonlyauthentications.NewWorkspaceAzureADOnlyAuthenticationsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building WorkspaceAzureADOnlyAuthentications client: %+v", err) + } + configureFunc(workspaceAzureADOnlyAuthenticationsClient.Client) + + workspaceManagedSqlServerBlobAuditingClient, err := workspacemanagedsqlserverblobauditing.NewWorkspaceManagedSqlServerBlobAuditingClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building WorkspaceManagedSqlServerBlobAuditing client: %+v", err) + } + configureFunc(workspaceManagedSqlServerBlobAuditingClient.Client) + + workspaceManagedSqlServerClient, err := workspacemanagedsqlserver.NewWorkspaceManagedSqlServerClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building WorkspaceManagedSqlServer client: %+v", err) + } + configureFunc(workspaceManagedSqlServerClient.Client) + + workspaceManagedSqlServerDedicatedSQLminimalTlsSettingsClient, err := workspacemanagedsqlserverdedicatedsqlminimaltlssettings.NewWorkspaceManagedSqlServerDedicatedSQLminimalTlsSettingsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building WorkspaceManagedSqlServerDedicatedSQLminimalTlsSettings client: %+v", err) + } + configureFunc(workspaceManagedSqlServerDedicatedSQLminimalTlsSettingsClient.Client) + + workspaceManagedSqlServerSecurityAlertPoliciesClient, err := workspacemanagedsqlserversecurityalertpolicies.NewWorkspaceManagedSqlServerSecurityAlertPoliciesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building WorkspaceManagedSqlServerSecurityAlertPolicies client: %+v", err) + } + configureFunc(workspaceManagedSqlServerSecurityAlertPoliciesClient.Client) + + workspaceManagedSqlServerServerEncryptionProtectorClient, err := workspacemanagedsqlserverserverencryptionprotector.NewWorkspaceManagedSqlServerServerEncryptionProtectorClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building WorkspaceManagedSqlServerServerEncryptionProtector client: %+v", err) + } + configureFunc(workspaceManagedSqlServerServerEncryptionProtectorClient.Client) + + workspaceManagedSqlServerServerVulnerabilityAssessmentsClient, err := workspacemanagedsqlserverservervulnerabilityassessments.NewWorkspaceManagedSqlServerServerVulnerabilityAssessmentsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building WorkspaceManagedSqlServerServerVulnerabilityAssessments client: %+v", err) + } + configureFunc(workspaceManagedSqlServerServerVulnerabilityAssessmentsClient.Client) + + workspaceManagedSqlServerSqlUsagesClient, err := workspacemanagedsqlserversqlusages.NewWorkspaceManagedSqlServerSqlUsagesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building WorkspaceManagedSqlServerSqlUsages client: %+v", err) + } + configureFunc(workspaceManagedSqlServerSqlUsagesClient.Client) + + workspacesClient, err := workspaces.NewWorkspacesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building Workspaces client: %+v", err) + } + configureFunc(workspacesClient.Client) + + return &Client{ + BigDataPools: bigDataPoolsClient, + DatabaseVulnerabilityAssesmentRuleBaselines: databaseVulnerabilityAssesmentRuleBaselinesClient, + IPFirewallRules: iPFirewallRulesClient, + IntegrationRuntime: integrationRuntimeClient, + IntegrationRuntimes: integrationRuntimesClient, + Keys: keysClient, + Libraries: librariesClient, + Operations: operationsClient, + PrivateEndpointConnections: privateEndpointConnectionsClient, + PrivateLinkHubPrivateLinkResources: privateLinkHubPrivateLinkResourcesClient, + PrivateLinkHubs: privateLinkHubsClient, + PrivateLinkResources: privateLinkResourcesClient, + RecoverableSqlPools: recoverableSqlPoolsClient, + RestorableDroppedSqlPools: restorableDroppedSqlPoolsClient, + SensitivityLabels: sensitivityLabelsClient, + SqlPools: sqlPoolsClient, + SqlPoolsBackup: sqlPoolsBackupClient, + SqlPoolsBlobAuditing: sqlPoolsBlobAuditingClient, + SqlPoolsConnectionPolicies: sqlPoolsConnectionPoliciesClient, + SqlPoolsDataMaskingPolicies: sqlPoolsDataMaskingPoliciesClient, + SqlPoolsDataMaskingRules: sqlPoolsDataMaskingRulesClient, + SqlPoolsDatabaseVulnerabilityAssesmentRuleBaselines: sqlPoolsDatabaseVulnerabilityAssesmentRuleBaselinesClient, + SqlPoolsGeoBackupPolicies: sqlPoolsGeoBackupPoliciesClient, + SqlPoolsMaintenanceWindowOptions: sqlPoolsMaintenanceWindowOptionsClient, + SqlPoolsMaintenanceWindows: sqlPoolsMaintenanceWindowsClient, + SqlPoolsOperations: sqlPoolsOperationsClient, + SqlPoolsReplicationLinks: sqlPoolsReplicationLinksClient, + SqlPoolsRestorePoints: sqlPoolsRestorePointsClient, + SqlPoolsSchemas: sqlPoolsSchemasClient, + SqlPoolsSecurityAlertPolicies: sqlPoolsSecurityAlertPoliciesClient, + SqlPoolsSensitivityLabels: sqlPoolsSensitivityLabelsClient, + SqlPoolsSqlPoolColumns: sqlPoolsSqlPoolColumnsClient, + SqlPoolsSqlPoolSchemas: sqlPoolsSqlPoolSchemasClient, + SqlPoolsSqlPoolTables: sqlPoolsSqlPoolTablesClient, + SqlPoolsSqlPoolUserActivities: sqlPoolsSqlPoolUserActivitiesClient, + SqlPoolsSqlPoolVulnerabilityAssesmentRuleBaselines: sqlPoolsSqlPoolVulnerabilityAssesmentRuleBaselinesClient, + SqlPoolsSqlPoolVulnerabilityAssessmentScans: sqlPoolsSqlPoolVulnerabilityAssessmentScansClient, + SqlPoolsTables: sqlPoolsTablesClient, + SqlPoolsTransparentDataEncryption: sqlPoolsTransparentDataEncryptionClient, + SqlPoolsUsages: sqlPoolsUsagesClient, + SqlPoolsVulnerabilityAssessmentScansExecute: sqlPoolsVulnerabilityAssessmentScansExecuteClient, + SqlPoolsVulnerabilityAssessmentScansExport: sqlPoolsVulnerabilityAssessmentScansExportClient, + SqlPoolsVulnerabilityAssessments: sqlPoolsVulnerabilityAssessmentsClient, + SqlPoolsWorkloadClassifiers: sqlPoolsWorkloadClassifiersClient, + SqlPoolsWorkloadGroups: sqlPoolsWorkloadGroupsClient, + WorkspaceAzureADOnlyAuthentications: workspaceAzureADOnlyAuthenticationsClient, + WorkspaceManagedSqlServer: workspaceManagedSqlServerClient, + WorkspaceManagedSqlServerBlobAuditing: workspaceManagedSqlServerBlobAuditingClient, + WorkspaceManagedSqlServerDedicatedSQLminimalTlsSettings: workspaceManagedSqlServerDedicatedSQLminimalTlsSettingsClient, + WorkspaceManagedSqlServerSecurityAlertPolicies: workspaceManagedSqlServerSecurityAlertPoliciesClient, + WorkspaceManagedSqlServerServerEncryptionProtector: workspaceManagedSqlServerServerEncryptionProtectorClient, + WorkspaceManagedSqlServerServerVulnerabilityAssessments: workspaceManagedSqlServerServerVulnerabilityAssessmentsClient, + WorkspaceManagedSqlServerSqlUsages: workspaceManagedSqlServerSqlUsagesClient, + Workspaces: workspacesClient, + }, nil +} diff --git a/resource-manager/synapse/2021-06-01/databasevulnerabilityassesmentrulebaselines/client.go b/resource-manager/synapse/2021-06-01/databasevulnerabilityassesmentrulebaselines/client.go new file mode 100644 index 00000000000..05615ad96fc --- /dev/null +++ b/resource-manager/synapse/2021-06-01/databasevulnerabilityassesmentrulebaselines/client.go @@ -0,0 +1,26 @@ +package databasevulnerabilityassesmentrulebaselines + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DatabaseVulnerabilityAssesmentRuleBaselinesClient struct { + Client *resourcemanager.Client +} + +func NewDatabaseVulnerabilityAssesmentRuleBaselinesClientWithBaseURI(sdkApi sdkEnv.Api) (*DatabaseVulnerabilityAssesmentRuleBaselinesClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "databasevulnerabilityassesmentrulebaselines", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating DatabaseVulnerabilityAssesmentRuleBaselinesClient: %+v", err) + } + + return &DatabaseVulnerabilityAssesmentRuleBaselinesClient{ + Client: client, + }, nil +} diff --git a/resource-manager/synapse/2021-06-01/databasevulnerabilityassesmentrulebaselines/constants.go b/resource-manager/synapse/2021-06-01/databasevulnerabilityassesmentrulebaselines/constants.go new file mode 100644 index 00000000000..eb38efb7691 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/databasevulnerabilityassesmentrulebaselines/constants.go @@ -0,0 +1,51 @@ +package databasevulnerabilityassesmentrulebaselines + +import ( + "encoding/json" + "fmt" + "strings" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type VulnerabilityAssessmentPolicyBaselineName string + +const ( + VulnerabilityAssessmentPolicyBaselineNameDefault VulnerabilityAssessmentPolicyBaselineName = "default" + VulnerabilityAssessmentPolicyBaselineNameMaster VulnerabilityAssessmentPolicyBaselineName = "master" +) + +func PossibleValuesForVulnerabilityAssessmentPolicyBaselineName() []string { + return []string{ + string(VulnerabilityAssessmentPolicyBaselineNameDefault), + string(VulnerabilityAssessmentPolicyBaselineNameMaster), + } +} + +func (s *VulnerabilityAssessmentPolicyBaselineName) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseVulnerabilityAssessmentPolicyBaselineName(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseVulnerabilityAssessmentPolicyBaselineName(input string) (*VulnerabilityAssessmentPolicyBaselineName, error) { + vals := map[string]VulnerabilityAssessmentPolicyBaselineName{ + "default": VulnerabilityAssessmentPolicyBaselineNameDefault, + "master": VulnerabilityAssessmentPolicyBaselineNameMaster, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := VulnerabilityAssessmentPolicyBaselineName(input) + return &out, nil +} diff --git a/resource-manager/synapse/2021-06-01/databasevulnerabilityassesmentrulebaselines/id_baseline.go b/resource-manager/synapse/2021-06-01/databasevulnerabilityassesmentrulebaselines/id_baseline.go new file mode 100644 index 00000000000..4e7a28a0a8f --- /dev/null +++ b/resource-manager/synapse/2021-06-01/databasevulnerabilityassesmentrulebaselines/id_baseline.go @@ -0,0 +1,162 @@ +package databasevulnerabilityassesmentrulebaselines + +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 = &BaselineId{} + +// BaselineId is a struct representing the Resource ID for a Baseline +type BaselineId struct { + SubscriptionId string + ResourceGroupName string + WorkspaceName string + SqlPoolName string + RuleId string + BaselineName VulnerabilityAssessmentPolicyBaselineName +} + +// NewBaselineID returns a new BaselineId struct +func NewBaselineID(subscriptionId string, resourceGroupName string, workspaceName string, sqlPoolName string, ruleId string, baselineName VulnerabilityAssessmentPolicyBaselineName) BaselineId { + return BaselineId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + WorkspaceName: workspaceName, + SqlPoolName: sqlPoolName, + RuleId: ruleId, + BaselineName: baselineName, + } +} + +// ParseBaselineID parses 'input' into a BaselineId +func ParseBaselineID(input string) (*BaselineId, error) { + parser := resourceids.NewParserFromResourceIdType(&BaselineId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := BaselineId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseBaselineIDInsensitively parses 'input' case-insensitively into a BaselineId +// note: this method should only be used for API response data and not user input +func ParseBaselineIDInsensitively(input string) (*BaselineId, error) { + parser := resourceids.NewParserFromResourceIdType(&BaselineId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := BaselineId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *BaselineId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.WorkspaceName, ok = input.Parsed["workspaceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "workspaceName", input) + } + + if id.SqlPoolName, ok = input.Parsed["sqlPoolName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "sqlPoolName", input) + } + + if id.RuleId, ok = input.Parsed["ruleId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "ruleId", input) + } + + if v, ok := input.Parsed["baselineName"]; true { + if !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "baselineName", input) + } + + baselineName, err := parseVulnerabilityAssessmentPolicyBaselineName(v) + if err != nil { + return fmt.Errorf("parsing %q: %+v", v, err) + } + id.BaselineName = *baselineName + } + + return nil +} + +// ValidateBaselineID checks that 'input' can be parsed as a Baseline ID +func ValidateBaselineID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseBaselineID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Baseline ID +func (id BaselineId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Synapse/workspaces/%s/sqlPools/%s/vulnerabilityAssessments/default/rules/%s/baselines/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.WorkspaceName, id.SqlPoolName, id.RuleId, string(id.BaselineName)) +} + +// Segments returns a slice of Resource ID Segments which comprise this Baseline ID +func (id BaselineId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftSynapse", "Microsoft.Synapse", "Microsoft.Synapse"), + resourceids.StaticSegment("staticWorkspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceName", "workspaceValue"), + resourceids.StaticSegment("staticSqlPools", "sqlPools", "sqlPools"), + resourceids.UserSpecifiedSegment("sqlPoolName", "sqlPoolValue"), + resourceids.StaticSegment("staticVulnerabilityAssessments", "vulnerabilityAssessments", "vulnerabilityAssessments"), + resourceids.StaticSegment("vulnerabilityAssessmentName", "default", "default"), + resourceids.StaticSegment("staticRules", "rules", "rules"), + resourceids.UserSpecifiedSegment("ruleId", "ruleIdValue"), + resourceids.StaticSegment("staticBaselines", "baselines", "baselines"), + resourceids.ConstantSegment("baselineName", PossibleValuesForVulnerabilityAssessmentPolicyBaselineName(), "default"), + } +} + +// String returns a human-readable description of this Baseline ID +func (id BaselineId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Workspace Name: %q", id.WorkspaceName), + fmt.Sprintf("Sql Pool Name: %q", id.SqlPoolName), + fmt.Sprintf("Rule: %q", id.RuleId), + fmt.Sprintf("Baseline Name: %q", string(id.BaselineName)), + } + return fmt.Sprintf("Baseline (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/synapse/2021-06-01/databasevulnerabilityassesmentrulebaselines/id_baseline_test.go b/resource-manager/synapse/2021-06-01/databasevulnerabilityassesmentrulebaselines/id_baseline_test.go new file mode 100644 index 00000000000..ffef74d180e --- /dev/null +++ b/resource-manager/synapse/2021-06-01/databasevulnerabilityassesmentrulebaselines/id_baseline_test.go @@ -0,0 +1,447 @@ +package databasevulnerabilityassesmentrulebaselines + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &BaselineId{} + +func TestNewBaselineID(t *testing.T) { + id := NewBaselineID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "sqlPoolValue", "ruleIdValue", "default") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.WorkspaceName != "workspaceValue" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceName'", id.WorkspaceName, "workspaceValue") + } + + if id.SqlPoolName != "sqlPoolValue" { + t.Fatalf("Expected %q but got %q for Segment 'SqlPoolName'", id.SqlPoolName, "sqlPoolValue") + } + + if id.RuleId != "ruleIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'RuleId'", id.RuleId, "ruleIdValue") + } + + if id.BaselineName != "default" { + t.Fatalf("Expected %q but got %q for Segment 'BaselineName'", id.BaselineName, "default") + } +} + +func TestFormatBaselineID(t *testing.T) { + actual := NewBaselineID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "sqlPoolValue", "ruleIdValue", "default").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/vulnerabilityAssessments/default/rules/ruleIdValue/baselines/default" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseBaselineID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *BaselineId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/vulnerabilityAssessments", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/vulnerabilityAssessments/default", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/vulnerabilityAssessments/default/rules", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/vulnerabilityAssessments/default/rules/ruleIdValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/vulnerabilityAssessments/default/rules/ruleIdValue/baselines", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/vulnerabilityAssessments/default/rules/ruleIdValue/baselines/default", + Expected: &BaselineId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + SqlPoolName: "sqlPoolValue", + RuleId: "ruleIdValue", + BaselineName: "default", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/vulnerabilityAssessments/default/rules/ruleIdValue/baselines/default/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseBaselineID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + if actual.SqlPoolName != v.Expected.SqlPoolName { + t.Fatalf("Expected %q but got %q for SqlPoolName", v.Expected.SqlPoolName, actual.SqlPoolName) + } + + if actual.RuleId != v.Expected.RuleId { + t.Fatalf("Expected %q but got %q for RuleId", v.Expected.RuleId, actual.RuleId) + } + + if actual.BaselineName != v.Expected.BaselineName { + t.Fatalf("Expected %q but got %q for BaselineName", v.Expected.BaselineName, actual.BaselineName) + } + + } +} + +func TestParseBaselineIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *BaselineId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/sQlPoOlS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/sQlPoOlS/sQlPoOlVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/vulnerabilityAssessments", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/sQlPoOlS/sQlPoOlVaLuE/vUlNeRaBiLiTyAsSeSsMeNtS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/vulnerabilityAssessments/default", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/sQlPoOlS/sQlPoOlVaLuE/vUlNeRaBiLiTyAsSeSsMeNtS/dEfAuLt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/vulnerabilityAssessments/default/rules", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/sQlPoOlS/sQlPoOlVaLuE/vUlNeRaBiLiTyAsSeSsMeNtS/dEfAuLt/rUlEs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/vulnerabilityAssessments/default/rules/ruleIdValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/sQlPoOlS/sQlPoOlVaLuE/vUlNeRaBiLiTyAsSeSsMeNtS/dEfAuLt/rUlEs/rUlEiDvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/vulnerabilityAssessments/default/rules/ruleIdValue/baselines", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/sQlPoOlS/sQlPoOlVaLuE/vUlNeRaBiLiTyAsSeSsMeNtS/dEfAuLt/rUlEs/rUlEiDvAlUe/bAsElInEs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/vulnerabilityAssessments/default/rules/ruleIdValue/baselines/default", + Expected: &BaselineId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + SqlPoolName: "sqlPoolValue", + RuleId: "ruleIdValue", + BaselineName: "default", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/vulnerabilityAssessments/default/rules/ruleIdValue/baselines/default/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/sQlPoOlS/sQlPoOlVaLuE/vUlNeRaBiLiTyAsSeSsMeNtS/dEfAuLt/rUlEs/rUlEiDvAlUe/bAsElInEs/dEfAuLt", + Expected: &BaselineId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + WorkspaceName: "wOrKsPaCeVaLuE", + SqlPoolName: "sQlPoOlVaLuE", + RuleId: "rUlEiDvAlUe", + BaselineName: "default", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/sQlPoOlS/sQlPoOlVaLuE/vUlNeRaBiLiTyAsSeSsMeNtS/dEfAuLt/rUlEs/rUlEiDvAlUe/bAsElInEs/dEfAuLt/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseBaselineIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + if actual.SqlPoolName != v.Expected.SqlPoolName { + t.Fatalf("Expected %q but got %q for SqlPoolName", v.Expected.SqlPoolName, actual.SqlPoolName) + } + + if actual.RuleId != v.Expected.RuleId { + t.Fatalf("Expected %q but got %q for RuleId", v.Expected.RuleId, actual.RuleId) + } + + if actual.BaselineName != v.Expected.BaselineName { + t.Fatalf("Expected %q but got %q for BaselineName", v.Expected.BaselineName, actual.BaselineName) + } + + } +} + +func TestSegmentsForBaselineId(t *testing.T) { + segments := BaselineId{}.Segments() + if len(segments) == 0 { + t.Fatalf("BaselineId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/synapse/2021-06-01/databasevulnerabilityassesmentrulebaselines/method_sqlpoolvulnerabilityassessmentrulebaselinesdelete.go b/resource-manager/synapse/2021-06-01/databasevulnerabilityassesmentrulebaselines/method_sqlpoolvulnerabilityassessmentrulebaselinesdelete.go new file mode 100644 index 00000000000..b34463bc434 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/databasevulnerabilityassesmentrulebaselines/method_sqlpoolvulnerabilityassessmentrulebaselinesdelete.go @@ -0,0 +1,47 @@ +package databasevulnerabilityassesmentrulebaselines + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SqlPoolVulnerabilityAssessmentRuleBaselinesDeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// SqlPoolVulnerabilityAssessmentRuleBaselinesDelete ... +func (c DatabaseVulnerabilityAssesmentRuleBaselinesClient) SqlPoolVulnerabilityAssessmentRuleBaselinesDelete(ctx context.Context, id BaselineId) (result SqlPoolVulnerabilityAssessmentRuleBaselinesDeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/synapse/2021-06-01/databasevulnerabilityassesmentrulebaselines/version.go b/resource-manager/synapse/2021-06-01/databasevulnerabilityassesmentrulebaselines/version.go new file mode 100644 index 00000000000..6710afae0fd --- /dev/null +++ b/resource-manager/synapse/2021-06-01/databasevulnerabilityassesmentrulebaselines/version.go @@ -0,0 +1,12 @@ +package databasevulnerabilityassesmentrulebaselines + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2021-06-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/databasevulnerabilityassesmentrulebaselines/%s", defaultApiVersion) +} diff --git a/resource-manager/synapse/2021-06-01/integrationruntime/README.md b/resource-manager/synapse/2021-06-01/integrationruntime/README.md new file mode 100644 index 00000000000..0421fdb8f29 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/integrationruntime/README.md @@ -0,0 +1,370 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/synapse/2021-06-01/integrationruntime` Documentation + +The `integrationruntime` SDK allows for interaction with the Azure Resource Manager Service `synapse` (API Version `2021-06-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/synapse/2021-06-01/integrationruntime" +``` + + +### Client Initialization + +```go +client := integrationruntime.NewIntegrationRuntimeClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `IntegrationRuntimeClient.AuthKeysList` + +```go +ctx := context.TODO() +id := integrationruntime.NewIntegrationRuntimeID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "integrationRuntimeValue") + +read, err := client.AuthKeysList(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `IntegrationRuntimeClient.AuthKeysRegenerate` + +```go +ctx := context.TODO() +id := integrationruntime.NewIntegrationRuntimeID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "integrationRuntimeValue") + +payload := integrationruntime.IntegrationRuntimeRegenerateKeyParameters{ + // ... +} + + +read, err := client.AuthKeysRegenerate(ctx, id, payload) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `IntegrationRuntimeClient.ConnectionInfosGet` + +```go +ctx := context.TODO() +id := integrationruntime.NewIntegrationRuntimeID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "integrationRuntimeValue") + +read, err := client.ConnectionInfosGet(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `IntegrationRuntimeClient.Create` + +```go +ctx := context.TODO() +id := integrationruntime.NewIntegrationRuntimeID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "integrationRuntimeValue") + +payload := integrationruntime.IntegrationRuntimeResource{ + // ... +} + + +if err := client.CreateThenPoll(ctx, id, payload, integrationruntime.DefaultCreateOperationOptions()); err != nil { + // handle the error +} +``` + + +### Example Usage: `IntegrationRuntimeClient.CredentialsSync` + +```go +ctx := context.TODO() +id := integrationruntime.NewIntegrationRuntimeID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "integrationRuntimeValue") + +read, err := client.CredentialsSync(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `IntegrationRuntimeClient.Delete` + +```go +ctx := context.TODO() +id := integrationruntime.NewIntegrationRuntimeID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "integrationRuntimeValue") + +if err := client.DeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `IntegrationRuntimeClient.DisableInteractiveQuery` + +```go +ctx := context.TODO() +id := integrationruntime.NewIntegrationRuntimeID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "integrationRuntimeValue") + +if err := client.DisableInteractiveQueryThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `IntegrationRuntimeClient.EnableInteractiveQuery` + +```go +ctx := context.TODO() +id := integrationruntime.NewIntegrationRuntimeID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "integrationRuntimeValue") + +if err := client.EnableInteractiveQueryThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `IntegrationRuntimeClient.Get` + +```go +ctx := context.TODO() +id := integrationruntime.NewIntegrationRuntimeID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "integrationRuntimeValue") + +read, err := client.Get(ctx, id, integrationruntime.DefaultGetOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `IntegrationRuntimeClient.ListByWorkspace` + +```go +ctx := context.TODO() +id := integrationruntime.NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue") + +// alternatively `client.ListByWorkspace(ctx, id)` can be used to do batched pagination +items, err := client.ListByWorkspaceComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `IntegrationRuntimeClient.MonitoringDataList` + +```go +ctx := context.TODO() +id := integrationruntime.NewIntegrationRuntimeID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "integrationRuntimeValue") + +read, err := client.MonitoringDataList(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `IntegrationRuntimeClient.NodeIPAddressGet` + +```go +ctx := context.TODO() +id := integrationruntime.NewNodeID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "integrationRuntimeValue", "nodeValue") + +read, err := client.NodeIPAddressGet(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `IntegrationRuntimeClient.NodesDelete` + +```go +ctx := context.TODO() +id := integrationruntime.NewNodeID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "integrationRuntimeValue", "nodeValue") + +read, err := client.NodesDelete(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `IntegrationRuntimeClient.NodesGet` + +```go +ctx := context.TODO() +id := integrationruntime.NewNodeID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "integrationRuntimeValue", "nodeValue") + +read, err := client.NodesGet(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `IntegrationRuntimeClient.NodesUpdate` + +```go +ctx := context.TODO() +id := integrationruntime.NewNodeID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "integrationRuntimeValue", "nodeValue") + +payload := integrationruntime.UpdateIntegrationRuntimeNodeRequest{ + // ... +} + + +read, err := client.NodesUpdate(ctx, id, payload) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `IntegrationRuntimeClient.ObjectMetadataList` + +```go +ctx := context.TODO() +id := integrationruntime.NewIntegrationRuntimeID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "integrationRuntimeValue") + +payload := integrationruntime.GetSsisObjectMetadataRequest{ + // ... +} + + +read, err := client.ObjectMetadataList(ctx, id, payload) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `IntegrationRuntimeClient.ObjectMetadataRefresh` + +```go +ctx := context.TODO() +id := integrationruntime.NewIntegrationRuntimeID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "integrationRuntimeValue") + +if err := client.ObjectMetadataRefreshThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `IntegrationRuntimeClient.Start` + +```go +ctx := context.TODO() +id := integrationruntime.NewIntegrationRuntimeID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "integrationRuntimeValue") + +if err := client.StartThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `IntegrationRuntimeClient.StatusGet` + +```go +ctx := context.TODO() +id := integrationruntime.NewIntegrationRuntimeID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "integrationRuntimeValue") + +read, err := client.StatusGet(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `IntegrationRuntimeClient.Stop` + +```go +ctx := context.TODO() +id := integrationruntime.NewIntegrationRuntimeID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "integrationRuntimeValue") + +if err := client.StopThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `IntegrationRuntimeClient.Update` + +```go +ctx := context.TODO() +id := integrationruntime.NewIntegrationRuntimeID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "integrationRuntimeValue") + +payload := integrationruntime.UpdateIntegrationRuntimeRequest{ + // ... +} + + +read, err := client.Update(ctx, id, payload) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `IntegrationRuntimeClient.Upgrade` + +```go +ctx := context.TODO() +id := integrationruntime.NewIntegrationRuntimeID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "integrationRuntimeValue") + +read, err := client.Upgrade(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` diff --git a/resource-manager/synapse/2021-06-01/integrationruntime/client.go b/resource-manager/synapse/2021-06-01/integrationruntime/client.go new file mode 100644 index 00000000000..e1933852c17 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/integrationruntime/client.go @@ -0,0 +1,26 @@ +package integrationruntime + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IntegrationRuntimeClient struct { + Client *resourcemanager.Client +} + +func NewIntegrationRuntimeClientWithBaseURI(sdkApi sdkEnv.Api) (*IntegrationRuntimeClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "integrationruntime", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating IntegrationRuntimeClient: %+v", err) + } + + return &IntegrationRuntimeClient{ + Client: client, + }, nil +} diff --git a/resource-manager/synapse/2021-06-01/integrationruntime/constants.go b/resource-manager/synapse/2021-06-01/integrationruntime/constants.go new file mode 100644 index 00000000000..a2af8f7180c --- /dev/null +++ b/resource-manager/synapse/2021-06-01/integrationruntime/constants.go @@ -0,0 +1,650 @@ +package integrationruntime + +import ( + "encoding/json" + "fmt" + "strings" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DataFlowComputeType string + +const ( + DataFlowComputeTypeComputeOptimized DataFlowComputeType = "ComputeOptimized" + DataFlowComputeTypeGeneral DataFlowComputeType = "General" + DataFlowComputeTypeMemoryOptimized DataFlowComputeType = "MemoryOptimized" +) + +func PossibleValuesForDataFlowComputeType() []string { + return []string{ + string(DataFlowComputeTypeComputeOptimized), + string(DataFlowComputeTypeGeneral), + string(DataFlowComputeTypeMemoryOptimized), + } +} + +func (s *DataFlowComputeType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseDataFlowComputeType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseDataFlowComputeType(input string) (*DataFlowComputeType, error) { + vals := map[string]DataFlowComputeType{ + "computeoptimized": DataFlowComputeTypeComputeOptimized, + "general": DataFlowComputeTypeGeneral, + "memoryoptimized": DataFlowComputeTypeMemoryOptimized, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := DataFlowComputeType(input) + return &out, nil +} + +type IntegrationRuntimeAuthKeyName string + +const ( + IntegrationRuntimeAuthKeyNameAuthKeyOne IntegrationRuntimeAuthKeyName = "authKey1" + IntegrationRuntimeAuthKeyNameAuthKeyTwo IntegrationRuntimeAuthKeyName = "authKey2" +) + +func PossibleValuesForIntegrationRuntimeAuthKeyName() []string { + return []string{ + string(IntegrationRuntimeAuthKeyNameAuthKeyOne), + string(IntegrationRuntimeAuthKeyNameAuthKeyTwo), + } +} + +func (s *IntegrationRuntimeAuthKeyName) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseIntegrationRuntimeAuthKeyName(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseIntegrationRuntimeAuthKeyName(input string) (*IntegrationRuntimeAuthKeyName, error) { + vals := map[string]IntegrationRuntimeAuthKeyName{ + "authkey1": IntegrationRuntimeAuthKeyNameAuthKeyOne, + "authkey2": IntegrationRuntimeAuthKeyNameAuthKeyTwo, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := IntegrationRuntimeAuthKeyName(input) + return &out, nil +} + +type IntegrationRuntimeAutoUpdate string + +const ( + IntegrationRuntimeAutoUpdateOff IntegrationRuntimeAutoUpdate = "Off" + IntegrationRuntimeAutoUpdateOn IntegrationRuntimeAutoUpdate = "On" +) + +func PossibleValuesForIntegrationRuntimeAutoUpdate() []string { + return []string{ + string(IntegrationRuntimeAutoUpdateOff), + string(IntegrationRuntimeAutoUpdateOn), + } +} + +func (s *IntegrationRuntimeAutoUpdate) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseIntegrationRuntimeAutoUpdate(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseIntegrationRuntimeAutoUpdate(input string) (*IntegrationRuntimeAutoUpdate, error) { + vals := map[string]IntegrationRuntimeAutoUpdate{ + "off": IntegrationRuntimeAutoUpdateOff, + "on": IntegrationRuntimeAutoUpdateOn, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := IntegrationRuntimeAutoUpdate(input) + return &out, nil +} + +type IntegrationRuntimeEdition string + +const ( + IntegrationRuntimeEditionEnterprise IntegrationRuntimeEdition = "Enterprise" + IntegrationRuntimeEditionStandard IntegrationRuntimeEdition = "Standard" +) + +func PossibleValuesForIntegrationRuntimeEdition() []string { + return []string{ + string(IntegrationRuntimeEditionEnterprise), + string(IntegrationRuntimeEditionStandard), + } +} + +func (s *IntegrationRuntimeEdition) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseIntegrationRuntimeEdition(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseIntegrationRuntimeEdition(input string) (*IntegrationRuntimeEdition, error) { + vals := map[string]IntegrationRuntimeEdition{ + "enterprise": IntegrationRuntimeEditionEnterprise, + "standard": IntegrationRuntimeEditionStandard, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := IntegrationRuntimeEdition(input) + return &out, nil +} + +type IntegrationRuntimeEntityReferenceType string + +const ( + IntegrationRuntimeEntityReferenceTypeIntegrationRuntimeReference IntegrationRuntimeEntityReferenceType = "IntegrationRuntimeReference" + IntegrationRuntimeEntityReferenceTypeLinkedServiceReference IntegrationRuntimeEntityReferenceType = "LinkedServiceReference" +) + +func PossibleValuesForIntegrationRuntimeEntityReferenceType() []string { + return []string{ + string(IntegrationRuntimeEntityReferenceTypeIntegrationRuntimeReference), + string(IntegrationRuntimeEntityReferenceTypeLinkedServiceReference), + } +} + +func (s *IntegrationRuntimeEntityReferenceType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseIntegrationRuntimeEntityReferenceType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseIntegrationRuntimeEntityReferenceType(input string) (*IntegrationRuntimeEntityReferenceType, error) { + vals := map[string]IntegrationRuntimeEntityReferenceType{ + "integrationruntimereference": IntegrationRuntimeEntityReferenceTypeIntegrationRuntimeReference, + "linkedservicereference": IntegrationRuntimeEntityReferenceTypeLinkedServiceReference, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := IntegrationRuntimeEntityReferenceType(input) + return &out, nil +} + +type IntegrationRuntimeInternalChannelEncryptionMode string + +const ( + IntegrationRuntimeInternalChannelEncryptionModeNotEncrypted IntegrationRuntimeInternalChannelEncryptionMode = "NotEncrypted" + IntegrationRuntimeInternalChannelEncryptionModeNotSet IntegrationRuntimeInternalChannelEncryptionMode = "NotSet" + IntegrationRuntimeInternalChannelEncryptionModeSslEncrypted IntegrationRuntimeInternalChannelEncryptionMode = "SslEncrypted" +) + +func PossibleValuesForIntegrationRuntimeInternalChannelEncryptionMode() []string { + return []string{ + string(IntegrationRuntimeInternalChannelEncryptionModeNotEncrypted), + string(IntegrationRuntimeInternalChannelEncryptionModeNotSet), + string(IntegrationRuntimeInternalChannelEncryptionModeSslEncrypted), + } +} + +func (s *IntegrationRuntimeInternalChannelEncryptionMode) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseIntegrationRuntimeInternalChannelEncryptionMode(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseIntegrationRuntimeInternalChannelEncryptionMode(input string) (*IntegrationRuntimeInternalChannelEncryptionMode, error) { + vals := map[string]IntegrationRuntimeInternalChannelEncryptionMode{ + "notencrypted": IntegrationRuntimeInternalChannelEncryptionModeNotEncrypted, + "notset": IntegrationRuntimeInternalChannelEncryptionModeNotSet, + "sslencrypted": IntegrationRuntimeInternalChannelEncryptionModeSslEncrypted, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := IntegrationRuntimeInternalChannelEncryptionMode(input) + return &out, nil +} + +type IntegrationRuntimeLicenseType string + +const ( + IntegrationRuntimeLicenseTypeBasePrice IntegrationRuntimeLicenseType = "BasePrice" + IntegrationRuntimeLicenseTypeLicenseIncluded IntegrationRuntimeLicenseType = "LicenseIncluded" +) + +func PossibleValuesForIntegrationRuntimeLicenseType() []string { + return []string{ + string(IntegrationRuntimeLicenseTypeBasePrice), + string(IntegrationRuntimeLicenseTypeLicenseIncluded), + } +} + +func (s *IntegrationRuntimeLicenseType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseIntegrationRuntimeLicenseType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseIntegrationRuntimeLicenseType(input string) (*IntegrationRuntimeLicenseType, error) { + vals := map[string]IntegrationRuntimeLicenseType{ + "baseprice": IntegrationRuntimeLicenseTypeBasePrice, + "licenseincluded": IntegrationRuntimeLicenseTypeLicenseIncluded, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := IntegrationRuntimeLicenseType(input) + return &out, nil +} + +type IntegrationRuntimeSsisCatalogPricingTier string + +const ( + IntegrationRuntimeSsisCatalogPricingTierBasic IntegrationRuntimeSsisCatalogPricingTier = "Basic" + IntegrationRuntimeSsisCatalogPricingTierPremium IntegrationRuntimeSsisCatalogPricingTier = "Premium" + IntegrationRuntimeSsisCatalogPricingTierPremiumRS IntegrationRuntimeSsisCatalogPricingTier = "PremiumRS" + IntegrationRuntimeSsisCatalogPricingTierStandard IntegrationRuntimeSsisCatalogPricingTier = "Standard" +) + +func PossibleValuesForIntegrationRuntimeSsisCatalogPricingTier() []string { + return []string{ + string(IntegrationRuntimeSsisCatalogPricingTierBasic), + string(IntegrationRuntimeSsisCatalogPricingTierPremium), + string(IntegrationRuntimeSsisCatalogPricingTierPremiumRS), + string(IntegrationRuntimeSsisCatalogPricingTierStandard), + } +} + +func (s *IntegrationRuntimeSsisCatalogPricingTier) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseIntegrationRuntimeSsisCatalogPricingTier(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseIntegrationRuntimeSsisCatalogPricingTier(input string) (*IntegrationRuntimeSsisCatalogPricingTier, error) { + vals := map[string]IntegrationRuntimeSsisCatalogPricingTier{ + "basic": IntegrationRuntimeSsisCatalogPricingTierBasic, + "premium": IntegrationRuntimeSsisCatalogPricingTierPremium, + "premiumrs": IntegrationRuntimeSsisCatalogPricingTierPremiumRS, + "standard": IntegrationRuntimeSsisCatalogPricingTierStandard, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := IntegrationRuntimeSsisCatalogPricingTier(input) + return &out, nil +} + +type IntegrationRuntimeState string + +const ( + IntegrationRuntimeStateAccessDenied IntegrationRuntimeState = "AccessDenied" + IntegrationRuntimeStateInitial IntegrationRuntimeState = "Initial" + IntegrationRuntimeStateLimited IntegrationRuntimeState = "Limited" + IntegrationRuntimeStateNeedRegistration IntegrationRuntimeState = "NeedRegistration" + IntegrationRuntimeStateOffline IntegrationRuntimeState = "Offline" + IntegrationRuntimeStateOnline IntegrationRuntimeState = "Online" + IntegrationRuntimeStateStarted IntegrationRuntimeState = "Started" + IntegrationRuntimeStateStarting IntegrationRuntimeState = "Starting" + IntegrationRuntimeStateStopped IntegrationRuntimeState = "Stopped" + IntegrationRuntimeStateStopping IntegrationRuntimeState = "Stopping" +) + +func PossibleValuesForIntegrationRuntimeState() []string { + return []string{ + string(IntegrationRuntimeStateAccessDenied), + string(IntegrationRuntimeStateInitial), + string(IntegrationRuntimeStateLimited), + string(IntegrationRuntimeStateNeedRegistration), + string(IntegrationRuntimeStateOffline), + string(IntegrationRuntimeStateOnline), + string(IntegrationRuntimeStateStarted), + string(IntegrationRuntimeStateStarting), + string(IntegrationRuntimeStateStopped), + string(IntegrationRuntimeStateStopping), + } +} + +func (s *IntegrationRuntimeState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseIntegrationRuntimeState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseIntegrationRuntimeState(input string) (*IntegrationRuntimeState, error) { + vals := map[string]IntegrationRuntimeState{ + "accessdenied": IntegrationRuntimeStateAccessDenied, + "initial": IntegrationRuntimeStateInitial, + "limited": IntegrationRuntimeStateLimited, + "needregistration": IntegrationRuntimeStateNeedRegistration, + "offline": IntegrationRuntimeStateOffline, + "online": IntegrationRuntimeStateOnline, + "started": IntegrationRuntimeStateStarted, + "starting": IntegrationRuntimeStateStarting, + "stopped": IntegrationRuntimeStateStopped, + "stopping": IntegrationRuntimeStateStopping, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := IntegrationRuntimeState(input) + return &out, nil +} + +type IntegrationRuntimeType string + +const ( + IntegrationRuntimeTypeManaged IntegrationRuntimeType = "Managed" + IntegrationRuntimeTypeSelfHosted IntegrationRuntimeType = "SelfHosted" +) + +func PossibleValuesForIntegrationRuntimeType() []string { + return []string{ + string(IntegrationRuntimeTypeManaged), + string(IntegrationRuntimeTypeSelfHosted), + } +} + +func (s *IntegrationRuntimeType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseIntegrationRuntimeType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseIntegrationRuntimeType(input string) (*IntegrationRuntimeType, error) { + vals := map[string]IntegrationRuntimeType{ + "managed": IntegrationRuntimeTypeManaged, + "selfhosted": IntegrationRuntimeTypeSelfHosted, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := IntegrationRuntimeType(input) + return &out, nil +} + +type IntegrationRuntimeUpdateResult string + +const ( + IntegrationRuntimeUpdateResultFail IntegrationRuntimeUpdateResult = "Fail" + IntegrationRuntimeUpdateResultNone IntegrationRuntimeUpdateResult = "None" + IntegrationRuntimeUpdateResultSucceed IntegrationRuntimeUpdateResult = "Succeed" +) + +func PossibleValuesForIntegrationRuntimeUpdateResult() []string { + return []string{ + string(IntegrationRuntimeUpdateResultFail), + string(IntegrationRuntimeUpdateResultNone), + string(IntegrationRuntimeUpdateResultSucceed), + } +} + +func (s *IntegrationRuntimeUpdateResult) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseIntegrationRuntimeUpdateResult(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseIntegrationRuntimeUpdateResult(input string) (*IntegrationRuntimeUpdateResult, error) { + vals := map[string]IntegrationRuntimeUpdateResult{ + "fail": IntegrationRuntimeUpdateResultFail, + "none": IntegrationRuntimeUpdateResultNone, + "succeed": IntegrationRuntimeUpdateResultSucceed, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := IntegrationRuntimeUpdateResult(input) + return &out, nil +} + +type ManagedIntegrationRuntimeNodeStatus string + +const ( + ManagedIntegrationRuntimeNodeStatusAvailable ManagedIntegrationRuntimeNodeStatus = "Available" + ManagedIntegrationRuntimeNodeStatusRecycling ManagedIntegrationRuntimeNodeStatus = "Recycling" + ManagedIntegrationRuntimeNodeStatusStarting ManagedIntegrationRuntimeNodeStatus = "Starting" + ManagedIntegrationRuntimeNodeStatusUnavailable ManagedIntegrationRuntimeNodeStatus = "Unavailable" +) + +func PossibleValuesForManagedIntegrationRuntimeNodeStatus() []string { + return []string{ + string(ManagedIntegrationRuntimeNodeStatusAvailable), + string(ManagedIntegrationRuntimeNodeStatusRecycling), + string(ManagedIntegrationRuntimeNodeStatusStarting), + string(ManagedIntegrationRuntimeNodeStatusUnavailable), + } +} + +func (s *ManagedIntegrationRuntimeNodeStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseManagedIntegrationRuntimeNodeStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseManagedIntegrationRuntimeNodeStatus(input string) (*ManagedIntegrationRuntimeNodeStatus, error) { + vals := map[string]ManagedIntegrationRuntimeNodeStatus{ + "available": ManagedIntegrationRuntimeNodeStatusAvailable, + "recycling": ManagedIntegrationRuntimeNodeStatusRecycling, + "starting": ManagedIntegrationRuntimeNodeStatusStarting, + "unavailable": ManagedIntegrationRuntimeNodeStatusUnavailable, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ManagedIntegrationRuntimeNodeStatus(input) + return &out, nil +} + +type SelfHostedIntegrationRuntimeNodeStatus string + +const ( + SelfHostedIntegrationRuntimeNodeStatusInitializeFailed SelfHostedIntegrationRuntimeNodeStatus = "InitializeFailed" + SelfHostedIntegrationRuntimeNodeStatusInitializing SelfHostedIntegrationRuntimeNodeStatus = "Initializing" + SelfHostedIntegrationRuntimeNodeStatusLimited SelfHostedIntegrationRuntimeNodeStatus = "Limited" + SelfHostedIntegrationRuntimeNodeStatusNeedRegistration SelfHostedIntegrationRuntimeNodeStatus = "NeedRegistration" + SelfHostedIntegrationRuntimeNodeStatusOffline SelfHostedIntegrationRuntimeNodeStatus = "Offline" + SelfHostedIntegrationRuntimeNodeStatusOnline SelfHostedIntegrationRuntimeNodeStatus = "Online" + SelfHostedIntegrationRuntimeNodeStatusUpgrading SelfHostedIntegrationRuntimeNodeStatus = "Upgrading" +) + +func PossibleValuesForSelfHostedIntegrationRuntimeNodeStatus() []string { + return []string{ + string(SelfHostedIntegrationRuntimeNodeStatusInitializeFailed), + string(SelfHostedIntegrationRuntimeNodeStatusInitializing), + string(SelfHostedIntegrationRuntimeNodeStatusLimited), + string(SelfHostedIntegrationRuntimeNodeStatusNeedRegistration), + string(SelfHostedIntegrationRuntimeNodeStatusOffline), + string(SelfHostedIntegrationRuntimeNodeStatusOnline), + string(SelfHostedIntegrationRuntimeNodeStatusUpgrading), + } +} + +func (s *SelfHostedIntegrationRuntimeNodeStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseSelfHostedIntegrationRuntimeNodeStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseSelfHostedIntegrationRuntimeNodeStatus(input string) (*SelfHostedIntegrationRuntimeNodeStatus, error) { + vals := map[string]SelfHostedIntegrationRuntimeNodeStatus{ + "initializefailed": SelfHostedIntegrationRuntimeNodeStatusInitializeFailed, + "initializing": SelfHostedIntegrationRuntimeNodeStatusInitializing, + "limited": SelfHostedIntegrationRuntimeNodeStatusLimited, + "needregistration": SelfHostedIntegrationRuntimeNodeStatusNeedRegistration, + "offline": SelfHostedIntegrationRuntimeNodeStatusOffline, + "online": SelfHostedIntegrationRuntimeNodeStatusOnline, + "upgrading": SelfHostedIntegrationRuntimeNodeStatusUpgrading, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := SelfHostedIntegrationRuntimeNodeStatus(input) + return &out, nil +} + +type SsisObjectMetadataType string + +const ( + SsisObjectMetadataTypeEnvironment SsisObjectMetadataType = "Environment" + SsisObjectMetadataTypeFolder SsisObjectMetadataType = "Folder" + SsisObjectMetadataTypePackage SsisObjectMetadataType = "Package" + SsisObjectMetadataTypeProject SsisObjectMetadataType = "Project" +) + +func PossibleValuesForSsisObjectMetadataType() []string { + return []string{ + string(SsisObjectMetadataTypeEnvironment), + string(SsisObjectMetadataTypeFolder), + string(SsisObjectMetadataTypePackage), + string(SsisObjectMetadataTypeProject), + } +} + +func (s *SsisObjectMetadataType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseSsisObjectMetadataType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseSsisObjectMetadataType(input string) (*SsisObjectMetadataType, error) { + vals := map[string]SsisObjectMetadataType{ + "environment": SsisObjectMetadataTypeEnvironment, + "folder": SsisObjectMetadataTypeFolder, + "package": SsisObjectMetadataTypePackage, + "project": SsisObjectMetadataTypeProject, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := SsisObjectMetadataType(input) + return &out, nil +} diff --git a/resource-manager/synapse/2021-06-01/integrationruntime/id_integrationruntime.go b/resource-manager/synapse/2021-06-01/integrationruntime/id_integrationruntime.go new file mode 100644 index 00000000000..e88aa40ecf3 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/integrationruntime/id_integrationruntime.go @@ -0,0 +1,134 @@ +package integrationruntime + +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 = &IntegrationRuntimeId{} + +// IntegrationRuntimeId is a struct representing the Resource ID for a Integration Runtime +type IntegrationRuntimeId struct { + SubscriptionId string + ResourceGroupName string + WorkspaceName string + IntegrationRuntimeName string +} + +// NewIntegrationRuntimeID returns a new IntegrationRuntimeId struct +func NewIntegrationRuntimeID(subscriptionId string, resourceGroupName string, workspaceName string, integrationRuntimeName string) IntegrationRuntimeId { + return IntegrationRuntimeId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + WorkspaceName: workspaceName, + IntegrationRuntimeName: integrationRuntimeName, + } +} + +// ParseIntegrationRuntimeID parses 'input' into a IntegrationRuntimeId +func ParseIntegrationRuntimeID(input string) (*IntegrationRuntimeId, error) { + parser := resourceids.NewParserFromResourceIdType(&IntegrationRuntimeId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := IntegrationRuntimeId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseIntegrationRuntimeIDInsensitively parses 'input' case-insensitively into a IntegrationRuntimeId +// note: this method should only be used for API response data and not user input +func ParseIntegrationRuntimeIDInsensitively(input string) (*IntegrationRuntimeId, error) { + parser := resourceids.NewParserFromResourceIdType(&IntegrationRuntimeId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := IntegrationRuntimeId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *IntegrationRuntimeId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.WorkspaceName, ok = input.Parsed["workspaceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "workspaceName", input) + } + + if id.IntegrationRuntimeName, ok = input.Parsed["integrationRuntimeName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "integrationRuntimeName", input) + } + + return nil +} + +// ValidateIntegrationRuntimeID checks that 'input' can be parsed as a Integration Runtime ID +func ValidateIntegrationRuntimeID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseIntegrationRuntimeID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Integration Runtime ID +func (id IntegrationRuntimeId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Synapse/workspaces/%s/integrationRuntimes/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.WorkspaceName, id.IntegrationRuntimeName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Integration Runtime ID +func (id IntegrationRuntimeId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftSynapse", "Microsoft.Synapse", "Microsoft.Synapse"), + resourceids.StaticSegment("staticWorkspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceName", "workspaceValue"), + resourceids.StaticSegment("staticIntegrationRuntimes", "integrationRuntimes", "integrationRuntimes"), + resourceids.UserSpecifiedSegment("integrationRuntimeName", "integrationRuntimeValue"), + } +} + +// String returns a human-readable description of this Integration Runtime ID +func (id IntegrationRuntimeId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Workspace Name: %q", id.WorkspaceName), + fmt.Sprintf("Integration Runtime Name: %q", id.IntegrationRuntimeName), + } + return fmt.Sprintf("Integration Runtime (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/synapse/2021-06-01/integrationruntime/id_integrationruntime_test.go b/resource-manager/synapse/2021-06-01/integrationruntime/id_integrationruntime_test.go new file mode 100644 index 00000000000..9ad8adffa72 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/integrationruntime/id_integrationruntime_test.go @@ -0,0 +1,327 @@ +package integrationruntime + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &IntegrationRuntimeId{} + +func TestNewIntegrationRuntimeID(t *testing.T) { + id := NewIntegrationRuntimeID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "integrationRuntimeValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.WorkspaceName != "workspaceValue" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceName'", id.WorkspaceName, "workspaceValue") + } + + if id.IntegrationRuntimeName != "integrationRuntimeValue" { + t.Fatalf("Expected %q but got %q for Segment 'IntegrationRuntimeName'", id.IntegrationRuntimeName, "integrationRuntimeValue") + } +} + +func TestFormatIntegrationRuntimeID(t *testing.T) { + actual := NewIntegrationRuntimeID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "integrationRuntimeValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/integrationRuntimes/integrationRuntimeValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseIntegrationRuntimeID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *IntegrationRuntimeId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/integrationRuntimes", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/integrationRuntimes/integrationRuntimeValue", + Expected: &IntegrationRuntimeId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + IntegrationRuntimeName: "integrationRuntimeValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/integrationRuntimes/integrationRuntimeValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseIntegrationRuntimeID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + if actual.IntegrationRuntimeName != v.Expected.IntegrationRuntimeName { + t.Fatalf("Expected %q but got %q for IntegrationRuntimeName", v.Expected.IntegrationRuntimeName, actual.IntegrationRuntimeName) + } + + } +} + +func TestParseIntegrationRuntimeIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *IntegrationRuntimeId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/integrationRuntimes", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/iNtEgRaTiOnRuNtImEs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/integrationRuntimes/integrationRuntimeValue", + Expected: &IntegrationRuntimeId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + IntegrationRuntimeName: "integrationRuntimeValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/integrationRuntimes/integrationRuntimeValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/iNtEgRaTiOnRuNtImEs/iNtEgRaTiOnRuNtImEvAlUe", + Expected: &IntegrationRuntimeId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + WorkspaceName: "wOrKsPaCeVaLuE", + IntegrationRuntimeName: "iNtEgRaTiOnRuNtImEvAlUe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/iNtEgRaTiOnRuNtImEs/iNtEgRaTiOnRuNtImEvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseIntegrationRuntimeIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + if actual.IntegrationRuntimeName != v.Expected.IntegrationRuntimeName { + t.Fatalf("Expected %q but got %q for IntegrationRuntimeName", v.Expected.IntegrationRuntimeName, actual.IntegrationRuntimeName) + } + + } +} + +func TestSegmentsForIntegrationRuntimeId(t *testing.T) { + segments := IntegrationRuntimeId{}.Segments() + if len(segments) == 0 { + t.Fatalf("IntegrationRuntimeId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/synapse/2021-06-01/integrationruntime/id_node.go b/resource-manager/synapse/2021-06-01/integrationruntime/id_node.go new file mode 100644 index 00000000000..fbbe94c633a --- /dev/null +++ b/resource-manager/synapse/2021-06-01/integrationruntime/id_node.go @@ -0,0 +1,143 @@ +package integrationruntime + +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 = &NodeId{} + +// NodeId is a struct representing the Resource ID for a Node +type NodeId struct { + SubscriptionId string + ResourceGroupName string + WorkspaceName string + IntegrationRuntimeName string + NodeName string +} + +// NewNodeID returns a new NodeId struct +func NewNodeID(subscriptionId string, resourceGroupName string, workspaceName string, integrationRuntimeName string, nodeName string) NodeId { + return NodeId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + WorkspaceName: workspaceName, + IntegrationRuntimeName: integrationRuntimeName, + NodeName: nodeName, + } +} + +// ParseNodeID parses 'input' into a NodeId +func ParseNodeID(input string) (*NodeId, error) { + parser := resourceids.NewParserFromResourceIdType(&NodeId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := NodeId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseNodeIDInsensitively parses 'input' case-insensitively into a NodeId +// note: this method should only be used for API response data and not user input +func ParseNodeIDInsensitively(input string) (*NodeId, error) { + parser := resourceids.NewParserFromResourceIdType(&NodeId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := NodeId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *NodeId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.WorkspaceName, ok = input.Parsed["workspaceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "workspaceName", input) + } + + if id.IntegrationRuntimeName, ok = input.Parsed["integrationRuntimeName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "integrationRuntimeName", input) + } + + if id.NodeName, ok = input.Parsed["nodeName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "nodeName", input) + } + + return nil +} + +// ValidateNodeID checks that 'input' can be parsed as a Node ID +func ValidateNodeID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseNodeID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Node ID +func (id NodeId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Synapse/workspaces/%s/integrationRuntimes/%s/nodes/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.WorkspaceName, id.IntegrationRuntimeName, id.NodeName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Node ID +func (id NodeId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftSynapse", "Microsoft.Synapse", "Microsoft.Synapse"), + resourceids.StaticSegment("staticWorkspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceName", "workspaceValue"), + resourceids.StaticSegment("staticIntegrationRuntimes", "integrationRuntimes", "integrationRuntimes"), + resourceids.UserSpecifiedSegment("integrationRuntimeName", "integrationRuntimeValue"), + resourceids.StaticSegment("staticNodes", "nodes", "nodes"), + resourceids.UserSpecifiedSegment("nodeName", "nodeValue"), + } +} + +// String returns a human-readable description of this Node ID +func (id NodeId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Workspace Name: %q", id.WorkspaceName), + fmt.Sprintf("Integration Runtime Name: %q", id.IntegrationRuntimeName), + fmt.Sprintf("Node Name: %q", id.NodeName), + } + return fmt.Sprintf("Node (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/synapse/2021-06-01/integrationruntime/id_node_test.go b/resource-manager/synapse/2021-06-01/integrationruntime/id_node_test.go new file mode 100644 index 00000000000..13029e209d9 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/integrationruntime/id_node_test.go @@ -0,0 +1,372 @@ +package integrationruntime + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &NodeId{} + +func TestNewNodeID(t *testing.T) { + id := NewNodeID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "integrationRuntimeValue", "nodeValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.WorkspaceName != "workspaceValue" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceName'", id.WorkspaceName, "workspaceValue") + } + + if id.IntegrationRuntimeName != "integrationRuntimeValue" { + t.Fatalf("Expected %q but got %q for Segment 'IntegrationRuntimeName'", id.IntegrationRuntimeName, "integrationRuntimeValue") + } + + if id.NodeName != "nodeValue" { + t.Fatalf("Expected %q but got %q for Segment 'NodeName'", id.NodeName, "nodeValue") + } +} + +func TestFormatNodeID(t *testing.T) { + actual := NewNodeID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "integrationRuntimeValue", "nodeValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/integrationRuntimes/integrationRuntimeValue/nodes/nodeValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseNodeID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *NodeId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/integrationRuntimes", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/integrationRuntimes/integrationRuntimeValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/integrationRuntimes/integrationRuntimeValue/nodes", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/integrationRuntimes/integrationRuntimeValue/nodes/nodeValue", + Expected: &NodeId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + IntegrationRuntimeName: "integrationRuntimeValue", + NodeName: "nodeValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/integrationRuntimes/integrationRuntimeValue/nodes/nodeValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseNodeID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + if actual.IntegrationRuntimeName != v.Expected.IntegrationRuntimeName { + t.Fatalf("Expected %q but got %q for IntegrationRuntimeName", v.Expected.IntegrationRuntimeName, actual.IntegrationRuntimeName) + } + + if actual.NodeName != v.Expected.NodeName { + t.Fatalf("Expected %q but got %q for NodeName", v.Expected.NodeName, actual.NodeName) + } + + } +} + +func TestParseNodeIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *NodeId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/integrationRuntimes", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/iNtEgRaTiOnRuNtImEs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/integrationRuntimes/integrationRuntimeValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/iNtEgRaTiOnRuNtImEs/iNtEgRaTiOnRuNtImEvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/integrationRuntimes/integrationRuntimeValue/nodes", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/iNtEgRaTiOnRuNtImEs/iNtEgRaTiOnRuNtImEvAlUe/nOdEs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/integrationRuntimes/integrationRuntimeValue/nodes/nodeValue", + Expected: &NodeId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + IntegrationRuntimeName: "integrationRuntimeValue", + NodeName: "nodeValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/integrationRuntimes/integrationRuntimeValue/nodes/nodeValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/iNtEgRaTiOnRuNtImEs/iNtEgRaTiOnRuNtImEvAlUe/nOdEs/nOdEvAlUe", + Expected: &NodeId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + WorkspaceName: "wOrKsPaCeVaLuE", + IntegrationRuntimeName: "iNtEgRaTiOnRuNtImEvAlUe", + NodeName: "nOdEvAlUe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/iNtEgRaTiOnRuNtImEs/iNtEgRaTiOnRuNtImEvAlUe/nOdEs/nOdEvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseNodeIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + if actual.IntegrationRuntimeName != v.Expected.IntegrationRuntimeName { + t.Fatalf("Expected %q but got %q for IntegrationRuntimeName", v.Expected.IntegrationRuntimeName, actual.IntegrationRuntimeName) + } + + if actual.NodeName != v.Expected.NodeName { + t.Fatalf("Expected %q but got %q for NodeName", v.Expected.NodeName, actual.NodeName) + } + + } +} + +func TestSegmentsForNodeId(t *testing.T) { + segments := NodeId{}.Segments() + if len(segments) == 0 { + t.Fatalf("NodeId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/synapse/2021-06-01/integrationruntime/id_workspace.go b/resource-manager/synapse/2021-06-01/integrationruntime/id_workspace.go new file mode 100644 index 00000000000..0b4c524c566 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/integrationruntime/id_workspace.go @@ -0,0 +1,125 @@ +package integrationruntime + +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 = &WorkspaceId{} + +// WorkspaceId is a struct representing the Resource ID for a Workspace +type WorkspaceId struct { + SubscriptionId string + ResourceGroupName string + WorkspaceName string +} + +// NewWorkspaceID returns a new WorkspaceId struct +func NewWorkspaceID(subscriptionId string, resourceGroupName string, workspaceName string) WorkspaceId { + return WorkspaceId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + WorkspaceName: workspaceName, + } +} + +// ParseWorkspaceID parses 'input' into a WorkspaceId +func ParseWorkspaceID(input string) (*WorkspaceId, error) { + parser := resourceids.NewParserFromResourceIdType(&WorkspaceId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := WorkspaceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseWorkspaceIDInsensitively parses 'input' case-insensitively into a WorkspaceId +// note: this method should only be used for API response data and not user input +func ParseWorkspaceIDInsensitively(input string) (*WorkspaceId, error) { + parser := resourceids.NewParserFromResourceIdType(&WorkspaceId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := WorkspaceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *WorkspaceId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.WorkspaceName, ok = input.Parsed["workspaceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "workspaceName", input) + } + + return nil +} + +// ValidateWorkspaceID checks that 'input' can be parsed as a Workspace ID +func ValidateWorkspaceID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseWorkspaceID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Workspace ID +func (id WorkspaceId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Synapse/workspaces/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.WorkspaceName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Workspace ID +func (id WorkspaceId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftSynapse", "Microsoft.Synapse", "Microsoft.Synapse"), + resourceids.StaticSegment("staticWorkspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceName", "workspaceValue"), + } +} + +// String returns a human-readable description of this Workspace ID +func (id WorkspaceId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Workspace Name: %q", id.WorkspaceName), + } + return fmt.Sprintf("Workspace (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/synapse/2021-06-01/integrationruntime/id_workspace_test.go b/resource-manager/synapse/2021-06-01/integrationruntime/id_workspace_test.go new file mode 100644 index 00000000000..d7a6eb29b23 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/integrationruntime/id_workspace_test.go @@ -0,0 +1,282 @@ +package integrationruntime + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &WorkspaceId{} + +func TestNewWorkspaceID(t *testing.T) { + id := NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.WorkspaceName != "workspaceValue" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceName'", id.WorkspaceName, "workspaceValue") + } +} + +func TestFormatWorkspaceID(t *testing.T) { + actual := NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseWorkspaceID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkspaceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue", + Expected: &WorkspaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkspaceID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + } +} + +func TestParseWorkspaceIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkspaceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue", + Expected: &WorkspaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE", + Expected: &WorkspaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + WorkspaceName: "wOrKsPaCeVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkspaceIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + } +} + +func TestSegmentsForWorkspaceId(t *testing.T) { + segments := WorkspaceId{}.Segments() + if len(segments) == 0 { + t.Fatalf("WorkspaceId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/synapse/2021-06-01/integrationruntime/method_authkeyslist.go b/resource-manager/synapse/2021-06-01/integrationruntime/method_authkeyslist.go new file mode 100644 index 00000000000..553a0f90cd0 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/integrationruntime/method_authkeyslist.go @@ -0,0 +1,52 @@ +package integrationruntime + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AuthKeysListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *IntegrationRuntimeAuthKeys +} + +// AuthKeysList ... +func (c IntegrationRuntimeClient) AuthKeysList(ctx context.Context, id IntegrationRuntimeId) (result AuthKeysListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/listAuthKeys", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/synapse/2021-06-01/integrationruntime/method_authkeysregenerate.go b/resource-manager/synapse/2021-06-01/integrationruntime/method_authkeysregenerate.go new file mode 100644 index 00000000000..8c33e65b982 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/integrationruntime/method_authkeysregenerate.go @@ -0,0 +1,56 @@ +package integrationruntime + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AuthKeysRegenerateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *IntegrationRuntimeAuthKeys +} + +// AuthKeysRegenerate ... +func (c IntegrationRuntimeClient) AuthKeysRegenerate(ctx context.Context, id IntegrationRuntimeId, input IntegrationRuntimeRegenerateKeyParameters) (result AuthKeysRegenerateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/regenerateAuthKey", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/synapse/2021-06-01/integrationruntime/method_connectioninfosget.go b/resource-manager/synapse/2021-06-01/integrationruntime/method_connectioninfosget.go new file mode 100644 index 00000000000..5fa5e324d4c --- /dev/null +++ b/resource-manager/synapse/2021-06-01/integrationruntime/method_connectioninfosget.go @@ -0,0 +1,52 @@ +package integrationruntime + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ConnectionInfosGetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *IntegrationRuntimeConnectionInfo +} + +// ConnectionInfosGet ... +func (c IntegrationRuntimeClient) ConnectionInfosGet(ctx context.Context, id IntegrationRuntimeId) (result ConnectionInfosGetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/getConnectionInfo", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/synapse/2021-06-01/integrationruntime/method_create.go b/resource-manager/synapse/2021-06-01/integrationruntime/method_create.go new file mode 100644 index 00000000000..bfd57bd9ca3 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/integrationruntime/method_create.go @@ -0,0 +1,103 @@ +package integrationruntime + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *IntegrationRuntimeResource +} + +type CreateOperationOptions struct { + IfMatch *string +} + +func DefaultCreateOperationOptions() CreateOperationOptions { + return CreateOperationOptions{} +} + +func (o CreateOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o CreateOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o CreateOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// Create ... +func (c IntegrationRuntimeClient) Create(ctx context.Context, id IntegrationRuntimeId, input IntegrationRuntimeResource, options CreateOperationOptions) (result CreateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + OptionsObject: options, + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// CreateThenPoll performs Create then polls until it's completed +func (c IntegrationRuntimeClient) CreateThenPoll(ctx context.Context, id IntegrationRuntimeId, input IntegrationRuntimeResource, options CreateOperationOptions) error { + result, err := c.Create(ctx, id, input, options) + if err != nil { + return fmt.Errorf("performing Create: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after Create: %+v", err) + } + + return nil +} diff --git a/resource-manager/synapse/2021-06-01/integrationruntime/method_credentialssync.go b/resource-manager/synapse/2021-06-01/integrationruntime/method_credentialssync.go new file mode 100644 index 00000000000..cacb3ffcd7e --- /dev/null +++ b/resource-manager/synapse/2021-06-01/integrationruntime/method_credentialssync.go @@ -0,0 +1,47 @@ +package integrationruntime + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CredentialsSyncOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// CredentialsSync ... +func (c IntegrationRuntimeClient) CredentialsSync(ctx context.Context, id IntegrationRuntimeId) (result CredentialsSyncOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/syncCredentials", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/synapse/2021-06-01/integrationruntime/method_delete.go b/resource-manager/synapse/2021-06-01/integrationruntime/method_delete.go new file mode 100644 index 00000000000..901b3620d4a --- /dev/null +++ b/resource-manager/synapse/2021-06-01/integrationruntime/method_delete.go @@ -0,0 +1,71 @@ +package integrationruntime + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// Delete ... +func (c IntegrationRuntimeClient) Delete(ctx context.Context, id IntegrationRuntimeId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// DeleteThenPoll performs Delete then polls until it's completed +func (c IntegrationRuntimeClient) DeleteThenPoll(ctx context.Context, id IntegrationRuntimeId) error { + result, err := c.Delete(ctx, id) + if err != nil { + return fmt.Errorf("performing Delete: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after Delete: %+v", err) + } + + return nil +} diff --git a/resource-manager/synapse/2021-06-01/integrationruntime/method_disableinteractivequery.go b/resource-manager/synapse/2021-06-01/integrationruntime/method_disableinteractivequery.go new file mode 100644 index 00000000000..064f0c78ed4 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/integrationruntime/method_disableinteractivequery.go @@ -0,0 +1,70 @@ +package integrationruntime + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DisableInteractiveQueryOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// DisableInteractiveQuery ... +func (c IntegrationRuntimeClient) DisableInteractiveQuery(ctx context.Context, id IntegrationRuntimeId) (result DisableInteractiveQueryOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/disableInteractiveQuery", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// DisableInteractiveQueryThenPoll performs DisableInteractiveQuery then polls until it's completed +func (c IntegrationRuntimeClient) DisableInteractiveQueryThenPoll(ctx context.Context, id IntegrationRuntimeId) error { + result, err := c.DisableInteractiveQuery(ctx, id) + if err != nil { + return fmt.Errorf("performing DisableInteractiveQuery: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after DisableInteractiveQuery: %+v", err) + } + + return nil +} diff --git a/resource-manager/synapse/2021-06-01/integrationruntime/method_enableinteractivequery.go b/resource-manager/synapse/2021-06-01/integrationruntime/method_enableinteractivequery.go new file mode 100644 index 00000000000..ea36e822af8 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/integrationruntime/method_enableinteractivequery.go @@ -0,0 +1,70 @@ +package integrationruntime + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type EnableInteractiveQueryOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// EnableInteractiveQuery ... +func (c IntegrationRuntimeClient) EnableInteractiveQuery(ctx context.Context, id IntegrationRuntimeId) (result EnableInteractiveQueryOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/enableInteractiveQuery", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// EnableInteractiveQueryThenPoll performs EnableInteractiveQuery then polls until it's completed +func (c IntegrationRuntimeClient) EnableInteractiveQueryThenPoll(ctx context.Context, id IntegrationRuntimeId) error { + result, err := c.EnableInteractiveQuery(ctx, id) + if err != nil { + return fmt.Errorf("performing EnableInteractiveQuery: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after EnableInteractiveQuery: %+v", err) + } + + return nil +} diff --git a/resource-manager/synapse/2021-06-01/integrationruntime/method_get.go b/resource-manager/synapse/2021-06-01/integrationruntime/method_get.go new file mode 100644 index 00000000000..02493acdaaf --- /dev/null +++ b/resource-manager/synapse/2021-06-01/integrationruntime/method_get.go @@ -0,0 +1,80 @@ +package integrationruntime + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *IntegrationRuntimeResource +} + +type GetOperationOptions struct { + IfNoneMatch *string +} + +func DefaultGetOperationOptions() GetOperationOptions { + return GetOperationOptions{} +} + +func (o GetOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfNoneMatch != nil { + out.Append("If-None-Match", fmt.Sprintf("%v", *o.IfNoneMatch)) + } + return &out +} + +func (o GetOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o GetOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// Get ... +func (c IntegrationRuntimeClient) Get(ctx context.Context, id IntegrationRuntimeId, options GetOperationOptions) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + OptionsObject: options, + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/synapse/2021-06-01/integrationruntime/method_listbyworkspace.go b/resource-manager/synapse/2021-06-01/integrationruntime/method_listbyworkspace.go new file mode 100644 index 00000000000..cd68a623128 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/integrationruntime/method_listbyworkspace.go @@ -0,0 +1,91 @@ +package integrationruntime + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListByWorkspaceOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]IntegrationRuntimeResource +} + +type ListByWorkspaceCompleteResult struct { + LatestHttpResponse *http.Response + Items []IntegrationRuntimeResource +} + +// ListByWorkspace ... +func (c IntegrationRuntimeClient) ListByWorkspace(ctx context.Context, id WorkspaceId) (result ListByWorkspaceOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/integrationRuntimes", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]IntegrationRuntimeResource `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByWorkspaceComplete retrieves all the results into a single object +func (c IntegrationRuntimeClient) ListByWorkspaceComplete(ctx context.Context, id WorkspaceId) (ListByWorkspaceCompleteResult, error) { + return c.ListByWorkspaceCompleteMatchingPredicate(ctx, id, IntegrationRuntimeResourceOperationPredicate{}) +} + +// ListByWorkspaceCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c IntegrationRuntimeClient) ListByWorkspaceCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, predicate IntegrationRuntimeResourceOperationPredicate) (result ListByWorkspaceCompleteResult, err error) { + items := make([]IntegrationRuntimeResource, 0) + + resp, err := c.ListByWorkspace(ctx, id) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByWorkspaceCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/synapse/2021-06-01/integrationruntime/method_monitoringdatalist.go b/resource-manager/synapse/2021-06-01/integrationruntime/method_monitoringdatalist.go new file mode 100644 index 00000000000..4f41a74bcae --- /dev/null +++ b/resource-manager/synapse/2021-06-01/integrationruntime/method_monitoringdatalist.go @@ -0,0 +1,52 @@ +package integrationruntime + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MonitoringDataListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *IntegrationRuntimeMonitoringData +} + +// MonitoringDataList ... +func (c IntegrationRuntimeClient) MonitoringDataList(ctx context.Context, id IntegrationRuntimeId) (result MonitoringDataListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/monitoringData", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/synapse/2021-06-01/integrationruntime/method_nodeipaddressget.go b/resource-manager/synapse/2021-06-01/integrationruntime/method_nodeipaddressget.go new file mode 100644 index 00000000000..578472e8849 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/integrationruntime/method_nodeipaddressget.go @@ -0,0 +1,52 @@ +package integrationruntime + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type NodeIPAddressGetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *IntegrationRuntimeNodeIPAddress +} + +// NodeIPAddressGet ... +func (c IntegrationRuntimeClient) NodeIPAddressGet(ctx context.Context, id NodeId) (result NodeIPAddressGetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/ipAddress", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/synapse/2021-06-01/integrationruntime/method_nodesdelete.go b/resource-manager/synapse/2021-06-01/integrationruntime/method_nodesdelete.go new file mode 100644 index 00000000000..120ced13c3f --- /dev/null +++ b/resource-manager/synapse/2021-06-01/integrationruntime/method_nodesdelete.go @@ -0,0 +1,47 @@ +package integrationruntime + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type NodesDeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// NodesDelete ... +func (c IntegrationRuntimeClient) NodesDelete(ctx context.Context, id NodeId) (result NodesDeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/synapse/2021-06-01/integrationruntime/method_nodesget.go b/resource-manager/synapse/2021-06-01/integrationruntime/method_nodesget.go new file mode 100644 index 00000000000..56b856c8f78 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/integrationruntime/method_nodesget.go @@ -0,0 +1,51 @@ +package integrationruntime + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type NodesGetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *SelfHostedIntegrationRuntimeNode +} + +// NodesGet ... +func (c IntegrationRuntimeClient) NodesGet(ctx context.Context, id NodeId) (result NodesGetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/synapse/2021-06-01/integrationruntime/method_nodesupdate.go b/resource-manager/synapse/2021-06-01/integrationruntime/method_nodesupdate.go new file mode 100644 index 00000000000..a71b2fb24a2 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/integrationruntime/method_nodesupdate.go @@ -0,0 +1,55 @@ +package integrationruntime + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type NodesUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *SelfHostedIntegrationRuntimeNode +} + +// NodesUpdate ... +func (c IntegrationRuntimeClient) NodesUpdate(ctx context.Context, id NodeId, input UpdateIntegrationRuntimeNodeRequest) (result NodesUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPatch, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/synapse/2021-06-01/integrationruntime/method_objectmetadatalist.go b/resource-manager/synapse/2021-06-01/integrationruntime/method_objectmetadatalist.go new file mode 100644 index 00000000000..c8376235ec7 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/integrationruntime/method_objectmetadatalist.go @@ -0,0 +1,56 @@ +package integrationruntime + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ObjectMetadataListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *SsisObjectMetadataListResponse +} + +// ObjectMetadataList ... +func (c IntegrationRuntimeClient) ObjectMetadataList(ctx context.Context, id IntegrationRuntimeId, input GetSsisObjectMetadataRequest) (result ObjectMetadataListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/getObjectMetadata", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/synapse/2021-06-01/integrationruntime/method_objectmetadatarefresh.go b/resource-manager/synapse/2021-06-01/integrationruntime/method_objectmetadatarefresh.go new file mode 100644 index 00000000000..896f30e7ad0 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/integrationruntime/method_objectmetadatarefresh.go @@ -0,0 +1,71 @@ +package integrationruntime + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ObjectMetadataRefreshOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *SsisObjectMetadataStatusResponse +} + +// ObjectMetadataRefresh ... +func (c IntegrationRuntimeClient) ObjectMetadataRefresh(ctx context.Context, id IntegrationRuntimeId) (result ObjectMetadataRefreshOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/refreshObjectMetadata", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// ObjectMetadataRefreshThenPoll performs ObjectMetadataRefresh then polls until it's completed +func (c IntegrationRuntimeClient) ObjectMetadataRefreshThenPoll(ctx context.Context, id IntegrationRuntimeId) error { + result, err := c.ObjectMetadataRefresh(ctx, id) + if err != nil { + return fmt.Errorf("performing ObjectMetadataRefresh: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after ObjectMetadataRefresh: %+v", err) + } + + return nil +} diff --git a/resource-manager/synapse/2021-06-01/integrationruntime/method_start.go b/resource-manager/synapse/2021-06-01/integrationruntime/method_start.go new file mode 100644 index 00000000000..776c4d0a900 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/integrationruntime/method_start.go @@ -0,0 +1,71 @@ +package integrationruntime + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type StartOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *IntegrationRuntimeStatusResponse +} + +// Start ... +func (c IntegrationRuntimeClient) Start(ctx context.Context, id IntegrationRuntimeId) (result StartOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/start", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// StartThenPoll performs Start then polls until it's completed +func (c IntegrationRuntimeClient) StartThenPoll(ctx context.Context, id IntegrationRuntimeId) error { + result, err := c.Start(ctx, id) + if err != nil { + return fmt.Errorf("performing Start: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after Start: %+v", err) + } + + return nil +} diff --git a/resource-manager/synapse/2021-06-01/integrationruntime/method_statusget.go b/resource-manager/synapse/2021-06-01/integrationruntime/method_statusget.go new file mode 100644 index 00000000000..bbd0f82cc15 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/integrationruntime/method_statusget.go @@ -0,0 +1,52 @@ +package integrationruntime + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type StatusGetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *IntegrationRuntimeStatusResponse +} + +// StatusGet ... +func (c IntegrationRuntimeClient) StatusGet(ctx context.Context, id IntegrationRuntimeId) (result StatusGetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/getStatus", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/synapse/2021-06-01/integrationruntime/method_stop.go b/resource-manager/synapse/2021-06-01/integrationruntime/method_stop.go new file mode 100644 index 00000000000..eb4fd782b50 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/integrationruntime/method_stop.go @@ -0,0 +1,70 @@ +package integrationruntime + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type StopOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// Stop ... +func (c IntegrationRuntimeClient) Stop(ctx context.Context, id IntegrationRuntimeId) (result StopOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/stop", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// StopThenPoll performs Stop then polls until it's completed +func (c IntegrationRuntimeClient) StopThenPoll(ctx context.Context, id IntegrationRuntimeId) error { + result, err := c.Stop(ctx, id) + if err != nil { + return fmt.Errorf("performing Stop: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after Stop: %+v", err) + } + + return nil +} diff --git a/resource-manager/synapse/2021-06-01/integrationruntime/method_update.go b/resource-manager/synapse/2021-06-01/integrationruntime/method_update.go new file mode 100644 index 00000000000..d3771a65a12 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/integrationruntime/method_update.go @@ -0,0 +1,55 @@ +package integrationruntime + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type UpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *IntegrationRuntimeResource +} + +// Update ... +func (c IntegrationRuntimeClient) Update(ctx context.Context, id IntegrationRuntimeId, input UpdateIntegrationRuntimeRequest) (result UpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPatch, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/synapse/2021-06-01/integrationruntime/method_upgrade.go b/resource-manager/synapse/2021-06-01/integrationruntime/method_upgrade.go new file mode 100644 index 00000000000..e49a91e3f0d --- /dev/null +++ b/resource-manager/synapse/2021-06-01/integrationruntime/method_upgrade.go @@ -0,0 +1,47 @@ +package integrationruntime + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type UpgradeOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// Upgrade ... +func (c IntegrationRuntimeClient) Upgrade(ctx context.Context, id IntegrationRuntimeId) (result UpgradeOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/upgrade", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/synapse/2021-06-01/integrationruntime/model_customsetupbase.go b/resource-manager/synapse/2021-06-01/integrationruntime/model_customsetupbase.go new file mode 100644 index 00000000000..cec879ceed9 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/integrationruntime/model_customsetupbase.go @@ -0,0 +1,44 @@ +package integrationruntime + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CustomSetupBase interface { +} + +// RawCustomSetupBaseImpl is returned when the Discriminated Value +// doesn't match any of the defined types +// NOTE: this should only be used when a type isn't defined for this type of Object (as a workaround) +// and is used only for Deserialization (e.g. this cannot be used as a Request Payload). +type RawCustomSetupBaseImpl struct { + Type string + Values map[string]interface{} +} + +func unmarshalCustomSetupBaseImplementation(input []byte) (CustomSetupBase, error) { + if input == nil { + return nil, nil + } + + var temp map[string]interface{} + if err := json.Unmarshal(input, &temp); err != nil { + return nil, fmt.Errorf("unmarshaling CustomSetupBase into map[string]interface: %+v", err) + } + + value, ok := temp["type"].(string) + if !ok { + return nil, nil + } + + out := RawCustomSetupBaseImpl{ + Type: value, + Values: temp, + } + return out, nil + +} diff --git a/resource-manager/synapse/2021-06-01/integrationruntime/model_entityreference.go b/resource-manager/synapse/2021-06-01/integrationruntime/model_entityreference.go new file mode 100644 index 00000000000..085aa9577aa --- /dev/null +++ b/resource-manager/synapse/2021-06-01/integrationruntime/model_entityreference.go @@ -0,0 +1,9 @@ +package integrationruntime + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type EntityReference struct { + ReferenceName *string `json:"referenceName,omitempty"` + Type *IntegrationRuntimeEntityReferenceType `json:"type,omitempty"` +} diff --git a/resource-manager/synapse/2021-06-01/integrationruntime/model_getssisobjectmetadatarequest.go b/resource-manager/synapse/2021-06-01/integrationruntime/model_getssisobjectmetadatarequest.go new file mode 100644 index 00000000000..82acf4939f9 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/integrationruntime/model_getssisobjectmetadatarequest.go @@ -0,0 +1,8 @@ +package integrationruntime + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetSsisObjectMetadataRequest struct { + MetadataPath *string `json:"metadataPath,omitempty"` +} diff --git a/resource-manager/synapse/2021-06-01/integrationruntime/model_integrationruntime.go b/resource-manager/synapse/2021-06-01/integrationruntime/model_integrationruntime.go new file mode 100644 index 00000000000..b04368281f7 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/integrationruntime/model_integrationruntime.go @@ -0,0 +1,61 @@ +package integrationruntime + +import ( + "encoding/json" + "fmt" + "strings" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IntegrationRuntime interface { +} + +// RawIntegrationRuntimeImpl is returned when the Discriminated Value +// doesn't match any of the defined types +// NOTE: this should only be used when a type isn't defined for this type of Object (as a workaround) +// and is used only for Deserialization (e.g. this cannot be used as a Request Payload). +type RawIntegrationRuntimeImpl struct { + Type string + Values map[string]interface{} +} + +func unmarshalIntegrationRuntimeImplementation(input []byte) (IntegrationRuntime, error) { + if input == nil { + return nil, nil + } + + var temp map[string]interface{} + if err := json.Unmarshal(input, &temp); err != nil { + return nil, fmt.Errorf("unmarshaling IntegrationRuntime into map[string]interface: %+v", err) + } + + value, ok := temp["type"].(string) + if !ok { + return nil, nil + } + + if strings.EqualFold(value, "Managed") { + var out ManagedIntegrationRuntime + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into ManagedIntegrationRuntime: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "SelfHosted") { + var out SelfHostedIntegrationRuntime + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into SelfHostedIntegrationRuntime: %+v", err) + } + return out, nil + } + + out := RawIntegrationRuntimeImpl{ + Type: value, + Values: temp, + } + return out, nil + +} diff --git a/resource-manager/synapse/2021-06-01/integrationruntime/model_integrationruntimeauthkeys.go b/resource-manager/synapse/2021-06-01/integrationruntime/model_integrationruntimeauthkeys.go new file mode 100644 index 00000000000..23d8dd544f9 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/integrationruntime/model_integrationruntimeauthkeys.go @@ -0,0 +1,9 @@ +package integrationruntime + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IntegrationRuntimeAuthKeys struct { + AuthKey1 *string `json:"authKey1,omitempty"` + AuthKey2 *string `json:"authKey2,omitempty"` +} diff --git a/resource-manager/synapse/2021-06-01/integrationruntime/model_integrationruntimecomputeproperties.go b/resource-manager/synapse/2021-06-01/integrationruntime/model_integrationruntimecomputeproperties.go new file mode 100644 index 00000000000..9f1878d3e3a --- /dev/null +++ b/resource-manager/synapse/2021-06-01/integrationruntime/model_integrationruntimecomputeproperties.go @@ -0,0 +1,13 @@ +package integrationruntime + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IntegrationRuntimeComputeProperties struct { + DataFlowProperties *IntegrationRuntimeDataFlowProperties `json:"dataFlowProperties,omitempty"` + Location *string `json:"location,omitempty"` + MaxParallelExecutionsPerNode *int64 `json:"maxParallelExecutionsPerNode,omitempty"` + NodeSize *string `json:"nodeSize,omitempty"` + NumberOfNodes *int64 `json:"numberOfNodes,omitempty"` + VNetProperties *IntegrationRuntimeVNetProperties `json:"vNetProperties,omitempty"` +} diff --git a/resource-manager/synapse/2021-06-01/integrationruntime/model_integrationruntimeconnectioninfo.go b/resource-manager/synapse/2021-06-01/integrationruntime/model_integrationruntimeconnectioninfo.go new file mode 100644 index 00000000000..79778c9b9db --- /dev/null +++ b/resource-manager/synapse/2021-06-01/integrationruntime/model_integrationruntimeconnectioninfo.go @@ -0,0 +1,13 @@ +package integrationruntime + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IntegrationRuntimeConnectionInfo struct { + HostServiceUri *string `json:"hostServiceUri,omitempty"` + IdentityCertThumbprint *string `json:"identityCertThumbprint,omitempty"` + IsIdentityCertExprired *bool `json:"isIdentityCertExprired,omitempty"` + PublicKey *string `json:"publicKey,omitempty"` + ServiceToken *string `json:"serviceToken,omitempty"` + Version *string `json:"version,omitempty"` +} diff --git a/resource-manager/synapse/2021-06-01/integrationruntime/model_integrationruntimecustomervirtualnetwork.go b/resource-manager/synapse/2021-06-01/integrationruntime/model_integrationruntimecustomervirtualnetwork.go new file mode 100644 index 00000000000..49853c9ba82 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/integrationruntime/model_integrationruntimecustomervirtualnetwork.go @@ -0,0 +1,8 @@ +package integrationruntime + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IntegrationRuntimeCustomerVirtualNetwork struct { + SubnetId *string `json:"subnetId,omitempty"` +} diff --git a/resource-manager/synapse/2021-06-01/integrationruntime/model_integrationruntimecustomsetupscriptproperties.go b/resource-manager/synapse/2021-06-01/integrationruntime/model_integrationruntimecustomsetupscriptproperties.go new file mode 100644 index 00000000000..18f56a0608a --- /dev/null +++ b/resource-manager/synapse/2021-06-01/integrationruntime/model_integrationruntimecustomsetupscriptproperties.go @@ -0,0 +1,9 @@ +package integrationruntime + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IntegrationRuntimeCustomSetupScriptProperties struct { + BlobContainerUri *string `json:"blobContainerUri,omitempty"` + SasToken *SecureString `json:"sasToken,omitempty"` +} diff --git a/resource-manager/synapse/2021-06-01/integrationruntime/model_integrationruntimedataflowproperties.go b/resource-manager/synapse/2021-06-01/integrationruntime/model_integrationruntimedataflowproperties.go new file mode 100644 index 00000000000..4c2903344a5 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/integrationruntime/model_integrationruntimedataflowproperties.go @@ -0,0 +1,10 @@ +package integrationruntime + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IntegrationRuntimeDataFlowProperties struct { + ComputeType *DataFlowComputeType `json:"computeType,omitempty"` + CoreCount *int64 `json:"coreCount,omitempty"` + TimeToLive *int64 `json:"timeToLive,omitempty"` +} diff --git a/resource-manager/synapse/2021-06-01/integrationruntime/model_integrationruntimedataproxyproperties.go b/resource-manager/synapse/2021-06-01/integrationruntime/model_integrationruntimedataproxyproperties.go new file mode 100644 index 00000000000..343c74cbc34 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/integrationruntime/model_integrationruntimedataproxyproperties.go @@ -0,0 +1,10 @@ +package integrationruntime + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IntegrationRuntimeDataProxyProperties struct { + ConnectVia *EntityReference `json:"connectVia,omitempty"` + Path *string `json:"path,omitempty"` + StagingLinkedService *EntityReference `json:"stagingLinkedService,omitempty"` +} diff --git a/resource-manager/synapse/2021-06-01/integrationruntime/model_integrationruntimemonitoringdata.go b/resource-manager/synapse/2021-06-01/integrationruntime/model_integrationruntimemonitoringdata.go new file mode 100644 index 00000000000..4688c95c232 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/integrationruntime/model_integrationruntimemonitoringdata.go @@ -0,0 +1,9 @@ +package integrationruntime + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IntegrationRuntimeMonitoringData struct { + Name *string `json:"name,omitempty"` + Nodes *[]IntegrationRuntimeNodeMonitoringData `json:"nodes,omitempty"` +} diff --git a/resource-manager/synapse/2021-06-01/integrationruntime/model_integrationruntimenodeipaddress.go b/resource-manager/synapse/2021-06-01/integrationruntime/model_integrationruntimenodeipaddress.go new file mode 100644 index 00000000000..2516cfa05fa --- /dev/null +++ b/resource-manager/synapse/2021-06-01/integrationruntime/model_integrationruntimenodeipaddress.go @@ -0,0 +1,8 @@ +package integrationruntime + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IntegrationRuntimeNodeIPAddress struct { + IPAddress *string `json:"ipAddress,omitempty"` +} diff --git a/resource-manager/synapse/2021-06-01/integrationruntime/model_integrationruntimenodemonitoringdata.go b/resource-manager/synapse/2021-06-01/integrationruntime/model_integrationruntimenodemonitoringdata.go new file mode 100644 index 00000000000..43caac09125 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/integrationruntime/model_integrationruntimenodemonitoringdata.go @@ -0,0 +1,15 @@ +package integrationruntime + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IntegrationRuntimeNodeMonitoringData struct { + AvailableMemoryInMB *int64 `json:"availableMemoryInMB,omitempty"` + ConcurrentJobsLimit *int64 `json:"concurrentJobsLimit,omitempty"` + ConcurrentJobsRunning *int64 `json:"concurrentJobsRunning,omitempty"` + CpuUtilization *int64 `json:"cpuUtilization,omitempty"` + MaxConcurrentJobs *int64 `json:"maxConcurrentJobs,omitempty"` + NodeName *string `json:"nodeName,omitempty"` + ReceivedBytes *float64 `json:"receivedBytes,omitempty"` + SentBytes *float64 `json:"sentBytes,omitempty"` +} diff --git a/resource-manager/synapse/2021-06-01/integrationruntime/model_integrationruntimeregeneratekeyparameters.go b/resource-manager/synapse/2021-06-01/integrationruntime/model_integrationruntimeregeneratekeyparameters.go new file mode 100644 index 00000000000..e6e01738d3f --- /dev/null +++ b/resource-manager/synapse/2021-06-01/integrationruntime/model_integrationruntimeregeneratekeyparameters.go @@ -0,0 +1,8 @@ +package integrationruntime + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IntegrationRuntimeRegenerateKeyParameters struct { + KeyName *IntegrationRuntimeAuthKeyName `json:"keyName,omitempty"` +} diff --git a/resource-manager/synapse/2021-06-01/integrationruntime/model_integrationruntimeresource.go b/resource-manager/synapse/2021-06-01/integrationruntime/model_integrationruntimeresource.go new file mode 100644 index 00000000000..b7486579d2a --- /dev/null +++ b/resource-manager/synapse/2021-06-01/integrationruntime/model_integrationruntimeresource.go @@ -0,0 +1,46 @@ +package integrationruntime + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IntegrationRuntimeResource struct { + Etag *string `json:"etag,omitempty"` + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties IntegrationRuntime `json:"properties"` + Type *string `json:"type,omitempty"` +} + +var _ json.Unmarshaler = &IntegrationRuntimeResource{} + +func (s *IntegrationRuntimeResource) UnmarshalJSON(bytes []byte) error { + type alias IntegrationRuntimeResource + var decoded alias + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling into IntegrationRuntimeResource: %+v", err) + } + + s.Etag = decoded.Etag + s.Id = decoded.Id + s.Name = decoded.Name + s.Type = decoded.Type + + var temp map[string]json.RawMessage + if err := json.Unmarshal(bytes, &temp); err != nil { + return fmt.Errorf("unmarshaling IntegrationRuntimeResource into map[string]json.RawMessage: %+v", err) + } + + if v, ok := temp["properties"]; ok { + impl, err := unmarshalIntegrationRuntimeImplementation(v) + if err != nil { + return fmt.Errorf("unmarshaling field 'Properties' for 'IntegrationRuntimeResource': %+v", err) + } + s.Properties = impl + } + return nil +} diff --git a/resource-manager/synapse/2021-06-01/integrationruntime/model_integrationruntimessiscataloginfo.go b/resource-manager/synapse/2021-06-01/integrationruntime/model_integrationruntimessiscataloginfo.go new file mode 100644 index 00000000000..4323eb7773b --- /dev/null +++ b/resource-manager/synapse/2021-06-01/integrationruntime/model_integrationruntimessiscataloginfo.go @@ -0,0 +1,11 @@ +package integrationruntime + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IntegrationRuntimeSsisCatalogInfo struct { + CatalogAdminPassword *SecureString `json:"catalogAdminPassword,omitempty"` + CatalogAdminUserName *string `json:"catalogAdminUserName,omitempty"` + CatalogPricingTier *IntegrationRuntimeSsisCatalogPricingTier `json:"catalogPricingTier,omitempty"` + CatalogServerEndpoint *string `json:"catalogServerEndpoint,omitempty"` +} diff --git a/resource-manager/synapse/2021-06-01/integrationruntime/model_integrationruntimessisproperties.go b/resource-manager/synapse/2021-06-01/integrationruntime/model_integrationruntimessisproperties.go new file mode 100644 index 00000000000..d5a5bd33cca --- /dev/null +++ b/resource-manager/synapse/2021-06-01/integrationruntime/model_integrationruntimessisproperties.go @@ -0,0 +1,57 @@ +package integrationruntime + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IntegrationRuntimeSsisProperties struct { + CatalogInfo *IntegrationRuntimeSsisCatalogInfo `json:"catalogInfo,omitempty"` + CustomSetupScriptProperties *IntegrationRuntimeCustomSetupScriptProperties `json:"customSetupScriptProperties,omitempty"` + DataProxyProperties *IntegrationRuntimeDataProxyProperties `json:"dataProxyProperties,omitempty"` + Edition *IntegrationRuntimeEdition `json:"edition,omitempty"` + ExpressCustomSetupProperties *[]CustomSetupBase `json:"expressCustomSetupProperties,omitempty"` + LicenseType *IntegrationRuntimeLicenseType `json:"licenseType,omitempty"` +} + +var _ json.Unmarshaler = &IntegrationRuntimeSsisProperties{} + +func (s *IntegrationRuntimeSsisProperties) UnmarshalJSON(bytes []byte) error { + type alias IntegrationRuntimeSsisProperties + var decoded alias + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling into IntegrationRuntimeSsisProperties: %+v", err) + } + + s.CatalogInfo = decoded.CatalogInfo + s.CustomSetupScriptProperties = decoded.CustomSetupScriptProperties + s.DataProxyProperties = decoded.DataProxyProperties + s.Edition = decoded.Edition + s.LicenseType = decoded.LicenseType + + var temp map[string]json.RawMessage + if err := json.Unmarshal(bytes, &temp); err != nil { + return fmt.Errorf("unmarshaling IntegrationRuntimeSsisProperties into map[string]json.RawMessage: %+v", err) + } + + if v, ok := temp["expressCustomSetupProperties"]; ok { + var listTemp []json.RawMessage + if err := json.Unmarshal(v, &listTemp); err != nil { + return fmt.Errorf("unmarshaling ExpressCustomSetupProperties into list []json.RawMessage: %+v", err) + } + + output := make([]CustomSetupBase, 0) + for i, val := range listTemp { + impl, err := unmarshalCustomSetupBaseImplementation(val) + if err != nil { + return fmt.Errorf("unmarshaling index %d field 'ExpressCustomSetupProperties' for 'IntegrationRuntimeSsisProperties': %+v", i, err) + } + output = append(output, impl) + } + s.ExpressCustomSetupProperties = &output + } + return nil +} diff --git a/resource-manager/synapse/2021-06-01/integrationruntime/model_integrationruntimestatus.go b/resource-manager/synapse/2021-06-01/integrationruntime/model_integrationruntimestatus.go new file mode 100644 index 00000000000..83ee92c148f --- /dev/null +++ b/resource-manager/synapse/2021-06-01/integrationruntime/model_integrationruntimestatus.go @@ -0,0 +1,61 @@ +package integrationruntime + +import ( + "encoding/json" + "fmt" + "strings" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IntegrationRuntimeStatus interface { +} + +// RawIntegrationRuntimeStatusImpl is returned when the Discriminated Value +// doesn't match any of the defined types +// NOTE: this should only be used when a type isn't defined for this type of Object (as a workaround) +// and is used only for Deserialization (e.g. this cannot be used as a Request Payload). +type RawIntegrationRuntimeStatusImpl struct { + Type string + Values map[string]interface{} +} + +func unmarshalIntegrationRuntimeStatusImplementation(input []byte) (IntegrationRuntimeStatus, error) { + if input == nil { + return nil, nil + } + + var temp map[string]interface{} + if err := json.Unmarshal(input, &temp); err != nil { + return nil, fmt.Errorf("unmarshaling IntegrationRuntimeStatus into map[string]interface: %+v", err) + } + + value, ok := temp["type"].(string) + if !ok { + return nil, nil + } + + if strings.EqualFold(value, "Managed") { + var out ManagedIntegrationRuntimeStatus + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into ManagedIntegrationRuntimeStatus: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "SelfHosted") { + var out SelfHostedIntegrationRuntimeStatus + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into SelfHostedIntegrationRuntimeStatus: %+v", err) + } + return out, nil + } + + out := RawIntegrationRuntimeStatusImpl{ + Type: value, + Values: temp, + } + return out, nil + +} diff --git a/resource-manager/synapse/2021-06-01/integrationruntime/model_integrationruntimestatusresponse.go b/resource-manager/synapse/2021-06-01/integrationruntime/model_integrationruntimestatusresponse.go new file mode 100644 index 00000000000..6c744524a66 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/integrationruntime/model_integrationruntimestatusresponse.go @@ -0,0 +1,40 @@ +package integrationruntime + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IntegrationRuntimeStatusResponse struct { + Name *string `json:"name,omitempty"` + Properties IntegrationRuntimeStatus `json:"properties"` +} + +var _ json.Unmarshaler = &IntegrationRuntimeStatusResponse{} + +func (s *IntegrationRuntimeStatusResponse) UnmarshalJSON(bytes []byte) error { + type alias IntegrationRuntimeStatusResponse + var decoded alias + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling into IntegrationRuntimeStatusResponse: %+v", err) + } + + s.Name = decoded.Name + + var temp map[string]json.RawMessage + if err := json.Unmarshal(bytes, &temp); err != nil { + return fmt.Errorf("unmarshaling IntegrationRuntimeStatusResponse into map[string]json.RawMessage: %+v", err) + } + + if v, ok := temp["properties"]; ok { + impl, err := unmarshalIntegrationRuntimeStatusImplementation(v) + if err != nil { + return fmt.Errorf("unmarshaling field 'Properties' for 'IntegrationRuntimeStatusResponse': %+v", err) + } + s.Properties = impl + } + return nil +} diff --git a/resource-manager/synapse/2021-06-01/integrationruntime/model_integrationruntimevnetproperties.go b/resource-manager/synapse/2021-06-01/integrationruntime/model_integrationruntimevnetproperties.go new file mode 100644 index 00000000000..b9874e29e03 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/integrationruntime/model_integrationruntimevnetproperties.go @@ -0,0 +1,11 @@ +package integrationruntime + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IntegrationRuntimeVNetProperties struct { + PublicIPs *[]string `json:"publicIPs,omitempty"` + Subnet *string `json:"subnet,omitempty"` + SubnetId *string `json:"subnetId,omitempty"` + VNetId *string `json:"vNetId,omitempty"` +} diff --git a/resource-manager/synapse/2021-06-01/integrationruntime/model_linkedintegrationruntime.go b/resource-manager/synapse/2021-06-01/integrationruntime/model_linkedintegrationruntime.go new file mode 100644 index 00000000000..f47a8db2a12 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/integrationruntime/model_linkedintegrationruntime.go @@ -0,0 +1,30 @@ +package integrationruntime + +import ( + "time" + + "github.com/hashicorp/go-azure-helpers/lang/dates" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type LinkedIntegrationRuntime struct { + CreateTime *string `json:"createTime,omitempty"` + DataFactoryLocation *string `json:"dataFactoryLocation,omitempty"` + DataFactoryName *string `json:"dataFactoryName,omitempty"` + Name *string `json:"name,omitempty"` + SubscriptionId *string `json:"subscriptionId,omitempty"` +} + +func (o *LinkedIntegrationRuntime) GetCreateTimeAsTime() (*time.Time, error) { + if o.CreateTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.CreateTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *LinkedIntegrationRuntime) SetCreateTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.CreateTime = &formatted +} diff --git a/resource-manager/synapse/2021-06-01/integrationruntime/model_linkedintegrationruntimekeyauthorization.go b/resource-manager/synapse/2021-06-01/integrationruntime/model_linkedintegrationruntimekeyauthorization.go new file mode 100644 index 00000000000..a2162dd5384 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/integrationruntime/model_linkedintegrationruntimekeyauthorization.go @@ -0,0 +1,41 @@ +package integrationruntime + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ LinkedIntegrationRuntimeType = LinkedIntegrationRuntimeKeyAuthorization{} + +type LinkedIntegrationRuntimeKeyAuthorization struct { + Key SecureString `json:"key"` + + // Fields inherited from LinkedIntegrationRuntimeType +} + +var _ json.Marshaler = LinkedIntegrationRuntimeKeyAuthorization{} + +func (s LinkedIntegrationRuntimeKeyAuthorization) MarshalJSON() ([]byte, error) { + type wrapper LinkedIntegrationRuntimeKeyAuthorization + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling LinkedIntegrationRuntimeKeyAuthorization: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling LinkedIntegrationRuntimeKeyAuthorization: %+v", err) + } + decoded["authorizationType"] = "Key" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling LinkedIntegrationRuntimeKeyAuthorization: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/synapse/2021-06-01/integrationruntime/model_linkedintegrationruntimerbacauthorization.go b/resource-manager/synapse/2021-06-01/integrationruntime/model_linkedintegrationruntimerbacauthorization.go new file mode 100644 index 00000000000..24f4556c25c --- /dev/null +++ b/resource-manager/synapse/2021-06-01/integrationruntime/model_linkedintegrationruntimerbacauthorization.go @@ -0,0 +1,41 @@ +package integrationruntime + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ LinkedIntegrationRuntimeType = LinkedIntegrationRuntimeRbacAuthorization{} + +type LinkedIntegrationRuntimeRbacAuthorization struct { + ResourceId string `json:"resourceId"` + + // Fields inherited from LinkedIntegrationRuntimeType +} + +var _ json.Marshaler = LinkedIntegrationRuntimeRbacAuthorization{} + +func (s LinkedIntegrationRuntimeRbacAuthorization) MarshalJSON() ([]byte, error) { + type wrapper LinkedIntegrationRuntimeRbacAuthorization + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling LinkedIntegrationRuntimeRbacAuthorization: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling LinkedIntegrationRuntimeRbacAuthorization: %+v", err) + } + decoded["authorizationType"] = "RBAC" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling LinkedIntegrationRuntimeRbacAuthorization: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/synapse/2021-06-01/integrationruntime/model_linkedintegrationruntimetype.go b/resource-manager/synapse/2021-06-01/integrationruntime/model_linkedintegrationruntimetype.go new file mode 100644 index 00000000000..14c717a16f9 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/integrationruntime/model_linkedintegrationruntimetype.go @@ -0,0 +1,61 @@ +package integrationruntime + +import ( + "encoding/json" + "fmt" + "strings" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type LinkedIntegrationRuntimeType interface { +} + +// RawLinkedIntegrationRuntimeTypeImpl is returned when the Discriminated Value +// doesn't match any of the defined types +// NOTE: this should only be used when a type isn't defined for this type of Object (as a workaround) +// and is used only for Deserialization (e.g. this cannot be used as a Request Payload). +type RawLinkedIntegrationRuntimeTypeImpl struct { + Type string + Values map[string]interface{} +} + +func unmarshalLinkedIntegrationRuntimeTypeImplementation(input []byte) (LinkedIntegrationRuntimeType, error) { + if input == nil { + return nil, nil + } + + var temp map[string]interface{} + if err := json.Unmarshal(input, &temp); err != nil { + return nil, fmt.Errorf("unmarshaling LinkedIntegrationRuntimeType into map[string]interface: %+v", err) + } + + value, ok := temp["authorizationType"].(string) + if !ok { + return nil, nil + } + + if strings.EqualFold(value, "Key") { + var out LinkedIntegrationRuntimeKeyAuthorization + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into LinkedIntegrationRuntimeKeyAuthorization: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "RBAC") { + var out LinkedIntegrationRuntimeRbacAuthorization + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into LinkedIntegrationRuntimeRbacAuthorization: %+v", err) + } + return out, nil + } + + out := RawLinkedIntegrationRuntimeTypeImpl{ + Type: value, + Values: temp, + } + return out, nil + +} diff --git a/resource-manager/synapse/2021-06-01/integrationruntime/model_managedintegrationruntime.go b/resource-manager/synapse/2021-06-01/integrationruntime/model_managedintegrationruntime.go new file mode 100644 index 00000000000..33fe359800b --- /dev/null +++ b/resource-manager/synapse/2021-06-01/integrationruntime/model_managedintegrationruntime.go @@ -0,0 +1,44 @@ +package integrationruntime + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ IntegrationRuntime = ManagedIntegrationRuntime{} + +type ManagedIntegrationRuntime struct { + ManagedVirtualNetwork *ManagedIntegrationRuntimeManagedVirtualNetworkReference `json:"managedVirtualNetwork,omitempty"` + ProvisioningState *IntegrationRuntimeState `json:"provisioningState,omitempty"` + TypeProperties ManagedIntegrationRuntimeTypeProperties `json:"typeProperties"` + + // Fields inherited from IntegrationRuntime + Description *string `json:"description,omitempty"` +} + +var _ json.Marshaler = ManagedIntegrationRuntime{} + +func (s ManagedIntegrationRuntime) MarshalJSON() ([]byte, error) { + type wrapper ManagedIntegrationRuntime + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling ManagedIntegrationRuntime: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling ManagedIntegrationRuntime: %+v", err) + } + decoded["type"] = "Managed" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling ManagedIntegrationRuntime: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/synapse/2021-06-01/integrationruntime/model_managedintegrationruntimeerror.go b/resource-manager/synapse/2021-06-01/integrationruntime/model_managedintegrationruntimeerror.go new file mode 100644 index 00000000000..a0dbd9dedec --- /dev/null +++ b/resource-manager/synapse/2021-06-01/integrationruntime/model_managedintegrationruntimeerror.go @@ -0,0 +1,29 @@ +package integrationruntime + +import ( + "time" + + "github.com/hashicorp/go-azure-helpers/lang/dates" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ManagedIntegrationRuntimeError struct { + Code *string `json:"code,omitempty"` + Message *string `json:"message,omitempty"` + Parameters *[]string `json:"parameters,omitempty"` + Time *string `json:"time,omitempty"` +} + +func (o *ManagedIntegrationRuntimeError) GetTimeAsTime() (*time.Time, error) { + if o.Time == nil { + return nil, nil + } + return dates.ParseAsFormat(o.Time, "2006-01-02T15:04:05Z07:00") +} + +func (o *ManagedIntegrationRuntimeError) SetTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.Time = &formatted +} diff --git a/resource-manager/synapse/2021-06-01/integrationruntime/model_managedintegrationruntimemanagedvirtualnetworkreference.go b/resource-manager/synapse/2021-06-01/integrationruntime/model_managedintegrationruntimemanagedvirtualnetworkreference.go new file mode 100644 index 00000000000..d040e01db6d --- /dev/null +++ b/resource-manager/synapse/2021-06-01/integrationruntime/model_managedintegrationruntimemanagedvirtualnetworkreference.go @@ -0,0 +1,10 @@ +package integrationruntime + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ManagedIntegrationRuntimeManagedVirtualNetworkReference struct { + Id *string `json:"id,omitempty"` + ReferenceName *string `json:"referenceName,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/synapse/2021-06-01/integrationruntime/model_managedintegrationruntimenode.go b/resource-manager/synapse/2021-06-01/integrationruntime/model_managedintegrationruntimenode.go new file mode 100644 index 00000000000..001d3dcc699 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/integrationruntime/model_managedintegrationruntimenode.go @@ -0,0 +1,10 @@ +package integrationruntime + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ManagedIntegrationRuntimeNode struct { + Errors *[]ManagedIntegrationRuntimeError `json:"errors,omitempty"` + NodeId *string `json:"nodeId,omitempty"` + Status *ManagedIntegrationRuntimeNodeStatus `json:"status,omitempty"` +} diff --git a/resource-manager/synapse/2021-06-01/integrationruntime/model_managedintegrationruntimeoperationresult.go b/resource-manager/synapse/2021-06-01/integrationruntime/model_managedintegrationruntimeoperationresult.go new file mode 100644 index 00000000000..7d5d94976dc --- /dev/null +++ b/resource-manager/synapse/2021-06-01/integrationruntime/model_managedintegrationruntimeoperationresult.go @@ -0,0 +1,31 @@ +package integrationruntime + +import ( + "time" + + "github.com/hashicorp/go-azure-helpers/lang/dates" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ManagedIntegrationRuntimeOperationResult struct { + ActivityId *string `json:"activityId,omitempty"` + ErrorCode *string `json:"errorCode,omitempty"` + Parameters *[]string `json:"parameters,omitempty"` + Result *string `json:"result,omitempty"` + StartTime *string `json:"startTime,omitempty"` + Type *string `json:"type,omitempty"` +} + +func (o *ManagedIntegrationRuntimeOperationResult) GetStartTimeAsTime() (*time.Time, error) { + if o.StartTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.StartTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *ManagedIntegrationRuntimeOperationResult) SetStartTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.StartTime = &formatted +} diff --git a/resource-manager/synapse/2021-06-01/integrationruntime/model_managedintegrationruntimestatus.go b/resource-manager/synapse/2021-06-01/integrationruntime/model_managedintegrationruntimestatus.go new file mode 100644 index 00000000000..aa8211e062b --- /dev/null +++ b/resource-manager/synapse/2021-06-01/integrationruntime/model_managedintegrationruntimestatus.go @@ -0,0 +1,43 @@ +package integrationruntime + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ IntegrationRuntimeStatus = ManagedIntegrationRuntimeStatus{} + +type ManagedIntegrationRuntimeStatus struct { + TypeProperties ManagedIntegrationRuntimeStatusTypeProperties `json:"typeProperties"` + + // Fields inherited from IntegrationRuntimeStatus + DataFactoryName *string `json:"dataFactoryName,omitempty"` + State *IntegrationRuntimeState `json:"state,omitempty"` +} + +var _ json.Marshaler = ManagedIntegrationRuntimeStatus{} + +func (s ManagedIntegrationRuntimeStatus) MarshalJSON() ([]byte, error) { + type wrapper ManagedIntegrationRuntimeStatus + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling ManagedIntegrationRuntimeStatus: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling ManagedIntegrationRuntimeStatus: %+v", err) + } + decoded["type"] = "Managed" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling ManagedIntegrationRuntimeStatus: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/synapse/2021-06-01/integrationruntime/model_managedintegrationruntimestatustypeproperties.go b/resource-manager/synapse/2021-06-01/integrationruntime/model_managedintegrationruntimestatustypeproperties.go new file mode 100644 index 00000000000..63e371cbe72 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/integrationruntime/model_managedintegrationruntimestatustypeproperties.go @@ -0,0 +1,29 @@ +package integrationruntime + +import ( + "time" + + "github.com/hashicorp/go-azure-helpers/lang/dates" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ManagedIntegrationRuntimeStatusTypeProperties struct { + CreateTime *string `json:"createTime,omitempty"` + LastOperation *ManagedIntegrationRuntimeOperationResult `json:"lastOperation,omitempty"` + Nodes *[]ManagedIntegrationRuntimeNode `json:"nodes,omitempty"` + OtherErrors *[]ManagedIntegrationRuntimeError `json:"otherErrors,omitempty"` +} + +func (o *ManagedIntegrationRuntimeStatusTypeProperties) GetCreateTimeAsTime() (*time.Time, error) { + if o.CreateTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.CreateTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *ManagedIntegrationRuntimeStatusTypeProperties) SetCreateTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.CreateTime = &formatted +} diff --git a/resource-manager/synapse/2021-06-01/integrationruntime/model_managedintegrationruntimetypeproperties.go b/resource-manager/synapse/2021-06-01/integrationruntime/model_managedintegrationruntimetypeproperties.go new file mode 100644 index 00000000000..aeb98a9b339 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/integrationruntime/model_managedintegrationruntimetypeproperties.go @@ -0,0 +1,10 @@ +package integrationruntime + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ManagedIntegrationRuntimeTypeProperties struct { + ComputeProperties *IntegrationRuntimeComputeProperties `json:"computeProperties,omitempty"` + CustomerVirtualNetwork *IntegrationRuntimeCustomerVirtualNetwork `json:"customerVirtualNetwork,omitempty"` + SsisProperties *IntegrationRuntimeSsisProperties `json:"ssisProperties,omitempty"` +} diff --git a/resource-manager/synapse/2021-06-01/integrationruntime/model_secretbase.go b/resource-manager/synapse/2021-06-01/integrationruntime/model_secretbase.go new file mode 100644 index 00000000000..b8624a50397 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/integrationruntime/model_secretbase.go @@ -0,0 +1,53 @@ +package integrationruntime + +import ( + "encoding/json" + "fmt" + "strings" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SecretBase interface { +} + +// RawSecretBaseImpl is returned when the Discriminated Value +// doesn't match any of the defined types +// NOTE: this should only be used when a type isn't defined for this type of Object (as a workaround) +// and is used only for Deserialization (e.g. this cannot be used as a Request Payload). +type RawSecretBaseImpl struct { + Type string + Values map[string]interface{} +} + +func unmarshalSecretBaseImplementation(input []byte) (SecretBase, error) { + if input == nil { + return nil, nil + } + + var temp map[string]interface{} + if err := json.Unmarshal(input, &temp); err != nil { + return nil, fmt.Errorf("unmarshaling SecretBase into map[string]interface: %+v", err) + } + + value, ok := temp["type"].(string) + if !ok { + return nil, nil + } + + if strings.EqualFold(value, "SecureString") { + var out SecureString + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into SecureString: %+v", err) + } + return out, nil + } + + out := RawSecretBaseImpl{ + Type: value, + Values: temp, + } + return out, nil + +} diff --git a/resource-manager/synapse/2021-06-01/integrationruntime/model_securestring.go b/resource-manager/synapse/2021-06-01/integrationruntime/model_securestring.go new file mode 100644 index 00000000000..7104f18183a --- /dev/null +++ b/resource-manager/synapse/2021-06-01/integrationruntime/model_securestring.go @@ -0,0 +1,41 @@ +package integrationruntime + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ SecretBase = SecureString{} + +type SecureString struct { + Value string `json:"value"` + + // Fields inherited from SecretBase +} + +var _ json.Marshaler = SecureString{} + +func (s SecureString) MarshalJSON() ([]byte, error) { + type wrapper SecureString + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling SecureString: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling SecureString: %+v", err) + } + decoded["type"] = "SecureString" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling SecureString: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/synapse/2021-06-01/integrationruntime/model_selfhostedintegrationruntime.go b/resource-manager/synapse/2021-06-01/integrationruntime/model_selfhostedintegrationruntime.go new file mode 100644 index 00000000000..ba60d843a88 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/integrationruntime/model_selfhostedintegrationruntime.go @@ -0,0 +1,42 @@ +package integrationruntime + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ IntegrationRuntime = SelfHostedIntegrationRuntime{} + +type SelfHostedIntegrationRuntime struct { + TypeProperties *SelfHostedIntegrationRuntimeTypeProperties `json:"typeProperties,omitempty"` + + // Fields inherited from IntegrationRuntime + Description *string `json:"description,omitempty"` +} + +var _ json.Marshaler = SelfHostedIntegrationRuntime{} + +func (s SelfHostedIntegrationRuntime) MarshalJSON() ([]byte, error) { + type wrapper SelfHostedIntegrationRuntime + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling SelfHostedIntegrationRuntime: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling SelfHostedIntegrationRuntime: %+v", err) + } + decoded["type"] = "SelfHosted" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling SelfHostedIntegrationRuntime: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/synapse/2021-06-01/integrationruntime/model_selfhostedintegrationruntimenode.go b/resource-manager/synapse/2021-06-01/integrationruntime/model_selfhostedintegrationruntimenode.go new file mode 100644 index 00000000000..74d0be05746 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/integrationruntime/model_selfhostedintegrationruntimenode.go @@ -0,0 +1,115 @@ +package integrationruntime + +import ( + "time" + + "github.com/hashicorp/go-azure-helpers/lang/dates" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SelfHostedIntegrationRuntimeNode struct { + Capabilities *map[string]string `json:"capabilities,omitempty"` + ConcurrentJobsLimit *int64 `json:"concurrentJobsLimit,omitempty"` + ExpiryTime *string `json:"expiryTime,omitempty"` + HostServiceUri *string `json:"hostServiceUri,omitempty"` + IsActiveDispatcher *bool `json:"isActiveDispatcher,omitempty"` + LastConnectTime *string `json:"lastConnectTime,omitempty"` + LastEndUpdateTime *string `json:"lastEndUpdateTime,omitempty"` + LastStartTime *string `json:"lastStartTime,omitempty"` + LastStartUpdateTime *string `json:"lastStartUpdateTime,omitempty"` + LastStopTime *string `json:"lastStopTime,omitempty"` + LastUpdateResult *IntegrationRuntimeUpdateResult `json:"lastUpdateResult,omitempty"` + MachineName *string `json:"machineName,omitempty"` + MaxConcurrentJobs *int64 `json:"maxConcurrentJobs,omitempty"` + NodeName *string `json:"nodeName,omitempty"` + RegisterTime *string `json:"registerTime,omitempty"` + Status *SelfHostedIntegrationRuntimeNodeStatus `json:"status,omitempty"` + Version *string `json:"version,omitempty"` + VersionStatus *string `json:"versionStatus,omitempty"` +} + +func (o *SelfHostedIntegrationRuntimeNode) GetExpiryTimeAsTime() (*time.Time, error) { + if o.ExpiryTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.ExpiryTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *SelfHostedIntegrationRuntimeNode) SetExpiryTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.ExpiryTime = &formatted +} + +func (o *SelfHostedIntegrationRuntimeNode) GetLastConnectTimeAsTime() (*time.Time, error) { + if o.LastConnectTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.LastConnectTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *SelfHostedIntegrationRuntimeNode) SetLastConnectTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.LastConnectTime = &formatted +} + +func (o *SelfHostedIntegrationRuntimeNode) GetLastEndUpdateTimeAsTime() (*time.Time, error) { + if o.LastEndUpdateTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.LastEndUpdateTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *SelfHostedIntegrationRuntimeNode) SetLastEndUpdateTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.LastEndUpdateTime = &formatted +} + +func (o *SelfHostedIntegrationRuntimeNode) GetLastStartTimeAsTime() (*time.Time, error) { + if o.LastStartTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.LastStartTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *SelfHostedIntegrationRuntimeNode) SetLastStartTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.LastStartTime = &formatted +} + +func (o *SelfHostedIntegrationRuntimeNode) GetLastStartUpdateTimeAsTime() (*time.Time, error) { + if o.LastStartUpdateTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.LastStartUpdateTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *SelfHostedIntegrationRuntimeNode) SetLastStartUpdateTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.LastStartUpdateTime = &formatted +} + +func (o *SelfHostedIntegrationRuntimeNode) GetLastStopTimeAsTime() (*time.Time, error) { + if o.LastStopTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.LastStopTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *SelfHostedIntegrationRuntimeNode) SetLastStopTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.LastStopTime = &formatted +} + +func (o *SelfHostedIntegrationRuntimeNode) GetRegisterTimeAsTime() (*time.Time, error) { + if o.RegisterTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.RegisterTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *SelfHostedIntegrationRuntimeNode) SetRegisterTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.RegisterTime = &formatted +} diff --git a/resource-manager/synapse/2021-06-01/integrationruntime/model_selfhostedintegrationruntimestatus.go b/resource-manager/synapse/2021-06-01/integrationruntime/model_selfhostedintegrationruntimestatus.go new file mode 100644 index 00000000000..38991a65add --- /dev/null +++ b/resource-manager/synapse/2021-06-01/integrationruntime/model_selfhostedintegrationruntimestatus.go @@ -0,0 +1,43 @@ +package integrationruntime + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ IntegrationRuntimeStatus = SelfHostedIntegrationRuntimeStatus{} + +type SelfHostedIntegrationRuntimeStatus struct { + TypeProperties SelfHostedIntegrationRuntimeStatusTypeProperties `json:"typeProperties"` + + // Fields inherited from IntegrationRuntimeStatus + DataFactoryName *string `json:"dataFactoryName,omitempty"` + State *IntegrationRuntimeState `json:"state,omitempty"` +} + +var _ json.Marshaler = SelfHostedIntegrationRuntimeStatus{} + +func (s SelfHostedIntegrationRuntimeStatus) MarshalJSON() ([]byte, error) { + type wrapper SelfHostedIntegrationRuntimeStatus + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling SelfHostedIntegrationRuntimeStatus: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling SelfHostedIntegrationRuntimeStatus: %+v", err) + } + decoded["type"] = "SelfHosted" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling SelfHostedIntegrationRuntimeStatus: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/synapse/2021-06-01/integrationruntime/model_selfhostedintegrationruntimestatustypeproperties.go b/resource-manager/synapse/2021-06-01/integrationruntime/model_selfhostedintegrationruntimestatustypeproperties.go new file mode 100644 index 00000000000..70c1bb969f9 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/integrationruntime/model_selfhostedintegrationruntimestatustypeproperties.go @@ -0,0 +1,66 @@ +package integrationruntime + +import ( + "time" + + "github.com/hashicorp/go-azure-helpers/lang/dates" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SelfHostedIntegrationRuntimeStatusTypeProperties struct { + AutoUpdate *IntegrationRuntimeAutoUpdate `json:"autoUpdate,omitempty"` + AutoUpdateETA *string `json:"autoUpdateETA,omitempty"` + Capabilities *map[string]string `json:"capabilities,omitempty"` + CreateTime *string `json:"createTime,omitempty"` + InternalChannelEncryption *IntegrationRuntimeInternalChannelEncryptionMode `json:"internalChannelEncryption,omitempty"` + LatestVersion *string `json:"latestVersion,omitempty"` + Links *[]LinkedIntegrationRuntime `json:"links,omitempty"` + LocalTimeZoneOffset *string `json:"localTimeZoneOffset,omitempty"` + NodeCommunicationChannelEncryptionMode *string `json:"nodeCommunicationChannelEncryptionMode,omitempty"` + Nodes *[]SelfHostedIntegrationRuntimeNode `json:"nodes,omitempty"` + PushedVersion *string `json:"pushedVersion,omitempty"` + ScheduledUpdateDate *string `json:"scheduledUpdateDate,omitempty"` + ServiceUrls *[]string `json:"serviceUrls,omitempty"` + TaskQueueId *string `json:"taskQueueId,omitempty"` + UpdateDelayOffset *string `json:"updateDelayOffset,omitempty"` + Version *string `json:"version,omitempty"` + VersionStatus *string `json:"versionStatus,omitempty"` +} + +func (o *SelfHostedIntegrationRuntimeStatusTypeProperties) GetAutoUpdateETAAsTime() (*time.Time, error) { + if o.AutoUpdateETA == nil { + return nil, nil + } + return dates.ParseAsFormat(o.AutoUpdateETA, "2006-01-02T15:04:05Z07:00") +} + +func (o *SelfHostedIntegrationRuntimeStatusTypeProperties) SetAutoUpdateETAAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.AutoUpdateETA = &formatted +} + +func (o *SelfHostedIntegrationRuntimeStatusTypeProperties) GetCreateTimeAsTime() (*time.Time, error) { + if o.CreateTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.CreateTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *SelfHostedIntegrationRuntimeStatusTypeProperties) SetCreateTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.CreateTime = &formatted +} + +func (o *SelfHostedIntegrationRuntimeStatusTypeProperties) GetScheduledUpdateDateAsTime() (*time.Time, error) { + if o.ScheduledUpdateDate == nil { + return nil, nil + } + return dates.ParseAsFormat(o.ScheduledUpdateDate, "2006-01-02T15:04:05Z07:00") +} + +func (o *SelfHostedIntegrationRuntimeStatusTypeProperties) SetScheduledUpdateDateAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.ScheduledUpdateDate = &formatted +} diff --git a/resource-manager/synapse/2021-06-01/integrationruntime/model_selfhostedintegrationruntimetypeproperties.go b/resource-manager/synapse/2021-06-01/integrationruntime/model_selfhostedintegrationruntimetypeproperties.go new file mode 100644 index 00000000000..439c4c0a1c1 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/integrationruntime/model_selfhostedintegrationruntimetypeproperties.go @@ -0,0 +1,32 @@ +package integrationruntime + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SelfHostedIntegrationRuntimeTypeProperties struct { + LinkedInfo LinkedIntegrationRuntimeType `json:"linkedInfo"` +} + +var _ json.Unmarshaler = &SelfHostedIntegrationRuntimeTypeProperties{} + +func (s *SelfHostedIntegrationRuntimeTypeProperties) UnmarshalJSON(bytes []byte) error { + + var temp map[string]json.RawMessage + if err := json.Unmarshal(bytes, &temp); err != nil { + return fmt.Errorf("unmarshaling SelfHostedIntegrationRuntimeTypeProperties into map[string]json.RawMessage: %+v", err) + } + + if v, ok := temp["linkedInfo"]; ok { + impl, err := unmarshalLinkedIntegrationRuntimeTypeImplementation(v) + if err != nil { + return fmt.Errorf("unmarshaling field 'LinkedInfo' for 'SelfHostedIntegrationRuntimeTypeProperties': %+v", err) + } + s.LinkedInfo = impl + } + return nil +} diff --git a/resource-manager/synapse/2021-06-01/integrationruntime/model_ssisenvironment.go b/resource-manager/synapse/2021-06-01/integrationruntime/model_ssisenvironment.go new file mode 100644 index 00000000000..c0210e822a0 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/integrationruntime/model_ssisenvironment.go @@ -0,0 +1,45 @@ +package integrationruntime + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ SsisObjectMetadata = SsisEnvironment{} + +type SsisEnvironment struct { + FolderId *int64 `json:"folderId,omitempty"` + Variables *[]SsisVariable `json:"variables,omitempty"` + + // Fields inherited from SsisObjectMetadata + Description *string `json:"description,omitempty"` + Id *int64 `json:"id,omitempty"` + Name *string `json:"name,omitempty"` +} + +var _ json.Marshaler = SsisEnvironment{} + +func (s SsisEnvironment) MarshalJSON() ([]byte, error) { + type wrapper SsisEnvironment + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling SsisEnvironment: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling SsisEnvironment: %+v", err) + } + decoded["type"] = "Environment" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling SsisEnvironment: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/synapse/2021-06-01/integrationruntime/model_ssisenvironmentreference.go b/resource-manager/synapse/2021-06-01/integrationruntime/model_ssisenvironmentreference.go new file mode 100644 index 00000000000..cc8a38d48bc --- /dev/null +++ b/resource-manager/synapse/2021-06-01/integrationruntime/model_ssisenvironmentreference.go @@ -0,0 +1,11 @@ +package integrationruntime + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SsisEnvironmentReference struct { + EnvironmentFolderName *string `json:"environmentFolderName,omitempty"` + EnvironmentName *string `json:"environmentName,omitempty"` + Id *int64 `json:"id,omitempty"` + ReferenceType *string `json:"referenceType,omitempty"` +} diff --git a/resource-manager/synapse/2021-06-01/integrationruntime/model_ssisfolder.go b/resource-manager/synapse/2021-06-01/integrationruntime/model_ssisfolder.go new file mode 100644 index 00000000000..4c2f2a79782 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/integrationruntime/model_ssisfolder.go @@ -0,0 +1,43 @@ +package integrationruntime + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ SsisObjectMetadata = SsisFolder{} + +type SsisFolder struct { + + // Fields inherited from SsisObjectMetadata + Description *string `json:"description,omitempty"` + Id *int64 `json:"id,omitempty"` + Name *string `json:"name,omitempty"` +} + +var _ json.Marshaler = SsisFolder{} + +func (s SsisFolder) MarshalJSON() ([]byte, error) { + type wrapper SsisFolder + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling SsisFolder: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling SsisFolder: %+v", err) + } + decoded["type"] = "Folder" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling SsisFolder: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/synapse/2021-06-01/integrationruntime/model_ssisobjectmetadata.go b/resource-manager/synapse/2021-06-01/integrationruntime/model_ssisobjectmetadata.go new file mode 100644 index 00000000000..8baf9c075c3 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/integrationruntime/model_ssisobjectmetadata.go @@ -0,0 +1,77 @@ +package integrationruntime + +import ( + "encoding/json" + "fmt" + "strings" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SsisObjectMetadata interface { +} + +// RawSsisObjectMetadataImpl is returned when the Discriminated Value +// doesn't match any of the defined types +// NOTE: this should only be used when a type isn't defined for this type of Object (as a workaround) +// and is used only for Deserialization (e.g. this cannot be used as a Request Payload). +type RawSsisObjectMetadataImpl struct { + Type string + Values map[string]interface{} +} + +func unmarshalSsisObjectMetadataImplementation(input []byte) (SsisObjectMetadata, error) { + if input == nil { + return nil, nil + } + + var temp map[string]interface{} + if err := json.Unmarshal(input, &temp); err != nil { + return nil, fmt.Errorf("unmarshaling SsisObjectMetadata into map[string]interface: %+v", err) + } + + value, ok := temp["type"].(string) + if !ok { + return nil, nil + } + + if strings.EqualFold(value, "Environment") { + var out SsisEnvironment + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into SsisEnvironment: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "Folder") { + var out SsisFolder + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into SsisFolder: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "Package") { + var out SsisPackage + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into SsisPackage: %+v", err) + } + return out, nil + } + + if strings.EqualFold(value, "Project") { + var out SsisProject + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into SsisProject: %+v", err) + } + return out, nil + } + + out := RawSsisObjectMetadataImpl{ + Type: value, + Values: temp, + } + return out, nil + +} diff --git a/resource-manager/synapse/2021-06-01/integrationruntime/model_ssisobjectmetadatalistresponse.go b/resource-manager/synapse/2021-06-01/integrationruntime/model_ssisobjectmetadatalistresponse.go new file mode 100644 index 00000000000..36d25acd550 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/integrationruntime/model_ssisobjectmetadatalistresponse.go @@ -0,0 +1,49 @@ +package integrationruntime + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SsisObjectMetadataListResponse struct { + NextLink *string `json:"nextLink,omitempty"` + Value *[]SsisObjectMetadata `json:"value,omitempty"` +} + +var _ json.Unmarshaler = &SsisObjectMetadataListResponse{} + +func (s *SsisObjectMetadataListResponse) UnmarshalJSON(bytes []byte) error { + type alias SsisObjectMetadataListResponse + var decoded alias + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling into SsisObjectMetadataListResponse: %+v", err) + } + + s.NextLink = decoded.NextLink + + var temp map[string]json.RawMessage + if err := json.Unmarshal(bytes, &temp); err != nil { + return fmt.Errorf("unmarshaling SsisObjectMetadataListResponse into map[string]json.RawMessage: %+v", err) + } + + if v, ok := temp["value"]; ok { + var listTemp []json.RawMessage + if err := json.Unmarshal(v, &listTemp); err != nil { + return fmt.Errorf("unmarshaling Value into list []json.RawMessage: %+v", err) + } + + output := make([]SsisObjectMetadata, 0) + for i, val := range listTemp { + impl, err := unmarshalSsisObjectMetadataImplementation(val) + if err != nil { + return fmt.Errorf("unmarshaling index %d field 'Value' for 'SsisObjectMetadataListResponse': %+v", i, err) + } + output = append(output, impl) + } + s.Value = &output + } + return nil +} diff --git a/resource-manager/synapse/2021-06-01/integrationruntime/model_ssisobjectmetadatastatusresponse.go b/resource-manager/synapse/2021-06-01/integrationruntime/model_ssisobjectmetadatastatusresponse.go new file mode 100644 index 00000000000..657150bb5c0 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/integrationruntime/model_ssisobjectmetadatastatusresponse.go @@ -0,0 +1,11 @@ +package integrationruntime + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SsisObjectMetadataStatusResponse struct { + Error *string `json:"error,omitempty"` + Name *string `json:"name,omitempty"` + Properties *string `json:"properties,omitempty"` + Status *string `json:"status,omitempty"` +} diff --git a/resource-manager/synapse/2021-06-01/integrationruntime/model_ssispackage.go b/resource-manager/synapse/2021-06-01/integrationruntime/model_ssispackage.go new file mode 100644 index 00000000000..d33b545a74a --- /dev/null +++ b/resource-manager/synapse/2021-06-01/integrationruntime/model_ssispackage.go @@ -0,0 +1,47 @@ +package integrationruntime + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ SsisObjectMetadata = SsisPackage{} + +type SsisPackage struct { + FolderId *int64 `json:"folderId,omitempty"` + Parameters *[]SsisParameter `json:"parameters,omitempty"` + ProjectId *int64 `json:"projectId,omitempty"` + ProjectVersion *int64 `json:"projectVersion,omitempty"` + + // Fields inherited from SsisObjectMetadata + Description *string `json:"description,omitempty"` + Id *int64 `json:"id,omitempty"` + Name *string `json:"name,omitempty"` +} + +var _ json.Marshaler = SsisPackage{} + +func (s SsisPackage) MarshalJSON() ([]byte, error) { + type wrapper SsisPackage + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling SsisPackage: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling SsisPackage: %+v", err) + } + decoded["type"] = "Package" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling SsisPackage: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/synapse/2021-06-01/integrationruntime/model_ssisparameter.go b/resource-manager/synapse/2021-06-01/integrationruntime/model_ssisparameter.go new file mode 100644 index 00000000000..21936d95d36 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/integrationruntime/model_ssisparameter.go @@ -0,0 +1,19 @@ +package integrationruntime + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SsisParameter struct { + DataType *string `json:"dataType,omitempty"` + DefaultValue *string `json:"defaultValue,omitempty"` + Description *string `json:"description,omitempty"` + DesignDefaultValue *string `json:"designDefaultValue,omitempty"` + Id *int64 `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Required *bool `json:"required,omitempty"` + Sensitive *bool `json:"sensitive,omitempty"` + SensitiveDefaultValue *string `json:"sensitiveDefaultValue,omitempty"` + ValueSet *bool `json:"valueSet,omitempty"` + ValueType *string `json:"valueType,omitempty"` + Variable *string `json:"variable,omitempty"` +} diff --git a/resource-manager/synapse/2021-06-01/integrationruntime/model_ssisproject.go b/resource-manager/synapse/2021-06-01/integrationruntime/model_ssisproject.go new file mode 100644 index 00000000000..c44eeb39dae --- /dev/null +++ b/resource-manager/synapse/2021-06-01/integrationruntime/model_ssisproject.go @@ -0,0 +1,47 @@ +package integrationruntime + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ SsisObjectMetadata = SsisProject{} + +type SsisProject struct { + EnvironmentRefs *[]SsisEnvironmentReference `json:"environmentRefs,omitempty"` + FolderId *int64 `json:"folderId,omitempty"` + Parameters *[]SsisParameter `json:"parameters,omitempty"` + Version *int64 `json:"version,omitempty"` + + // Fields inherited from SsisObjectMetadata + Description *string `json:"description,omitempty"` + Id *int64 `json:"id,omitempty"` + Name *string `json:"name,omitempty"` +} + +var _ json.Marshaler = SsisProject{} + +func (s SsisProject) MarshalJSON() ([]byte, error) { + type wrapper SsisProject + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling SsisProject: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling SsisProject: %+v", err) + } + decoded["type"] = "Project" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling SsisProject: %+v", err) + } + + return encoded, nil +} diff --git a/resource-manager/synapse/2021-06-01/integrationruntime/model_ssisvariable.go b/resource-manager/synapse/2021-06-01/integrationruntime/model_ssisvariable.go new file mode 100644 index 00000000000..354d873e96d --- /dev/null +++ b/resource-manager/synapse/2021-06-01/integrationruntime/model_ssisvariable.go @@ -0,0 +1,14 @@ +package integrationruntime + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SsisVariable struct { + DataType *string `json:"dataType,omitempty"` + Description *string `json:"description,omitempty"` + Id *int64 `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Sensitive *bool `json:"sensitive,omitempty"` + SensitiveValue *string `json:"sensitiveValue,omitempty"` + Value *string `json:"value,omitempty"` +} diff --git a/resource-manager/synapse/2021-06-01/integrationruntime/model_updateintegrationruntimenoderequest.go b/resource-manager/synapse/2021-06-01/integrationruntime/model_updateintegrationruntimenoderequest.go new file mode 100644 index 00000000000..a007b41293c --- /dev/null +++ b/resource-manager/synapse/2021-06-01/integrationruntime/model_updateintegrationruntimenoderequest.go @@ -0,0 +1,8 @@ +package integrationruntime + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type UpdateIntegrationRuntimeNodeRequest struct { + ConcurrentJobsLimit *int64 `json:"concurrentJobsLimit,omitempty"` +} diff --git a/resource-manager/synapse/2021-06-01/integrationruntime/model_updateintegrationruntimerequest.go b/resource-manager/synapse/2021-06-01/integrationruntime/model_updateintegrationruntimerequest.go new file mode 100644 index 00000000000..d38172c9cd2 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/integrationruntime/model_updateintegrationruntimerequest.go @@ -0,0 +1,9 @@ +package integrationruntime + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type UpdateIntegrationRuntimeRequest struct { + AutoUpdate *IntegrationRuntimeAutoUpdate `json:"autoUpdate,omitempty"` + UpdateDelayOffset *string `json:"updateDelayOffset,omitempty"` +} diff --git a/resource-manager/synapse/2021-06-01/integrationruntime/predicates.go b/resource-manager/synapse/2021-06-01/integrationruntime/predicates.go new file mode 100644 index 00000000000..5e5379af578 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/integrationruntime/predicates.go @@ -0,0 +1,32 @@ +package integrationruntime + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IntegrationRuntimeResourceOperationPredicate struct { + Etag *string + Id *string + Name *string + Type *string +} + +func (p IntegrationRuntimeResourceOperationPredicate) Matches(input IntegrationRuntimeResource) bool { + + if p.Etag != nil && (input.Etag == nil || *p.Etag != *input.Etag) { + return false + } + + if p.Id != nil && (input.Id == nil || *p.Id != *input.Id) { + return false + } + + if p.Name != nil && (input.Name == nil || *p.Name != *input.Name) { + return false + } + + if p.Type != nil && (input.Type == nil || *p.Type != *input.Type) { + return false + } + + return true +} diff --git a/resource-manager/synapse/2021-06-01/integrationruntime/version.go b/resource-manager/synapse/2021-06-01/integrationruntime/version.go new file mode 100644 index 00000000000..81eb0b72cca --- /dev/null +++ b/resource-manager/synapse/2021-06-01/integrationruntime/version.go @@ -0,0 +1,12 @@ +package integrationruntime + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2021-06-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/integrationruntime/%s", defaultApiVersion) +} diff --git a/resource-manager/synapse/2021-06-01/integrationruntimes/README.md b/resource-manager/synapse/2021-06-01/integrationruntimes/README.md new file mode 100644 index 00000000000..9b7e278d3f2 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/integrationruntimes/README.md @@ -0,0 +1,36 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/synapse/2021-06-01/integrationruntimes` Documentation + +The `integrationruntimes` SDK allows for interaction with the Azure Resource Manager Service `synapse` (API Version `2021-06-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/synapse/2021-06-01/integrationruntimes" +``` + + +### Client Initialization + +```go +client := integrationruntimes.NewIntegrationRuntimesClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `IntegrationRuntimesClient.ListOutboundNetworkDependenciesEndpoints` + +```go +ctx := context.TODO() +id := integrationruntimes.NewIntegrationRuntimeID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "integrationRuntimeValue") + +read, err := client.ListOutboundNetworkDependenciesEndpoints(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` diff --git a/resource-manager/synapse/2021-06-01/integrationruntimes/client.go b/resource-manager/synapse/2021-06-01/integrationruntimes/client.go new file mode 100644 index 00000000000..a2601dc5e85 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/integrationruntimes/client.go @@ -0,0 +1,26 @@ +package integrationruntimes + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IntegrationRuntimesClient struct { + Client *resourcemanager.Client +} + +func NewIntegrationRuntimesClientWithBaseURI(sdkApi sdkEnv.Api) (*IntegrationRuntimesClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "integrationruntimes", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating IntegrationRuntimesClient: %+v", err) + } + + return &IntegrationRuntimesClient{ + Client: client, + }, nil +} diff --git a/resource-manager/synapse/2021-06-01/integrationruntimes/id_integrationruntime.go b/resource-manager/synapse/2021-06-01/integrationruntimes/id_integrationruntime.go new file mode 100644 index 00000000000..1b5b89bc913 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/integrationruntimes/id_integrationruntime.go @@ -0,0 +1,134 @@ +package integrationruntimes + +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 = &IntegrationRuntimeId{} + +// IntegrationRuntimeId is a struct representing the Resource ID for a Integration Runtime +type IntegrationRuntimeId struct { + SubscriptionId string + ResourceGroupName string + WorkspaceName string + IntegrationRuntimeName string +} + +// NewIntegrationRuntimeID returns a new IntegrationRuntimeId struct +func NewIntegrationRuntimeID(subscriptionId string, resourceGroupName string, workspaceName string, integrationRuntimeName string) IntegrationRuntimeId { + return IntegrationRuntimeId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + WorkspaceName: workspaceName, + IntegrationRuntimeName: integrationRuntimeName, + } +} + +// ParseIntegrationRuntimeID parses 'input' into a IntegrationRuntimeId +func ParseIntegrationRuntimeID(input string) (*IntegrationRuntimeId, error) { + parser := resourceids.NewParserFromResourceIdType(&IntegrationRuntimeId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := IntegrationRuntimeId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseIntegrationRuntimeIDInsensitively parses 'input' case-insensitively into a IntegrationRuntimeId +// note: this method should only be used for API response data and not user input +func ParseIntegrationRuntimeIDInsensitively(input string) (*IntegrationRuntimeId, error) { + parser := resourceids.NewParserFromResourceIdType(&IntegrationRuntimeId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := IntegrationRuntimeId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *IntegrationRuntimeId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.WorkspaceName, ok = input.Parsed["workspaceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "workspaceName", input) + } + + if id.IntegrationRuntimeName, ok = input.Parsed["integrationRuntimeName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "integrationRuntimeName", input) + } + + return nil +} + +// ValidateIntegrationRuntimeID checks that 'input' can be parsed as a Integration Runtime ID +func ValidateIntegrationRuntimeID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseIntegrationRuntimeID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Integration Runtime ID +func (id IntegrationRuntimeId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Synapse/workspaces/%s/integrationRuntimes/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.WorkspaceName, id.IntegrationRuntimeName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Integration Runtime ID +func (id IntegrationRuntimeId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftSynapse", "Microsoft.Synapse", "Microsoft.Synapse"), + resourceids.StaticSegment("staticWorkspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceName", "workspaceValue"), + resourceids.StaticSegment("staticIntegrationRuntimes", "integrationRuntimes", "integrationRuntimes"), + resourceids.UserSpecifiedSegment("integrationRuntimeName", "integrationRuntimeValue"), + } +} + +// String returns a human-readable description of this Integration Runtime ID +func (id IntegrationRuntimeId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Workspace Name: %q", id.WorkspaceName), + fmt.Sprintf("Integration Runtime Name: %q", id.IntegrationRuntimeName), + } + return fmt.Sprintf("Integration Runtime (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/synapse/2021-06-01/integrationruntimes/id_integrationruntime_test.go b/resource-manager/synapse/2021-06-01/integrationruntimes/id_integrationruntime_test.go new file mode 100644 index 00000000000..5f517df0ddd --- /dev/null +++ b/resource-manager/synapse/2021-06-01/integrationruntimes/id_integrationruntime_test.go @@ -0,0 +1,327 @@ +package integrationruntimes + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &IntegrationRuntimeId{} + +func TestNewIntegrationRuntimeID(t *testing.T) { + id := NewIntegrationRuntimeID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "integrationRuntimeValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.WorkspaceName != "workspaceValue" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceName'", id.WorkspaceName, "workspaceValue") + } + + if id.IntegrationRuntimeName != "integrationRuntimeValue" { + t.Fatalf("Expected %q but got %q for Segment 'IntegrationRuntimeName'", id.IntegrationRuntimeName, "integrationRuntimeValue") + } +} + +func TestFormatIntegrationRuntimeID(t *testing.T) { + actual := NewIntegrationRuntimeID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "integrationRuntimeValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/integrationRuntimes/integrationRuntimeValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseIntegrationRuntimeID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *IntegrationRuntimeId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/integrationRuntimes", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/integrationRuntimes/integrationRuntimeValue", + Expected: &IntegrationRuntimeId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + IntegrationRuntimeName: "integrationRuntimeValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/integrationRuntimes/integrationRuntimeValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseIntegrationRuntimeID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + if actual.IntegrationRuntimeName != v.Expected.IntegrationRuntimeName { + t.Fatalf("Expected %q but got %q for IntegrationRuntimeName", v.Expected.IntegrationRuntimeName, actual.IntegrationRuntimeName) + } + + } +} + +func TestParseIntegrationRuntimeIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *IntegrationRuntimeId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/integrationRuntimes", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/iNtEgRaTiOnRuNtImEs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/integrationRuntimes/integrationRuntimeValue", + Expected: &IntegrationRuntimeId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + IntegrationRuntimeName: "integrationRuntimeValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/integrationRuntimes/integrationRuntimeValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/iNtEgRaTiOnRuNtImEs/iNtEgRaTiOnRuNtImEvAlUe", + Expected: &IntegrationRuntimeId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + WorkspaceName: "wOrKsPaCeVaLuE", + IntegrationRuntimeName: "iNtEgRaTiOnRuNtImEvAlUe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/iNtEgRaTiOnRuNtImEs/iNtEgRaTiOnRuNtImEvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseIntegrationRuntimeIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + if actual.IntegrationRuntimeName != v.Expected.IntegrationRuntimeName { + t.Fatalf("Expected %q but got %q for IntegrationRuntimeName", v.Expected.IntegrationRuntimeName, actual.IntegrationRuntimeName) + } + + } +} + +func TestSegmentsForIntegrationRuntimeId(t *testing.T) { + segments := IntegrationRuntimeId{}.Segments() + if len(segments) == 0 { + t.Fatalf("IntegrationRuntimeId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/synapse/2021-06-01/integrationruntimes/method_listoutboundnetworkdependenciesendpoints.go b/resource-manager/synapse/2021-06-01/integrationruntimes/method_listoutboundnetworkdependenciesendpoints.go new file mode 100644 index 00000000000..2127a65136e --- /dev/null +++ b/resource-manager/synapse/2021-06-01/integrationruntimes/method_listoutboundnetworkdependenciesendpoints.go @@ -0,0 +1,52 @@ +package integrationruntimes + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOutboundNetworkDependenciesEndpointsOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *IntegrationRuntimeOutboundNetworkDependenciesEndpointsResponse +} + +// ListOutboundNetworkDependenciesEndpoints ... +func (c IntegrationRuntimesClient) ListOutboundNetworkDependenciesEndpoints(ctx context.Context, id IntegrationRuntimeId) (result ListOutboundNetworkDependenciesEndpointsOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/outboundNetworkDependenciesEndpoints", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/synapse/2021-06-01/integrationruntimes/model_integrationruntimeoutboundnetworkdependenciescategoryendpoint.go b/resource-manager/synapse/2021-06-01/integrationruntimes/model_integrationruntimeoutboundnetworkdependenciescategoryendpoint.go new file mode 100644 index 00000000000..6af22719e80 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/integrationruntimes/model_integrationruntimeoutboundnetworkdependenciescategoryendpoint.go @@ -0,0 +1,9 @@ +package integrationruntimes + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IntegrationRuntimeOutboundNetworkDependenciesCategoryEndpoint struct { + Category *string `json:"category,omitempty"` + Endpoints *[]IntegrationRuntimeOutboundNetworkDependenciesEndpoint `json:"endpoints,omitempty"` +} diff --git a/resource-manager/synapse/2021-06-01/integrationruntimes/model_integrationruntimeoutboundnetworkdependenciesendpoint.go b/resource-manager/synapse/2021-06-01/integrationruntimes/model_integrationruntimeoutboundnetworkdependenciesendpoint.go new file mode 100644 index 00000000000..5dadfd45536 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/integrationruntimes/model_integrationruntimeoutboundnetworkdependenciesendpoint.go @@ -0,0 +1,9 @@ +package integrationruntimes + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IntegrationRuntimeOutboundNetworkDependenciesEndpoint struct { + DomainName *string `json:"domainName,omitempty"` + EndpointDetails *[]IntegrationRuntimeOutboundNetworkDependenciesEndpointDetails `json:"endpointDetails,omitempty"` +} diff --git a/resource-manager/synapse/2021-06-01/integrationruntimes/model_integrationruntimeoutboundnetworkdependenciesendpointdetails.go b/resource-manager/synapse/2021-06-01/integrationruntimes/model_integrationruntimeoutboundnetworkdependenciesendpointdetails.go new file mode 100644 index 00000000000..161c664fb95 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/integrationruntimes/model_integrationruntimeoutboundnetworkdependenciesendpointdetails.go @@ -0,0 +1,8 @@ +package integrationruntimes + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IntegrationRuntimeOutboundNetworkDependenciesEndpointDetails struct { + Port *int64 `json:"port,omitempty"` +} diff --git a/resource-manager/synapse/2021-06-01/integrationruntimes/model_integrationruntimeoutboundnetworkdependenciesendpointsresponse.go b/resource-manager/synapse/2021-06-01/integrationruntimes/model_integrationruntimeoutboundnetworkdependenciesendpointsresponse.go new file mode 100644 index 00000000000..ae824c1e16b --- /dev/null +++ b/resource-manager/synapse/2021-06-01/integrationruntimes/model_integrationruntimeoutboundnetworkdependenciesendpointsresponse.go @@ -0,0 +1,8 @@ +package integrationruntimes + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IntegrationRuntimeOutboundNetworkDependenciesEndpointsResponse struct { + Value *[]IntegrationRuntimeOutboundNetworkDependenciesCategoryEndpoint `json:"value,omitempty"` +} diff --git a/resource-manager/synapse/2021-06-01/integrationruntimes/version.go b/resource-manager/synapse/2021-06-01/integrationruntimes/version.go new file mode 100644 index 00000000000..3a9f3288e9d --- /dev/null +++ b/resource-manager/synapse/2021-06-01/integrationruntimes/version.go @@ -0,0 +1,12 @@ +package integrationruntimes + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2021-06-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/integrationruntimes/%s", defaultApiVersion) +} diff --git a/resource-manager/synapse/2021-06-01/ipfirewallrules/README.md b/resource-manager/synapse/2021-06-01/ipfirewallrules/README.md new file mode 100644 index 00000000000..bda60a6d63d --- /dev/null +++ b/resource-manager/synapse/2021-06-01/ipfirewallrules/README.md @@ -0,0 +1,99 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/synapse/2021-06-01/ipfirewallrules` Documentation + +The `ipfirewallrules` SDK allows for interaction with the Azure Resource Manager Service `synapse` (API Version `2021-06-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/synapse/2021-06-01/ipfirewallrules" +``` + + +### Client Initialization + +```go +client := ipfirewallrules.NewIPFirewallRulesClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `IPFirewallRulesClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := ipfirewallrules.NewFirewallRuleID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "firewallRuleValue") + +payload := ipfirewallrules.IPFirewallRuleInfo{ + // ... +} + + +if err := client.CreateOrUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `IPFirewallRulesClient.Delete` + +```go +ctx := context.TODO() +id := ipfirewallrules.NewFirewallRuleID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "firewallRuleValue") + +if err := client.DeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `IPFirewallRulesClient.Get` + +```go +ctx := context.TODO() +id := ipfirewallrules.NewFirewallRuleID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "firewallRuleValue") + +read, err := client.Get(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `IPFirewallRulesClient.ListByWorkspace` + +```go +ctx := context.TODO() +id := ipfirewallrules.NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue") + +// alternatively `client.ListByWorkspace(ctx, id)` can be used to do batched pagination +items, err := client.ListByWorkspaceComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `IPFirewallRulesClient.ReplaceAll` + +```go +ctx := context.TODO() +id := ipfirewallrules.NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue") + +payload := ipfirewallrules.ReplaceAllIPFirewallRulesRequest{ + // ... +} + + +if err := client.ReplaceAllThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` diff --git a/resource-manager/synapse/2021-06-01/ipfirewallrules/client.go b/resource-manager/synapse/2021-06-01/ipfirewallrules/client.go new file mode 100644 index 00000000000..ef006a6dae3 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/ipfirewallrules/client.go @@ -0,0 +1,26 @@ +package ipfirewallrules + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IPFirewallRulesClient struct { + Client *resourcemanager.Client +} + +func NewIPFirewallRulesClientWithBaseURI(sdkApi sdkEnv.Api) (*IPFirewallRulesClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "ipfirewallrules", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating IPFirewallRulesClient: %+v", err) + } + + return &IPFirewallRulesClient{ + Client: client, + }, nil +} diff --git a/resource-manager/synapse/2021-06-01/ipfirewallrules/constants.go b/resource-manager/synapse/2021-06-01/ipfirewallrules/constants.go new file mode 100644 index 00000000000..f93f23452cd --- /dev/null +++ b/resource-manager/synapse/2021-06-01/ipfirewallrules/constants.go @@ -0,0 +1,60 @@ +package ipfirewallrules + +import ( + "encoding/json" + "fmt" + "strings" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ProvisioningState string + +const ( + ProvisioningStateDeleteError ProvisioningState = "DeleteError" + ProvisioningStateDeleting ProvisioningState = "Deleting" + ProvisioningStateFailed ProvisioningState = "Failed" + ProvisioningStateProvisioning ProvisioningState = "Provisioning" + ProvisioningStateSucceeded ProvisioningState = "Succeeded" +) + +func PossibleValuesForProvisioningState() []string { + return []string{ + string(ProvisioningStateDeleteError), + string(ProvisioningStateDeleting), + string(ProvisioningStateFailed), + string(ProvisioningStateProvisioning), + string(ProvisioningStateSucceeded), + } +} + +func (s *ProvisioningState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseProvisioningState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseProvisioningState(input string) (*ProvisioningState, error) { + vals := map[string]ProvisioningState{ + "deleteerror": ProvisioningStateDeleteError, + "deleting": ProvisioningStateDeleting, + "failed": ProvisioningStateFailed, + "provisioning": ProvisioningStateProvisioning, + "succeeded": ProvisioningStateSucceeded, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ProvisioningState(input) + return &out, nil +} diff --git a/resource-manager/synapse/2021-06-01/ipfirewallrules/id_firewallrule.go b/resource-manager/synapse/2021-06-01/ipfirewallrules/id_firewallrule.go new file mode 100644 index 00000000000..1d989e094d8 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/ipfirewallrules/id_firewallrule.go @@ -0,0 +1,134 @@ +package ipfirewallrules + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &FirewallRuleId{} + +// FirewallRuleId is a struct representing the Resource ID for a Firewall Rule +type FirewallRuleId struct { + SubscriptionId string + ResourceGroupName string + WorkspaceName string + FirewallRuleName string +} + +// NewFirewallRuleID returns a new FirewallRuleId struct +func NewFirewallRuleID(subscriptionId string, resourceGroupName string, workspaceName string, firewallRuleName string) FirewallRuleId { + return FirewallRuleId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + WorkspaceName: workspaceName, + FirewallRuleName: firewallRuleName, + } +} + +// ParseFirewallRuleID parses 'input' into a FirewallRuleId +func ParseFirewallRuleID(input string) (*FirewallRuleId, error) { + parser := resourceids.NewParserFromResourceIdType(&FirewallRuleId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := FirewallRuleId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseFirewallRuleIDInsensitively parses 'input' case-insensitively into a FirewallRuleId +// note: this method should only be used for API response data and not user input +func ParseFirewallRuleIDInsensitively(input string) (*FirewallRuleId, error) { + parser := resourceids.NewParserFromResourceIdType(&FirewallRuleId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := FirewallRuleId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *FirewallRuleId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.WorkspaceName, ok = input.Parsed["workspaceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "workspaceName", input) + } + + if id.FirewallRuleName, ok = input.Parsed["firewallRuleName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "firewallRuleName", input) + } + + return nil +} + +// ValidateFirewallRuleID checks that 'input' can be parsed as a Firewall Rule ID +func ValidateFirewallRuleID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseFirewallRuleID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Firewall Rule ID +func (id FirewallRuleId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Synapse/workspaces/%s/firewallRules/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.WorkspaceName, id.FirewallRuleName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Firewall Rule ID +func (id FirewallRuleId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftSynapse", "Microsoft.Synapse", "Microsoft.Synapse"), + resourceids.StaticSegment("staticWorkspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceName", "workspaceValue"), + resourceids.StaticSegment("staticFirewallRules", "firewallRules", "firewallRules"), + resourceids.UserSpecifiedSegment("firewallRuleName", "firewallRuleValue"), + } +} + +// String returns a human-readable description of this Firewall Rule ID +func (id FirewallRuleId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Workspace Name: %q", id.WorkspaceName), + fmt.Sprintf("Firewall Rule Name: %q", id.FirewallRuleName), + } + return fmt.Sprintf("Firewall Rule (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/synapse/2021-06-01/ipfirewallrules/id_firewallrule_test.go b/resource-manager/synapse/2021-06-01/ipfirewallrules/id_firewallrule_test.go new file mode 100644 index 00000000000..c2929a8e95f --- /dev/null +++ b/resource-manager/synapse/2021-06-01/ipfirewallrules/id_firewallrule_test.go @@ -0,0 +1,327 @@ +package ipfirewallrules + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &FirewallRuleId{} + +func TestNewFirewallRuleID(t *testing.T) { + id := NewFirewallRuleID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "firewallRuleValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.WorkspaceName != "workspaceValue" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceName'", id.WorkspaceName, "workspaceValue") + } + + if id.FirewallRuleName != "firewallRuleValue" { + t.Fatalf("Expected %q but got %q for Segment 'FirewallRuleName'", id.FirewallRuleName, "firewallRuleValue") + } +} + +func TestFormatFirewallRuleID(t *testing.T) { + actual := NewFirewallRuleID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "firewallRuleValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/firewallRules/firewallRuleValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseFirewallRuleID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *FirewallRuleId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/firewallRules", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/firewallRules/firewallRuleValue", + Expected: &FirewallRuleId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + FirewallRuleName: "firewallRuleValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/firewallRules/firewallRuleValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseFirewallRuleID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + if actual.FirewallRuleName != v.Expected.FirewallRuleName { + t.Fatalf("Expected %q but got %q for FirewallRuleName", v.Expected.FirewallRuleName, actual.FirewallRuleName) + } + + } +} + +func TestParseFirewallRuleIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *FirewallRuleId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/firewallRules", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/fIrEwAlLrUlEs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/firewallRules/firewallRuleValue", + Expected: &FirewallRuleId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + FirewallRuleName: "firewallRuleValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/firewallRules/firewallRuleValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/fIrEwAlLrUlEs/fIrEwAlLrUlEvAlUe", + Expected: &FirewallRuleId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + WorkspaceName: "wOrKsPaCeVaLuE", + FirewallRuleName: "fIrEwAlLrUlEvAlUe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/fIrEwAlLrUlEs/fIrEwAlLrUlEvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseFirewallRuleIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + if actual.FirewallRuleName != v.Expected.FirewallRuleName { + t.Fatalf("Expected %q but got %q for FirewallRuleName", v.Expected.FirewallRuleName, actual.FirewallRuleName) + } + + } +} + +func TestSegmentsForFirewallRuleId(t *testing.T) { + segments := FirewallRuleId{}.Segments() + if len(segments) == 0 { + t.Fatalf("FirewallRuleId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/synapse/2021-06-01/ipfirewallrules/id_workspace.go b/resource-manager/synapse/2021-06-01/ipfirewallrules/id_workspace.go new file mode 100644 index 00000000000..2ca83eeb012 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/ipfirewallrules/id_workspace.go @@ -0,0 +1,125 @@ +package ipfirewallrules + +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 = &WorkspaceId{} + +// WorkspaceId is a struct representing the Resource ID for a Workspace +type WorkspaceId struct { + SubscriptionId string + ResourceGroupName string + WorkspaceName string +} + +// NewWorkspaceID returns a new WorkspaceId struct +func NewWorkspaceID(subscriptionId string, resourceGroupName string, workspaceName string) WorkspaceId { + return WorkspaceId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + WorkspaceName: workspaceName, + } +} + +// ParseWorkspaceID parses 'input' into a WorkspaceId +func ParseWorkspaceID(input string) (*WorkspaceId, error) { + parser := resourceids.NewParserFromResourceIdType(&WorkspaceId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := WorkspaceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseWorkspaceIDInsensitively parses 'input' case-insensitively into a WorkspaceId +// note: this method should only be used for API response data and not user input +func ParseWorkspaceIDInsensitively(input string) (*WorkspaceId, error) { + parser := resourceids.NewParserFromResourceIdType(&WorkspaceId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := WorkspaceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *WorkspaceId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.WorkspaceName, ok = input.Parsed["workspaceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "workspaceName", input) + } + + return nil +} + +// ValidateWorkspaceID checks that 'input' can be parsed as a Workspace ID +func ValidateWorkspaceID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseWorkspaceID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Workspace ID +func (id WorkspaceId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Synapse/workspaces/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.WorkspaceName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Workspace ID +func (id WorkspaceId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftSynapse", "Microsoft.Synapse", "Microsoft.Synapse"), + resourceids.StaticSegment("staticWorkspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceName", "workspaceValue"), + } +} + +// String returns a human-readable description of this Workspace ID +func (id WorkspaceId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Workspace Name: %q", id.WorkspaceName), + } + return fmt.Sprintf("Workspace (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/synapse/2021-06-01/ipfirewallrules/id_workspace_test.go b/resource-manager/synapse/2021-06-01/ipfirewallrules/id_workspace_test.go new file mode 100644 index 00000000000..81c345e33a0 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/ipfirewallrules/id_workspace_test.go @@ -0,0 +1,282 @@ +package ipfirewallrules + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &WorkspaceId{} + +func TestNewWorkspaceID(t *testing.T) { + id := NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.WorkspaceName != "workspaceValue" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceName'", id.WorkspaceName, "workspaceValue") + } +} + +func TestFormatWorkspaceID(t *testing.T) { + actual := NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseWorkspaceID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkspaceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue", + Expected: &WorkspaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkspaceID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + } +} + +func TestParseWorkspaceIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkspaceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue", + Expected: &WorkspaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE", + Expected: &WorkspaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + WorkspaceName: "wOrKsPaCeVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkspaceIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + } +} + +func TestSegmentsForWorkspaceId(t *testing.T) { + segments := WorkspaceId{}.Segments() + if len(segments) == 0 { + t.Fatalf("WorkspaceId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/synapse/2021-06-01/ipfirewallrules/method_createorupdate.go b/resource-manager/synapse/2021-06-01/ipfirewallrules/method_createorupdate.go new file mode 100644 index 00000000000..bfb6f4f63f2 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/ipfirewallrules/method_createorupdate.go @@ -0,0 +1,76 @@ +package ipfirewallrules + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOrUpdateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *IPFirewallRuleInfo +} + +// CreateOrUpdate ... +func (c IPFirewallRulesClient) CreateOrUpdate(ctx context.Context, id FirewallRuleId, input IPFirewallRuleInfo) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// CreateOrUpdateThenPoll performs CreateOrUpdate then polls until it's completed +func (c IPFirewallRulesClient) CreateOrUpdateThenPoll(ctx context.Context, id FirewallRuleId, input IPFirewallRuleInfo) error { + result, err := c.CreateOrUpdate(ctx, id, input) + if err != nil { + return fmt.Errorf("performing CreateOrUpdate: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after CreateOrUpdate: %+v", err) + } + + return nil +} diff --git a/resource-manager/synapse/2021-06-01/ipfirewallrules/method_delete.go b/resource-manager/synapse/2021-06-01/ipfirewallrules/method_delete.go new file mode 100644 index 00000000000..145ff809582 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/ipfirewallrules/method_delete.go @@ -0,0 +1,72 @@ +package ipfirewallrules + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *IPFirewallRuleInfo +} + +// Delete ... +func (c IPFirewallRulesClient) Delete(ctx context.Context, id FirewallRuleId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// DeleteThenPoll performs Delete then polls until it's completed +func (c IPFirewallRulesClient) DeleteThenPoll(ctx context.Context, id FirewallRuleId) error { + result, err := c.Delete(ctx, id) + if err != nil { + return fmt.Errorf("performing Delete: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after Delete: %+v", err) + } + + return nil +} diff --git a/resource-manager/synapse/2021-06-01/ipfirewallrules/method_get.go b/resource-manager/synapse/2021-06-01/ipfirewallrules/method_get.go new file mode 100644 index 00000000000..834a7db7dd3 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/ipfirewallrules/method_get.go @@ -0,0 +1,51 @@ +package ipfirewallrules + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *IPFirewallRuleInfo +} + +// Get ... +func (c IPFirewallRulesClient) Get(ctx context.Context, id FirewallRuleId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/synapse/2021-06-01/ipfirewallrules/method_listbyworkspace.go b/resource-manager/synapse/2021-06-01/ipfirewallrules/method_listbyworkspace.go new file mode 100644 index 00000000000..470c8d5d02d --- /dev/null +++ b/resource-manager/synapse/2021-06-01/ipfirewallrules/method_listbyworkspace.go @@ -0,0 +1,91 @@ +package ipfirewallrules + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListByWorkspaceOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]IPFirewallRuleInfo +} + +type ListByWorkspaceCompleteResult struct { + LatestHttpResponse *http.Response + Items []IPFirewallRuleInfo +} + +// ListByWorkspace ... +func (c IPFirewallRulesClient) ListByWorkspace(ctx context.Context, id WorkspaceId) (result ListByWorkspaceOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/firewallRules", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]IPFirewallRuleInfo `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByWorkspaceComplete retrieves all the results into a single object +func (c IPFirewallRulesClient) ListByWorkspaceComplete(ctx context.Context, id WorkspaceId) (ListByWorkspaceCompleteResult, error) { + return c.ListByWorkspaceCompleteMatchingPredicate(ctx, id, IPFirewallRuleInfoOperationPredicate{}) +} + +// ListByWorkspaceCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c IPFirewallRulesClient) ListByWorkspaceCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, predicate IPFirewallRuleInfoOperationPredicate) (result ListByWorkspaceCompleteResult, err error) { + items := make([]IPFirewallRuleInfo, 0) + + resp, err := c.ListByWorkspace(ctx, id) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByWorkspaceCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/synapse/2021-06-01/ipfirewallrules/method_replaceall.go b/resource-manager/synapse/2021-06-01/ipfirewallrules/method_replaceall.go new file mode 100644 index 00000000000..4009a7fe251 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/ipfirewallrules/method_replaceall.go @@ -0,0 +1,75 @@ +package ipfirewallrules + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ReplaceAllOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *ReplaceAllFirewallRulesOperationResponse +} + +// ReplaceAll ... +func (c IPFirewallRulesClient) ReplaceAll(ctx context.Context, id WorkspaceId, input ReplaceAllIPFirewallRulesRequest) (result ReplaceAllOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/replaceAllIpFirewallRules", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// ReplaceAllThenPoll performs ReplaceAll then polls until it's completed +func (c IPFirewallRulesClient) ReplaceAllThenPoll(ctx context.Context, id WorkspaceId, input ReplaceAllIPFirewallRulesRequest) error { + result, err := c.ReplaceAll(ctx, id, input) + if err != nil { + return fmt.Errorf("performing ReplaceAll: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after ReplaceAll: %+v", err) + } + + return nil +} diff --git a/resource-manager/synapse/2021-06-01/ipfirewallrules/model_ipfirewallruleinfo.go b/resource-manager/synapse/2021-06-01/ipfirewallrules/model_ipfirewallruleinfo.go new file mode 100644 index 00000000000..4e9dc777e30 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/ipfirewallrules/model_ipfirewallruleinfo.go @@ -0,0 +1,11 @@ +package ipfirewallrules + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IPFirewallRuleInfo struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *IPFirewallRuleProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/synapse/2021-06-01/ipfirewallrules/model_ipfirewallruleproperties.go b/resource-manager/synapse/2021-06-01/ipfirewallrules/model_ipfirewallruleproperties.go new file mode 100644 index 00000000000..a3dca52dca8 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/ipfirewallrules/model_ipfirewallruleproperties.go @@ -0,0 +1,10 @@ +package ipfirewallrules + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IPFirewallRuleProperties struct { + EndIPAddress *string `json:"endIpAddress,omitempty"` + ProvisioningState *ProvisioningState `json:"provisioningState,omitempty"` + StartIPAddress *string `json:"startIpAddress,omitempty"` +} diff --git a/resource-manager/synapse/2021-06-01/ipfirewallrules/model_replaceallfirewallrulesoperationresponse.go b/resource-manager/synapse/2021-06-01/ipfirewallrules/model_replaceallfirewallrulesoperationresponse.go new file mode 100644 index 00000000000..f3870f8f3a2 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/ipfirewallrules/model_replaceallfirewallrulesoperationresponse.go @@ -0,0 +1,8 @@ +package ipfirewallrules + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ReplaceAllFirewallRulesOperationResponse struct { + OperationId *string `json:"operationId,omitempty"` +} diff --git a/resource-manager/synapse/2021-06-01/ipfirewallrules/model_replaceallipfirewallrulesrequest.go b/resource-manager/synapse/2021-06-01/ipfirewallrules/model_replaceallipfirewallrulesrequest.go new file mode 100644 index 00000000000..c02b0126f52 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/ipfirewallrules/model_replaceallipfirewallrulesrequest.go @@ -0,0 +1,8 @@ +package ipfirewallrules + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ReplaceAllIPFirewallRulesRequest struct { + IPFirewallRules *map[string]IPFirewallRuleProperties `json:"ipFirewallRules,omitempty"` +} diff --git a/resource-manager/synapse/2021-06-01/ipfirewallrules/predicates.go b/resource-manager/synapse/2021-06-01/ipfirewallrules/predicates.go new file mode 100644 index 00000000000..1f9226720a5 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/ipfirewallrules/predicates.go @@ -0,0 +1,27 @@ +package ipfirewallrules + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IPFirewallRuleInfoOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p IPFirewallRuleInfoOperationPredicate) Matches(input IPFirewallRuleInfo) bool { + + if p.Id != nil && (input.Id == nil || *p.Id != *input.Id) { + return false + } + + if p.Name != nil && (input.Name == nil || *p.Name != *input.Name) { + return false + } + + if p.Type != nil && (input.Type == nil || *p.Type != *input.Type) { + return false + } + + return true +} diff --git a/resource-manager/synapse/2021-06-01/ipfirewallrules/version.go b/resource-manager/synapse/2021-06-01/ipfirewallrules/version.go new file mode 100644 index 00000000000..c9d807787ca --- /dev/null +++ b/resource-manager/synapse/2021-06-01/ipfirewallrules/version.go @@ -0,0 +1,12 @@ +package ipfirewallrules + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2021-06-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/ipfirewallrules/%s", defaultApiVersion) +} diff --git a/resource-manager/synapse/2021-06-01/keys/README.md b/resource-manager/synapse/2021-06-01/keys/README.md new file mode 100644 index 00000000000..38af64aafc7 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/keys/README.md @@ -0,0 +1,90 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/synapse/2021-06-01/keys` Documentation + +The `keys` SDK allows for interaction with the Azure Resource Manager Service `synapse` (API Version `2021-06-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/synapse/2021-06-01/keys" +``` + + +### Client Initialization + +```go +client := keys.NewKeysClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `KeysClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := keys.NewKeyID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "keyValue") + +payload := keys.Key{ + // ... +} + + +read, err := client.CreateOrUpdate(ctx, id, payload) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `KeysClient.Delete` + +```go +ctx := context.TODO() +id := keys.NewKeyID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "keyValue") + +read, err := client.Delete(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `KeysClient.Get` + +```go +ctx := context.TODO() +id := keys.NewKeyID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "keyValue") + +read, err := client.Get(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `KeysClient.ListByWorkspace` + +```go +ctx := context.TODO() +id := keys.NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue") + +// alternatively `client.ListByWorkspace(ctx, id)` can be used to do batched pagination +items, err := client.ListByWorkspaceComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/synapse/2021-06-01/keys/client.go b/resource-manager/synapse/2021-06-01/keys/client.go new file mode 100644 index 00000000000..91e56411c78 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/keys/client.go @@ -0,0 +1,26 @@ +package keys + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type KeysClient struct { + Client *resourcemanager.Client +} + +func NewKeysClientWithBaseURI(sdkApi sdkEnv.Api) (*KeysClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "keys", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating KeysClient: %+v", err) + } + + return &KeysClient{ + Client: client, + }, nil +} diff --git a/resource-manager/synapse/2021-06-01/keys/id_key.go b/resource-manager/synapse/2021-06-01/keys/id_key.go new file mode 100644 index 00000000000..8fec006bdbe --- /dev/null +++ b/resource-manager/synapse/2021-06-01/keys/id_key.go @@ -0,0 +1,134 @@ +package keys + +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 = &KeyId{} + +// KeyId is a struct representing the Resource ID for a Key +type KeyId struct { + SubscriptionId string + ResourceGroupName string + WorkspaceName string + KeyName string +} + +// NewKeyID returns a new KeyId struct +func NewKeyID(subscriptionId string, resourceGroupName string, workspaceName string, keyName string) KeyId { + return KeyId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + WorkspaceName: workspaceName, + KeyName: keyName, + } +} + +// ParseKeyID parses 'input' into a KeyId +func ParseKeyID(input string) (*KeyId, error) { + parser := resourceids.NewParserFromResourceIdType(&KeyId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := KeyId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseKeyIDInsensitively parses 'input' case-insensitively into a KeyId +// note: this method should only be used for API response data and not user input +func ParseKeyIDInsensitively(input string) (*KeyId, error) { + parser := resourceids.NewParserFromResourceIdType(&KeyId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := KeyId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *KeyId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.WorkspaceName, ok = input.Parsed["workspaceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "workspaceName", input) + } + + if id.KeyName, ok = input.Parsed["keyName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "keyName", input) + } + + return nil +} + +// ValidateKeyID checks that 'input' can be parsed as a Key ID +func ValidateKeyID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseKeyID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Key ID +func (id KeyId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Synapse/workspaces/%s/keys/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.WorkspaceName, id.KeyName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Key ID +func (id KeyId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftSynapse", "Microsoft.Synapse", "Microsoft.Synapse"), + resourceids.StaticSegment("staticWorkspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceName", "workspaceValue"), + resourceids.StaticSegment("staticKeys", "keys", "keys"), + resourceids.UserSpecifiedSegment("keyName", "keyValue"), + } +} + +// String returns a human-readable description of this Key ID +func (id KeyId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Workspace Name: %q", id.WorkspaceName), + fmt.Sprintf("Key Name: %q", id.KeyName), + } + return fmt.Sprintf("Key (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/synapse/2021-06-01/keys/id_key_test.go b/resource-manager/synapse/2021-06-01/keys/id_key_test.go new file mode 100644 index 00000000000..f4a243c2991 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/keys/id_key_test.go @@ -0,0 +1,327 @@ +package keys + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &KeyId{} + +func TestNewKeyID(t *testing.T) { + id := NewKeyID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "keyValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.WorkspaceName != "workspaceValue" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceName'", id.WorkspaceName, "workspaceValue") + } + + if id.KeyName != "keyValue" { + t.Fatalf("Expected %q but got %q for Segment 'KeyName'", id.KeyName, "keyValue") + } +} + +func TestFormatKeyID(t *testing.T) { + actual := NewKeyID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "keyValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/keys/keyValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseKeyID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *KeyId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/keys", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/keys/keyValue", + Expected: &KeyId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + KeyName: "keyValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/keys/keyValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseKeyID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + if actual.KeyName != v.Expected.KeyName { + t.Fatalf("Expected %q but got %q for KeyName", v.Expected.KeyName, actual.KeyName) + } + + } +} + +func TestParseKeyIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *KeyId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/keys", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/kEyS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/keys/keyValue", + Expected: &KeyId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + KeyName: "keyValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/keys/keyValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/kEyS/kEyVaLuE", + Expected: &KeyId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + WorkspaceName: "wOrKsPaCeVaLuE", + KeyName: "kEyVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/kEyS/kEyVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseKeyIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + if actual.KeyName != v.Expected.KeyName { + t.Fatalf("Expected %q but got %q for KeyName", v.Expected.KeyName, actual.KeyName) + } + + } +} + +func TestSegmentsForKeyId(t *testing.T) { + segments := KeyId{}.Segments() + if len(segments) == 0 { + t.Fatalf("KeyId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/synapse/2021-06-01/keys/id_workspace.go b/resource-manager/synapse/2021-06-01/keys/id_workspace.go new file mode 100644 index 00000000000..24848f79340 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/keys/id_workspace.go @@ -0,0 +1,125 @@ +package keys + +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 = &WorkspaceId{} + +// WorkspaceId is a struct representing the Resource ID for a Workspace +type WorkspaceId struct { + SubscriptionId string + ResourceGroupName string + WorkspaceName string +} + +// NewWorkspaceID returns a new WorkspaceId struct +func NewWorkspaceID(subscriptionId string, resourceGroupName string, workspaceName string) WorkspaceId { + return WorkspaceId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + WorkspaceName: workspaceName, + } +} + +// ParseWorkspaceID parses 'input' into a WorkspaceId +func ParseWorkspaceID(input string) (*WorkspaceId, error) { + parser := resourceids.NewParserFromResourceIdType(&WorkspaceId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := WorkspaceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseWorkspaceIDInsensitively parses 'input' case-insensitively into a WorkspaceId +// note: this method should only be used for API response data and not user input +func ParseWorkspaceIDInsensitively(input string) (*WorkspaceId, error) { + parser := resourceids.NewParserFromResourceIdType(&WorkspaceId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := WorkspaceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *WorkspaceId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.WorkspaceName, ok = input.Parsed["workspaceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "workspaceName", input) + } + + return nil +} + +// ValidateWorkspaceID checks that 'input' can be parsed as a Workspace ID +func ValidateWorkspaceID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseWorkspaceID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Workspace ID +func (id WorkspaceId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Synapse/workspaces/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.WorkspaceName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Workspace ID +func (id WorkspaceId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftSynapse", "Microsoft.Synapse", "Microsoft.Synapse"), + resourceids.StaticSegment("staticWorkspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceName", "workspaceValue"), + } +} + +// String returns a human-readable description of this Workspace ID +func (id WorkspaceId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Workspace Name: %q", id.WorkspaceName), + } + return fmt.Sprintf("Workspace (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/synapse/2021-06-01/keys/id_workspace_test.go b/resource-manager/synapse/2021-06-01/keys/id_workspace_test.go new file mode 100644 index 00000000000..3becfa71d57 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/keys/id_workspace_test.go @@ -0,0 +1,282 @@ +package keys + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &WorkspaceId{} + +func TestNewWorkspaceID(t *testing.T) { + id := NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.WorkspaceName != "workspaceValue" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceName'", id.WorkspaceName, "workspaceValue") + } +} + +func TestFormatWorkspaceID(t *testing.T) { + actual := NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseWorkspaceID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkspaceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue", + Expected: &WorkspaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkspaceID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + } +} + +func TestParseWorkspaceIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkspaceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue", + Expected: &WorkspaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE", + Expected: &WorkspaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + WorkspaceName: "wOrKsPaCeVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkspaceIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + } +} + +func TestSegmentsForWorkspaceId(t *testing.T) { + segments := WorkspaceId{}.Segments() + if len(segments) == 0 { + t.Fatalf("WorkspaceId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/synapse/2021-06-01/keys/method_createorupdate.go b/resource-manager/synapse/2021-06-01/keys/method_createorupdate.go new file mode 100644 index 00000000000..ffcf0ca0423 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/keys/method_createorupdate.go @@ -0,0 +1,55 @@ +package keys + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *Key +} + +// CreateOrUpdate ... +func (c KeysClient) CreateOrUpdate(ctx context.Context, id KeyId, input Key) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/synapse/2021-06-01/keys/method_delete.go b/resource-manager/synapse/2021-06-01/keys/method_delete.go new file mode 100644 index 00000000000..d7a382318b4 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/keys/method_delete.go @@ -0,0 +1,52 @@ +package keys + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *Key +} + +// Delete ... +func (c KeysClient) Delete(ctx context.Context, id KeyId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/synapse/2021-06-01/keys/method_get.go b/resource-manager/synapse/2021-06-01/keys/method_get.go new file mode 100644 index 00000000000..f530462d790 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/keys/method_get.go @@ -0,0 +1,51 @@ +package keys + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *Key +} + +// Get ... +func (c KeysClient) Get(ctx context.Context, id KeyId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/synapse/2021-06-01/keys/method_listbyworkspace.go b/resource-manager/synapse/2021-06-01/keys/method_listbyworkspace.go new file mode 100644 index 00000000000..333a05a381a --- /dev/null +++ b/resource-manager/synapse/2021-06-01/keys/method_listbyworkspace.go @@ -0,0 +1,91 @@ +package keys + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListByWorkspaceOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]Key +} + +type ListByWorkspaceCompleteResult struct { + LatestHttpResponse *http.Response + Items []Key +} + +// ListByWorkspace ... +func (c KeysClient) ListByWorkspace(ctx context.Context, id WorkspaceId) (result ListByWorkspaceOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/keys", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]Key `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByWorkspaceComplete retrieves all the results into a single object +func (c KeysClient) ListByWorkspaceComplete(ctx context.Context, id WorkspaceId) (ListByWorkspaceCompleteResult, error) { + return c.ListByWorkspaceCompleteMatchingPredicate(ctx, id, KeyOperationPredicate{}) +} + +// ListByWorkspaceCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c KeysClient) ListByWorkspaceCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, predicate KeyOperationPredicate) (result ListByWorkspaceCompleteResult, err error) { + items := make([]Key, 0) + + resp, err := c.ListByWorkspace(ctx, id) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByWorkspaceCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/synapse/2021-06-01/keys/model_key.go b/resource-manager/synapse/2021-06-01/keys/model_key.go new file mode 100644 index 00000000000..0de7186d365 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/keys/model_key.go @@ -0,0 +1,11 @@ +package keys + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Key struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *KeyProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/synapse/2021-06-01/keys/model_keyproperties.go b/resource-manager/synapse/2021-06-01/keys/model_keyproperties.go new file mode 100644 index 00000000000..253fb70487f --- /dev/null +++ b/resource-manager/synapse/2021-06-01/keys/model_keyproperties.go @@ -0,0 +1,9 @@ +package keys + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type KeyProperties struct { + IsActiveCMK *bool `json:"isActiveCMK,omitempty"` + KeyVaultUrl *string `json:"keyVaultUrl,omitempty"` +} diff --git a/resource-manager/synapse/2021-06-01/keys/predicates.go b/resource-manager/synapse/2021-06-01/keys/predicates.go new file mode 100644 index 00000000000..bb58c6b0d23 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/keys/predicates.go @@ -0,0 +1,27 @@ +package keys + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type KeyOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p KeyOperationPredicate) Matches(input Key) bool { + + if p.Id != nil && (input.Id == nil || *p.Id != *input.Id) { + return false + } + + if p.Name != nil && (input.Name == nil || *p.Name != *input.Name) { + return false + } + + if p.Type != nil && (input.Type == nil || *p.Type != *input.Type) { + return false + } + + return true +} diff --git a/resource-manager/synapse/2021-06-01/keys/version.go b/resource-manager/synapse/2021-06-01/keys/version.go new file mode 100644 index 00000000000..1f5038d3fb2 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/keys/version.go @@ -0,0 +1,12 @@ +package keys + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2021-06-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/keys/%s", defaultApiVersion) +} diff --git a/resource-manager/synapse/2021-06-01/libraries/README.md b/resource-manager/synapse/2021-06-01/libraries/README.md new file mode 100644 index 00000000000..69c2f46ad11 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/libraries/README.md @@ -0,0 +1,53 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/synapse/2021-06-01/libraries` Documentation + +The `libraries` SDK allows for interaction with the Azure Resource Manager Service `synapse` (API Version `2021-06-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/synapse/2021-06-01/libraries" +``` + + +### Client Initialization + +```go +client := libraries.NewLibrariesClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `LibrariesClient.LibraryGet` + +```go +ctx := context.TODO() +id := libraries.NewLibraryID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "libraryValue") + +read, err := client.LibraryGet(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `LibrariesClient.ListByWorkspace` + +```go +ctx := context.TODO() +id := libraries.NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue") + +// alternatively `client.ListByWorkspace(ctx, id)` can be used to do batched pagination +items, err := client.ListByWorkspaceComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/synapse/2021-06-01/libraries/client.go b/resource-manager/synapse/2021-06-01/libraries/client.go new file mode 100644 index 00000000000..a165bcc5ff2 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/libraries/client.go @@ -0,0 +1,26 @@ +package libraries + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type LibrariesClient struct { + Client *resourcemanager.Client +} + +func NewLibrariesClientWithBaseURI(sdkApi sdkEnv.Api) (*LibrariesClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "libraries", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating LibrariesClient: %+v", err) + } + + return &LibrariesClient{ + Client: client, + }, nil +} diff --git a/resource-manager/synapse/2021-06-01/libraries/id_library.go b/resource-manager/synapse/2021-06-01/libraries/id_library.go new file mode 100644 index 00000000000..6dfa954fcc5 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/libraries/id_library.go @@ -0,0 +1,134 @@ +package libraries + +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 = &LibraryId{} + +// LibraryId is a struct representing the Resource ID for a Library +type LibraryId struct { + SubscriptionId string + ResourceGroupName string + WorkspaceName string + LibraryName string +} + +// NewLibraryID returns a new LibraryId struct +func NewLibraryID(subscriptionId string, resourceGroupName string, workspaceName string, libraryName string) LibraryId { + return LibraryId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + WorkspaceName: workspaceName, + LibraryName: libraryName, + } +} + +// ParseLibraryID parses 'input' into a LibraryId +func ParseLibraryID(input string) (*LibraryId, error) { + parser := resourceids.NewParserFromResourceIdType(&LibraryId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := LibraryId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseLibraryIDInsensitively parses 'input' case-insensitively into a LibraryId +// note: this method should only be used for API response data and not user input +func ParseLibraryIDInsensitively(input string) (*LibraryId, error) { + parser := resourceids.NewParserFromResourceIdType(&LibraryId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := LibraryId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *LibraryId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.WorkspaceName, ok = input.Parsed["workspaceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "workspaceName", input) + } + + if id.LibraryName, ok = input.Parsed["libraryName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "libraryName", input) + } + + return nil +} + +// ValidateLibraryID checks that 'input' can be parsed as a Library ID +func ValidateLibraryID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseLibraryID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Library ID +func (id LibraryId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Synapse/workspaces/%s/libraries/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.WorkspaceName, id.LibraryName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Library ID +func (id LibraryId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftSynapse", "Microsoft.Synapse", "Microsoft.Synapse"), + resourceids.StaticSegment("staticWorkspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceName", "workspaceValue"), + resourceids.StaticSegment("staticLibraries", "libraries", "libraries"), + resourceids.UserSpecifiedSegment("libraryName", "libraryValue"), + } +} + +// String returns a human-readable description of this Library ID +func (id LibraryId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Workspace Name: %q", id.WorkspaceName), + fmt.Sprintf("Library Name: %q", id.LibraryName), + } + return fmt.Sprintf("Library (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/synapse/2021-06-01/libraries/id_library_test.go b/resource-manager/synapse/2021-06-01/libraries/id_library_test.go new file mode 100644 index 00000000000..6fdf0e6be4a --- /dev/null +++ b/resource-manager/synapse/2021-06-01/libraries/id_library_test.go @@ -0,0 +1,327 @@ +package libraries + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &LibraryId{} + +func TestNewLibraryID(t *testing.T) { + id := NewLibraryID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "libraryValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.WorkspaceName != "workspaceValue" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceName'", id.WorkspaceName, "workspaceValue") + } + + if id.LibraryName != "libraryValue" { + t.Fatalf("Expected %q but got %q for Segment 'LibraryName'", id.LibraryName, "libraryValue") + } +} + +func TestFormatLibraryID(t *testing.T) { + actual := NewLibraryID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "libraryValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/libraries/libraryValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseLibraryID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *LibraryId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/libraries", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/libraries/libraryValue", + Expected: &LibraryId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + LibraryName: "libraryValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/libraries/libraryValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseLibraryID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + if actual.LibraryName != v.Expected.LibraryName { + t.Fatalf("Expected %q but got %q for LibraryName", v.Expected.LibraryName, actual.LibraryName) + } + + } +} + +func TestParseLibraryIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *LibraryId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/libraries", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/lIbRaRiEs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/libraries/libraryValue", + Expected: &LibraryId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + LibraryName: "libraryValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/libraries/libraryValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/lIbRaRiEs/lIbRaRyVaLuE", + Expected: &LibraryId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + WorkspaceName: "wOrKsPaCeVaLuE", + LibraryName: "lIbRaRyVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/lIbRaRiEs/lIbRaRyVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseLibraryIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + if actual.LibraryName != v.Expected.LibraryName { + t.Fatalf("Expected %q but got %q for LibraryName", v.Expected.LibraryName, actual.LibraryName) + } + + } +} + +func TestSegmentsForLibraryId(t *testing.T) { + segments := LibraryId{}.Segments() + if len(segments) == 0 { + t.Fatalf("LibraryId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/synapse/2021-06-01/libraries/id_workspace.go b/resource-manager/synapse/2021-06-01/libraries/id_workspace.go new file mode 100644 index 00000000000..659047c03f4 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/libraries/id_workspace.go @@ -0,0 +1,125 @@ +package libraries + +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 = &WorkspaceId{} + +// WorkspaceId is a struct representing the Resource ID for a Workspace +type WorkspaceId struct { + SubscriptionId string + ResourceGroupName string + WorkspaceName string +} + +// NewWorkspaceID returns a new WorkspaceId struct +func NewWorkspaceID(subscriptionId string, resourceGroupName string, workspaceName string) WorkspaceId { + return WorkspaceId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + WorkspaceName: workspaceName, + } +} + +// ParseWorkspaceID parses 'input' into a WorkspaceId +func ParseWorkspaceID(input string) (*WorkspaceId, error) { + parser := resourceids.NewParserFromResourceIdType(&WorkspaceId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := WorkspaceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseWorkspaceIDInsensitively parses 'input' case-insensitively into a WorkspaceId +// note: this method should only be used for API response data and not user input +func ParseWorkspaceIDInsensitively(input string) (*WorkspaceId, error) { + parser := resourceids.NewParserFromResourceIdType(&WorkspaceId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := WorkspaceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *WorkspaceId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.WorkspaceName, ok = input.Parsed["workspaceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "workspaceName", input) + } + + return nil +} + +// ValidateWorkspaceID checks that 'input' can be parsed as a Workspace ID +func ValidateWorkspaceID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseWorkspaceID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Workspace ID +func (id WorkspaceId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Synapse/workspaces/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.WorkspaceName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Workspace ID +func (id WorkspaceId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftSynapse", "Microsoft.Synapse", "Microsoft.Synapse"), + resourceids.StaticSegment("staticWorkspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceName", "workspaceValue"), + } +} + +// String returns a human-readable description of this Workspace ID +func (id WorkspaceId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Workspace Name: %q", id.WorkspaceName), + } + return fmt.Sprintf("Workspace (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/synapse/2021-06-01/libraries/id_workspace_test.go b/resource-manager/synapse/2021-06-01/libraries/id_workspace_test.go new file mode 100644 index 00000000000..4020dd3dbc5 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/libraries/id_workspace_test.go @@ -0,0 +1,282 @@ +package libraries + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &WorkspaceId{} + +func TestNewWorkspaceID(t *testing.T) { + id := NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.WorkspaceName != "workspaceValue" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceName'", id.WorkspaceName, "workspaceValue") + } +} + +func TestFormatWorkspaceID(t *testing.T) { + actual := NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseWorkspaceID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkspaceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue", + Expected: &WorkspaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkspaceID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + } +} + +func TestParseWorkspaceIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkspaceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue", + Expected: &WorkspaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE", + Expected: &WorkspaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + WorkspaceName: "wOrKsPaCeVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkspaceIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + } +} + +func TestSegmentsForWorkspaceId(t *testing.T) { + segments := WorkspaceId{}.Segments() + if len(segments) == 0 { + t.Fatalf("WorkspaceId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/synapse/2021-06-01/libraries/method_libraryget.go b/resource-manager/synapse/2021-06-01/libraries/method_libraryget.go new file mode 100644 index 00000000000..31492806052 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/libraries/method_libraryget.go @@ -0,0 +1,51 @@ +package libraries + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type LibraryGetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *LibraryResource +} + +// LibraryGet ... +func (c LibrariesClient) LibraryGet(ctx context.Context, id LibraryId) (result LibraryGetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/synapse/2021-06-01/libraries/method_listbyworkspace.go b/resource-manager/synapse/2021-06-01/libraries/method_listbyworkspace.go new file mode 100644 index 00000000000..bd0a2ec3f93 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/libraries/method_listbyworkspace.go @@ -0,0 +1,91 @@ +package libraries + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListByWorkspaceOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]LibraryResource +} + +type ListByWorkspaceCompleteResult struct { + LatestHttpResponse *http.Response + Items []LibraryResource +} + +// ListByWorkspace ... +func (c LibrariesClient) ListByWorkspace(ctx context.Context, id WorkspaceId) (result ListByWorkspaceOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/libraries", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]LibraryResource `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByWorkspaceComplete retrieves all the results into a single object +func (c LibrariesClient) ListByWorkspaceComplete(ctx context.Context, id WorkspaceId) (ListByWorkspaceCompleteResult, error) { + return c.ListByWorkspaceCompleteMatchingPredicate(ctx, id, LibraryResourceOperationPredicate{}) +} + +// ListByWorkspaceCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c LibrariesClient) ListByWorkspaceCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, predicate LibraryResourceOperationPredicate) (result ListByWorkspaceCompleteResult, err error) { + items := make([]LibraryResource, 0) + + resp, err := c.ListByWorkspace(ctx, id) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByWorkspaceCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/synapse/2021-06-01/libraries/model_libraryinfo.go b/resource-manager/synapse/2021-06-01/libraries/model_libraryinfo.go new file mode 100644 index 00000000000..1d97c18155c --- /dev/null +++ b/resource-manager/synapse/2021-06-01/libraries/model_libraryinfo.go @@ -0,0 +1,32 @@ +package libraries + +import ( + "time" + + "github.com/hashicorp/go-azure-helpers/lang/dates" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type LibraryInfo struct { + ContainerName *string `json:"containerName,omitempty"` + CreatorId *string `json:"creatorId,omitempty"` + Name *string `json:"name,omitempty"` + Path *string `json:"path,omitempty"` + ProvisioningStatus *string `json:"provisioningStatus,omitempty"` + Type *string `json:"type,omitempty"` + UploadedTimestamp *string `json:"uploadedTimestamp,omitempty"` +} + +func (o *LibraryInfo) GetUploadedTimestampAsTime() (*time.Time, error) { + if o.UploadedTimestamp == nil { + return nil, nil + } + return dates.ParseAsFormat(o.UploadedTimestamp, "2006-01-02T15:04:05Z07:00") +} + +func (o *LibraryInfo) SetUploadedTimestampAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.UploadedTimestamp = &formatted +} diff --git a/resource-manager/synapse/2021-06-01/libraries/model_libraryresource.go b/resource-manager/synapse/2021-06-01/libraries/model_libraryresource.go new file mode 100644 index 00000000000..ef0dc720d03 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/libraries/model_libraryresource.go @@ -0,0 +1,12 @@ +package libraries + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type LibraryResource struct { + Etag *string `json:"etag,omitempty"` + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties LibraryInfo `json:"properties"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/synapse/2021-06-01/libraries/predicates.go b/resource-manager/synapse/2021-06-01/libraries/predicates.go new file mode 100644 index 00000000000..0f9fc07bb02 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/libraries/predicates.go @@ -0,0 +1,32 @@ +package libraries + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type LibraryResourceOperationPredicate struct { + Etag *string + Id *string + Name *string + Type *string +} + +func (p LibraryResourceOperationPredicate) Matches(input LibraryResource) bool { + + if p.Etag != nil && (input.Etag == nil || *p.Etag != *input.Etag) { + return false + } + + if p.Id != nil && (input.Id == nil || *p.Id != *input.Id) { + return false + } + + if p.Name != nil && (input.Name == nil || *p.Name != *input.Name) { + return false + } + + if p.Type != nil && (input.Type == nil || *p.Type != *input.Type) { + return false + } + + return true +} diff --git a/resource-manager/synapse/2021-06-01/libraries/version.go b/resource-manager/synapse/2021-06-01/libraries/version.go new file mode 100644 index 00000000000..b89cd42b093 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/libraries/version.go @@ -0,0 +1,12 @@ +package libraries + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2021-06-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/libraries/%s", defaultApiVersion) +} diff --git a/resource-manager/synapse/2021-06-01/operations/README.md b/resource-manager/synapse/2021-06-01/operations/README.md new file mode 100644 index 00000000000..eb1f0b2af89 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/operations/README.md @@ -0,0 +1,41 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/synapse/2021-06-01/operations` Documentation + +The `operations` SDK allows for interaction with the Azure Resource Manager Service `synapse` (API Version `2021-06-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/synapse/2021-06-01/operations" +``` + + +### Client Initialization + +```go +client := operations.NewOperationsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `OperationsClient.CheckNameAvailability` + +```go +ctx := context.TODO() +id := operations.NewSubscriptionID("12345678-1234-9876-4563-123456789012") + +payload := operations.CheckNameAvailabilityRequest{ + // ... +} + + +read, err := client.CheckNameAvailability(ctx, id, payload) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` diff --git a/resource-manager/synapse/2021-06-01/operations/client.go b/resource-manager/synapse/2021-06-01/operations/client.go new file mode 100644 index 00000000000..304a17c8d48 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/operations/client.go @@ -0,0 +1,26 @@ +package operations + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type OperationsClient struct { + Client *resourcemanager.Client +} + +func NewOperationsClientWithBaseURI(sdkApi sdkEnv.Api) (*OperationsClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "operations", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating OperationsClient: %+v", err) + } + + return &OperationsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/synapse/2021-06-01/operations/method_checknameavailability.go b/resource-manager/synapse/2021-06-01/operations/method_checknameavailability.go new file mode 100644 index 00000000000..ad12dcd0062 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/operations/method_checknameavailability.go @@ -0,0 +1,57 @@ +package operations + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CheckNameAvailabilityOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *CheckNameAvailabilityResponse +} + +// CheckNameAvailability ... +func (c OperationsClient) CheckNameAvailability(ctx context.Context, id commonids.SubscriptionId, input CheckNameAvailabilityRequest) (result CheckNameAvailabilityOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/providers/Microsoft.Synapse/checkNameAvailability", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/synapse/2021-06-01/operations/model_checknameavailabilityrequest.go b/resource-manager/synapse/2021-06-01/operations/model_checknameavailabilityrequest.go new file mode 100644 index 00000000000..536acdcaf12 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/operations/model_checknameavailabilityrequest.go @@ -0,0 +1,9 @@ +package operations + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CheckNameAvailabilityRequest struct { + Name *string `json:"name,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/synapse/2021-06-01/operations/model_checknameavailabilityresponse.go b/resource-manager/synapse/2021-06-01/operations/model_checknameavailabilityresponse.go new file mode 100644 index 00000000000..098625e647b --- /dev/null +++ b/resource-manager/synapse/2021-06-01/operations/model_checknameavailabilityresponse.go @@ -0,0 +1,11 @@ +package operations + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CheckNameAvailabilityResponse struct { + Available *bool `json:"available,omitempty"` + Message *string `json:"message,omitempty"` + Name *string `json:"name,omitempty"` + Reason *string `json:"reason,omitempty"` +} diff --git a/resource-manager/synapse/2021-06-01/operations/version.go b/resource-manager/synapse/2021-06-01/operations/version.go new file mode 100644 index 00000000000..ce0cb6ca13d --- /dev/null +++ b/resource-manager/synapse/2021-06-01/operations/version.go @@ -0,0 +1,12 @@ +package operations + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2021-06-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/operations/%s", defaultApiVersion) +} diff --git a/resource-manager/synapse/2021-06-01/privateendpointconnections/README.md b/resource-manager/synapse/2021-06-01/privateendpointconnections/README.md new file mode 100644 index 00000000000..37e35b1da94 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/privateendpointconnections/README.md @@ -0,0 +1,115 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/synapse/2021-06-01/privateendpointconnections` Documentation + +The `privateendpointconnections` SDK allows for interaction with the Azure Resource Manager Service `synapse` (API Version `2021-06-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/synapse/2021-06-01/privateendpointconnections" +``` + + +### Client Initialization + +```go +client := privateendpointconnections.NewPrivateEndpointConnectionsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `PrivateEndpointConnectionsClient.Create` + +```go +ctx := context.TODO() +id := privateendpointconnections.NewPrivateEndpointConnectionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "privateEndpointConnectionValue") + +payload := privateendpointconnections.PrivateEndpointConnection{ + // ... +} + + +if err := client.CreateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `PrivateEndpointConnectionsClient.Delete` + +```go +ctx := context.TODO() +id := privateendpointconnections.NewPrivateEndpointConnectionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "privateEndpointConnectionValue") + +if err := client.DeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `PrivateEndpointConnectionsClient.Get` + +```go +ctx := context.TODO() +id := privateendpointconnections.NewPrivateEndpointConnectionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "privateEndpointConnectionValue") + +read, err := client.Get(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `PrivateEndpointConnectionsClient.List` + +```go +ctx := context.TODO() +id := privateendpointconnections.NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue") + +// alternatively `client.List(ctx, id)` can be used to do batched pagination +items, err := client.ListComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `PrivateEndpointConnectionsClient.PrivateLinkHubGet` + +```go +ctx := context.TODO() +id := privateendpointconnections.NewPrivateLinkHubPrivateEndpointConnectionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "privateLinkHubValue", "privateEndpointConnectionValue") + +read, err := client.PrivateLinkHubGet(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `PrivateEndpointConnectionsClient.PrivateLinkHubList` + +```go +ctx := context.TODO() +id := privateendpointconnections.NewPrivateLinkHubID("12345678-1234-9876-4563-123456789012", "example-resource-group", "privateLinkHubValue") + +// alternatively `client.PrivateLinkHubList(ctx, id)` can be used to do batched pagination +items, err := client.PrivateLinkHubListComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/synapse/2021-06-01/privateendpointconnections/client.go b/resource-manager/synapse/2021-06-01/privateendpointconnections/client.go new file mode 100644 index 00000000000..3bf7a6afe1f --- /dev/null +++ b/resource-manager/synapse/2021-06-01/privateendpointconnections/client.go @@ -0,0 +1,26 @@ +package privateendpointconnections + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateEndpointConnectionsClient struct { + Client *resourcemanager.Client +} + +func NewPrivateEndpointConnectionsClientWithBaseURI(sdkApi sdkEnv.Api) (*PrivateEndpointConnectionsClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "privateendpointconnections", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating PrivateEndpointConnectionsClient: %+v", err) + } + + return &PrivateEndpointConnectionsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/synapse/2021-06-01/privateendpointconnections/constants.go b/resource-manager/synapse/2021-06-01/privateendpointconnections/constants.go new file mode 100644 index 00000000000..c07a0a9e014 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/privateendpointconnections/constants.go @@ -0,0 +1,57 @@ +package privateendpointconnections + +import ( + "encoding/json" + "fmt" + "strings" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type OperationStatus string + +const ( + OperationStatusCanceled OperationStatus = "Canceled" + OperationStatusFailed OperationStatus = "Failed" + OperationStatusInProgress OperationStatus = "InProgress" + OperationStatusSucceeded OperationStatus = "Succeeded" +) + +func PossibleValuesForOperationStatus() []string { + return []string{ + string(OperationStatusCanceled), + string(OperationStatusFailed), + string(OperationStatusInProgress), + string(OperationStatusSucceeded), + } +} + +func (s *OperationStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseOperationStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseOperationStatus(input string) (*OperationStatus, error) { + vals := map[string]OperationStatus{ + "canceled": OperationStatusCanceled, + "failed": OperationStatusFailed, + "inprogress": OperationStatusInProgress, + "succeeded": OperationStatusSucceeded, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := OperationStatus(input) + return &out, nil +} diff --git a/resource-manager/synapse/2021-06-01/privateendpointconnections/id_privateendpointconnection.go b/resource-manager/synapse/2021-06-01/privateendpointconnections/id_privateendpointconnection.go new file mode 100644 index 00000000000..33bcd7293ab --- /dev/null +++ b/resource-manager/synapse/2021-06-01/privateendpointconnections/id_privateendpointconnection.go @@ -0,0 +1,134 @@ +package privateendpointconnections + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &PrivateEndpointConnectionId{} + +// PrivateEndpointConnectionId is a struct representing the Resource ID for a Private Endpoint Connection +type PrivateEndpointConnectionId struct { + SubscriptionId string + ResourceGroupName string + WorkspaceName string + PrivateEndpointConnectionName string +} + +// NewPrivateEndpointConnectionID returns a new PrivateEndpointConnectionId struct +func NewPrivateEndpointConnectionID(subscriptionId string, resourceGroupName string, workspaceName string, privateEndpointConnectionName string) PrivateEndpointConnectionId { + return PrivateEndpointConnectionId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + WorkspaceName: workspaceName, + PrivateEndpointConnectionName: privateEndpointConnectionName, + } +} + +// ParsePrivateEndpointConnectionID parses 'input' into a PrivateEndpointConnectionId +func ParsePrivateEndpointConnectionID(input string) (*PrivateEndpointConnectionId, error) { + parser := resourceids.NewParserFromResourceIdType(&PrivateEndpointConnectionId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := PrivateEndpointConnectionId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParsePrivateEndpointConnectionIDInsensitively parses 'input' case-insensitively into a PrivateEndpointConnectionId +// note: this method should only be used for API response data and not user input +func ParsePrivateEndpointConnectionIDInsensitively(input string) (*PrivateEndpointConnectionId, error) { + parser := resourceids.NewParserFromResourceIdType(&PrivateEndpointConnectionId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := PrivateEndpointConnectionId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *PrivateEndpointConnectionId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.WorkspaceName, ok = input.Parsed["workspaceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "workspaceName", input) + } + + if id.PrivateEndpointConnectionName, ok = input.Parsed["privateEndpointConnectionName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "privateEndpointConnectionName", input) + } + + return nil +} + +// ValidatePrivateEndpointConnectionID checks that 'input' can be parsed as a Private Endpoint Connection ID +func ValidatePrivateEndpointConnectionID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParsePrivateEndpointConnectionID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Private Endpoint Connection ID +func (id PrivateEndpointConnectionId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Synapse/workspaces/%s/privateEndpointConnections/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.WorkspaceName, id.PrivateEndpointConnectionName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Private Endpoint Connection ID +func (id PrivateEndpointConnectionId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftSynapse", "Microsoft.Synapse", "Microsoft.Synapse"), + resourceids.StaticSegment("staticWorkspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceName", "workspaceValue"), + resourceids.StaticSegment("staticPrivateEndpointConnections", "privateEndpointConnections", "privateEndpointConnections"), + resourceids.UserSpecifiedSegment("privateEndpointConnectionName", "privateEndpointConnectionValue"), + } +} + +// String returns a human-readable description of this Private Endpoint Connection ID +func (id PrivateEndpointConnectionId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Workspace Name: %q", id.WorkspaceName), + fmt.Sprintf("Private Endpoint Connection Name: %q", id.PrivateEndpointConnectionName), + } + return fmt.Sprintf("Private Endpoint Connection (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/synapse/2021-06-01/privateendpointconnections/id_privateendpointconnection_test.go b/resource-manager/synapse/2021-06-01/privateendpointconnections/id_privateendpointconnection_test.go new file mode 100644 index 00000000000..e250c83f777 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/privateendpointconnections/id_privateendpointconnection_test.go @@ -0,0 +1,327 @@ +package privateendpointconnections + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &PrivateEndpointConnectionId{} + +func TestNewPrivateEndpointConnectionID(t *testing.T) { + id := NewPrivateEndpointConnectionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "privateEndpointConnectionValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.WorkspaceName != "workspaceValue" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceName'", id.WorkspaceName, "workspaceValue") + } + + if id.PrivateEndpointConnectionName != "privateEndpointConnectionValue" { + t.Fatalf("Expected %q but got %q for Segment 'PrivateEndpointConnectionName'", id.PrivateEndpointConnectionName, "privateEndpointConnectionValue") + } +} + +func TestFormatPrivateEndpointConnectionID(t *testing.T) { + actual := NewPrivateEndpointConnectionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "privateEndpointConnectionValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/privateEndpointConnections/privateEndpointConnectionValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParsePrivateEndpointConnectionID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *PrivateEndpointConnectionId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/privateEndpointConnections", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/privateEndpointConnections/privateEndpointConnectionValue", + Expected: &PrivateEndpointConnectionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + PrivateEndpointConnectionName: "privateEndpointConnectionValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/privateEndpointConnections/privateEndpointConnectionValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParsePrivateEndpointConnectionID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + if actual.PrivateEndpointConnectionName != v.Expected.PrivateEndpointConnectionName { + t.Fatalf("Expected %q but got %q for PrivateEndpointConnectionName", v.Expected.PrivateEndpointConnectionName, actual.PrivateEndpointConnectionName) + } + + } +} + +func TestParsePrivateEndpointConnectionIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *PrivateEndpointConnectionId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/privateEndpointConnections", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/pRiVaTeEnDpOiNtCoNnEcTiOnS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/privateEndpointConnections/privateEndpointConnectionValue", + Expected: &PrivateEndpointConnectionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + PrivateEndpointConnectionName: "privateEndpointConnectionValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/privateEndpointConnections/privateEndpointConnectionValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/pRiVaTeEnDpOiNtCoNnEcTiOnS/pRiVaTeEnDpOiNtCoNnEcTiOnVaLuE", + Expected: &PrivateEndpointConnectionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + WorkspaceName: "wOrKsPaCeVaLuE", + PrivateEndpointConnectionName: "pRiVaTeEnDpOiNtCoNnEcTiOnVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/pRiVaTeEnDpOiNtCoNnEcTiOnS/pRiVaTeEnDpOiNtCoNnEcTiOnVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParsePrivateEndpointConnectionIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + if actual.PrivateEndpointConnectionName != v.Expected.PrivateEndpointConnectionName { + t.Fatalf("Expected %q but got %q for PrivateEndpointConnectionName", v.Expected.PrivateEndpointConnectionName, actual.PrivateEndpointConnectionName) + } + + } +} + +func TestSegmentsForPrivateEndpointConnectionId(t *testing.T) { + segments := PrivateEndpointConnectionId{}.Segments() + if len(segments) == 0 { + t.Fatalf("PrivateEndpointConnectionId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/synapse/2021-06-01/privateendpointconnections/id_privatelinkhub.go b/resource-manager/synapse/2021-06-01/privateendpointconnections/id_privatelinkhub.go new file mode 100644 index 00000000000..d6203f6d936 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/privateendpointconnections/id_privatelinkhub.go @@ -0,0 +1,125 @@ +package privateendpointconnections + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &PrivateLinkHubId{} + +// PrivateLinkHubId is a struct representing the Resource ID for a Private Link Hub +type PrivateLinkHubId struct { + SubscriptionId string + ResourceGroupName string + PrivateLinkHubName string +} + +// NewPrivateLinkHubID returns a new PrivateLinkHubId struct +func NewPrivateLinkHubID(subscriptionId string, resourceGroupName string, privateLinkHubName string) PrivateLinkHubId { + return PrivateLinkHubId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + PrivateLinkHubName: privateLinkHubName, + } +} + +// ParsePrivateLinkHubID parses 'input' into a PrivateLinkHubId +func ParsePrivateLinkHubID(input string) (*PrivateLinkHubId, error) { + parser := resourceids.NewParserFromResourceIdType(&PrivateLinkHubId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := PrivateLinkHubId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParsePrivateLinkHubIDInsensitively parses 'input' case-insensitively into a PrivateLinkHubId +// note: this method should only be used for API response data and not user input +func ParsePrivateLinkHubIDInsensitively(input string) (*PrivateLinkHubId, error) { + parser := resourceids.NewParserFromResourceIdType(&PrivateLinkHubId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := PrivateLinkHubId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *PrivateLinkHubId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.PrivateLinkHubName, ok = input.Parsed["privateLinkHubName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "privateLinkHubName", input) + } + + return nil +} + +// ValidatePrivateLinkHubID checks that 'input' can be parsed as a Private Link Hub ID +func ValidatePrivateLinkHubID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParsePrivateLinkHubID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Private Link Hub ID +func (id PrivateLinkHubId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Synapse/privateLinkHubs/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.PrivateLinkHubName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Private Link Hub ID +func (id PrivateLinkHubId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftSynapse", "Microsoft.Synapse", "Microsoft.Synapse"), + resourceids.StaticSegment("staticPrivateLinkHubs", "privateLinkHubs", "privateLinkHubs"), + resourceids.UserSpecifiedSegment("privateLinkHubName", "privateLinkHubValue"), + } +} + +// String returns a human-readable description of this Private Link Hub ID +func (id PrivateLinkHubId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Private Link Hub Name: %q", id.PrivateLinkHubName), + } + return fmt.Sprintf("Private Link Hub (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/synapse/2021-06-01/privateendpointconnections/id_privatelinkhub_test.go b/resource-manager/synapse/2021-06-01/privateendpointconnections/id_privatelinkhub_test.go new file mode 100644 index 00000000000..cbbd3ce803d --- /dev/null +++ b/resource-manager/synapse/2021-06-01/privateendpointconnections/id_privatelinkhub_test.go @@ -0,0 +1,282 @@ +package privateendpointconnections + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &PrivateLinkHubId{} + +func TestNewPrivateLinkHubID(t *testing.T) { + id := NewPrivateLinkHubID("12345678-1234-9876-4563-123456789012", "example-resource-group", "privateLinkHubValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.PrivateLinkHubName != "privateLinkHubValue" { + t.Fatalf("Expected %q but got %q for Segment 'PrivateLinkHubName'", id.PrivateLinkHubName, "privateLinkHubValue") + } +} + +func TestFormatPrivateLinkHubID(t *testing.T) { + actual := NewPrivateLinkHubID("12345678-1234-9876-4563-123456789012", "example-resource-group", "privateLinkHubValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/privateLinkHubs/privateLinkHubValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParsePrivateLinkHubID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *PrivateLinkHubId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/privateLinkHubs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/privateLinkHubs/privateLinkHubValue", + Expected: &PrivateLinkHubId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + PrivateLinkHubName: "privateLinkHubValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/privateLinkHubs/privateLinkHubValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParsePrivateLinkHubID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.PrivateLinkHubName != v.Expected.PrivateLinkHubName { + t.Fatalf("Expected %q but got %q for PrivateLinkHubName", v.Expected.PrivateLinkHubName, actual.PrivateLinkHubName) + } + + } +} + +func TestParsePrivateLinkHubIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *PrivateLinkHubId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/privateLinkHubs", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/pRiVaTeLiNkHuBs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/privateLinkHubs/privateLinkHubValue", + Expected: &PrivateLinkHubId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + PrivateLinkHubName: "privateLinkHubValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/privateLinkHubs/privateLinkHubValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/pRiVaTeLiNkHuBs/pRiVaTeLiNkHuBvAlUe", + Expected: &PrivateLinkHubId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + PrivateLinkHubName: "pRiVaTeLiNkHuBvAlUe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/pRiVaTeLiNkHuBs/pRiVaTeLiNkHuBvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParsePrivateLinkHubIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.PrivateLinkHubName != v.Expected.PrivateLinkHubName { + t.Fatalf("Expected %q but got %q for PrivateLinkHubName", v.Expected.PrivateLinkHubName, actual.PrivateLinkHubName) + } + + } +} + +func TestSegmentsForPrivateLinkHubId(t *testing.T) { + segments := PrivateLinkHubId{}.Segments() + if len(segments) == 0 { + t.Fatalf("PrivateLinkHubId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/synapse/2021-06-01/privateendpointconnections/id_privatelinkhubprivateendpointconnection.go b/resource-manager/synapse/2021-06-01/privateendpointconnections/id_privatelinkhubprivateendpointconnection.go new file mode 100644 index 00000000000..c95c59c17f4 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/privateendpointconnections/id_privatelinkhubprivateendpointconnection.go @@ -0,0 +1,134 @@ +package privateendpointconnections + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &PrivateLinkHubPrivateEndpointConnectionId{} + +// PrivateLinkHubPrivateEndpointConnectionId is a struct representing the Resource ID for a Private Link Hub Private Endpoint Connection +type PrivateLinkHubPrivateEndpointConnectionId struct { + SubscriptionId string + ResourceGroupName string + PrivateLinkHubName string + PrivateEndpointConnectionName string +} + +// NewPrivateLinkHubPrivateEndpointConnectionID returns a new PrivateLinkHubPrivateEndpointConnectionId struct +func NewPrivateLinkHubPrivateEndpointConnectionID(subscriptionId string, resourceGroupName string, privateLinkHubName string, privateEndpointConnectionName string) PrivateLinkHubPrivateEndpointConnectionId { + return PrivateLinkHubPrivateEndpointConnectionId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + PrivateLinkHubName: privateLinkHubName, + PrivateEndpointConnectionName: privateEndpointConnectionName, + } +} + +// ParsePrivateLinkHubPrivateEndpointConnectionID parses 'input' into a PrivateLinkHubPrivateEndpointConnectionId +func ParsePrivateLinkHubPrivateEndpointConnectionID(input string) (*PrivateLinkHubPrivateEndpointConnectionId, error) { + parser := resourceids.NewParserFromResourceIdType(&PrivateLinkHubPrivateEndpointConnectionId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := PrivateLinkHubPrivateEndpointConnectionId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParsePrivateLinkHubPrivateEndpointConnectionIDInsensitively parses 'input' case-insensitively into a PrivateLinkHubPrivateEndpointConnectionId +// note: this method should only be used for API response data and not user input +func ParsePrivateLinkHubPrivateEndpointConnectionIDInsensitively(input string) (*PrivateLinkHubPrivateEndpointConnectionId, error) { + parser := resourceids.NewParserFromResourceIdType(&PrivateLinkHubPrivateEndpointConnectionId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := PrivateLinkHubPrivateEndpointConnectionId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *PrivateLinkHubPrivateEndpointConnectionId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.PrivateLinkHubName, ok = input.Parsed["privateLinkHubName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "privateLinkHubName", input) + } + + if id.PrivateEndpointConnectionName, ok = input.Parsed["privateEndpointConnectionName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "privateEndpointConnectionName", input) + } + + return nil +} + +// ValidatePrivateLinkHubPrivateEndpointConnectionID checks that 'input' can be parsed as a Private Link Hub Private Endpoint Connection ID +func ValidatePrivateLinkHubPrivateEndpointConnectionID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParsePrivateLinkHubPrivateEndpointConnectionID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Private Link Hub Private Endpoint Connection ID +func (id PrivateLinkHubPrivateEndpointConnectionId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Synapse/privateLinkHubs/%s/privateEndpointConnections/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.PrivateLinkHubName, id.PrivateEndpointConnectionName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Private Link Hub Private Endpoint Connection ID +func (id PrivateLinkHubPrivateEndpointConnectionId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftSynapse", "Microsoft.Synapse", "Microsoft.Synapse"), + resourceids.StaticSegment("staticPrivateLinkHubs", "privateLinkHubs", "privateLinkHubs"), + resourceids.UserSpecifiedSegment("privateLinkHubName", "privateLinkHubValue"), + resourceids.StaticSegment("staticPrivateEndpointConnections", "privateEndpointConnections", "privateEndpointConnections"), + resourceids.UserSpecifiedSegment("privateEndpointConnectionName", "privateEndpointConnectionValue"), + } +} + +// String returns a human-readable description of this Private Link Hub Private Endpoint Connection ID +func (id PrivateLinkHubPrivateEndpointConnectionId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Private Link Hub Name: %q", id.PrivateLinkHubName), + fmt.Sprintf("Private Endpoint Connection Name: %q", id.PrivateEndpointConnectionName), + } + return fmt.Sprintf("Private Link Hub Private Endpoint Connection (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/synapse/2021-06-01/privateendpointconnections/id_privatelinkhubprivateendpointconnection_test.go b/resource-manager/synapse/2021-06-01/privateendpointconnections/id_privatelinkhubprivateendpointconnection_test.go new file mode 100644 index 00000000000..2c30a0b9dc3 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/privateendpointconnections/id_privatelinkhubprivateendpointconnection_test.go @@ -0,0 +1,327 @@ +package privateendpointconnections + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &PrivateLinkHubPrivateEndpointConnectionId{} + +func TestNewPrivateLinkHubPrivateEndpointConnectionID(t *testing.T) { + id := NewPrivateLinkHubPrivateEndpointConnectionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "privateLinkHubValue", "privateEndpointConnectionValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.PrivateLinkHubName != "privateLinkHubValue" { + t.Fatalf("Expected %q but got %q for Segment 'PrivateLinkHubName'", id.PrivateLinkHubName, "privateLinkHubValue") + } + + if id.PrivateEndpointConnectionName != "privateEndpointConnectionValue" { + t.Fatalf("Expected %q but got %q for Segment 'PrivateEndpointConnectionName'", id.PrivateEndpointConnectionName, "privateEndpointConnectionValue") + } +} + +func TestFormatPrivateLinkHubPrivateEndpointConnectionID(t *testing.T) { + actual := NewPrivateLinkHubPrivateEndpointConnectionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "privateLinkHubValue", "privateEndpointConnectionValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/privateLinkHubs/privateLinkHubValue/privateEndpointConnections/privateEndpointConnectionValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParsePrivateLinkHubPrivateEndpointConnectionID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *PrivateLinkHubPrivateEndpointConnectionId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/privateLinkHubs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/privateLinkHubs/privateLinkHubValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/privateLinkHubs/privateLinkHubValue/privateEndpointConnections", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/privateLinkHubs/privateLinkHubValue/privateEndpointConnections/privateEndpointConnectionValue", + Expected: &PrivateLinkHubPrivateEndpointConnectionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + PrivateLinkHubName: "privateLinkHubValue", + PrivateEndpointConnectionName: "privateEndpointConnectionValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/privateLinkHubs/privateLinkHubValue/privateEndpointConnections/privateEndpointConnectionValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParsePrivateLinkHubPrivateEndpointConnectionID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.PrivateLinkHubName != v.Expected.PrivateLinkHubName { + t.Fatalf("Expected %q but got %q for PrivateLinkHubName", v.Expected.PrivateLinkHubName, actual.PrivateLinkHubName) + } + + if actual.PrivateEndpointConnectionName != v.Expected.PrivateEndpointConnectionName { + t.Fatalf("Expected %q but got %q for PrivateEndpointConnectionName", v.Expected.PrivateEndpointConnectionName, actual.PrivateEndpointConnectionName) + } + + } +} + +func TestParsePrivateLinkHubPrivateEndpointConnectionIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *PrivateLinkHubPrivateEndpointConnectionId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/privateLinkHubs", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/pRiVaTeLiNkHuBs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/privateLinkHubs/privateLinkHubValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/pRiVaTeLiNkHuBs/pRiVaTeLiNkHuBvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/privateLinkHubs/privateLinkHubValue/privateEndpointConnections", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/pRiVaTeLiNkHuBs/pRiVaTeLiNkHuBvAlUe/pRiVaTeEnDpOiNtCoNnEcTiOnS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/privateLinkHubs/privateLinkHubValue/privateEndpointConnections/privateEndpointConnectionValue", + Expected: &PrivateLinkHubPrivateEndpointConnectionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + PrivateLinkHubName: "privateLinkHubValue", + PrivateEndpointConnectionName: "privateEndpointConnectionValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/privateLinkHubs/privateLinkHubValue/privateEndpointConnections/privateEndpointConnectionValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/pRiVaTeLiNkHuBs/pRiVaTeLiNkHuBvAlUe/pRiVaTeEnDpOiNtCoNnEcTiOnS/pRiVaTeEnDpOiNtCoNnEcTiOnVaLuE", + Expected: &PrivateLinkHubPrivateEndpointConnectionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + PrivateLinkHubName: "pRiVaTeLiNkHuBvAlUe", + PrivateEndpointConnectionName: "pRiVaTeEnDpOiNtCoNnEcTiOnVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/pRiVaTeLiNkHuBs/pRiVaTeLiNkHuBvAlUe/pRiVaTeEnDpOiNtCoNnEcTiOnS/pRiVaTeEnDpOiNtCoNnEcTiOnVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParsePrivateLinkHubPrivateEndpointConnectionIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.PrivateLinkHubName != v.Expected.PrivateLinkHubName { + t.Fatalf("Expected %q but got %q for PrivateLinkHubName", v.Expected.PrivateLinkHubName, actual.PrivateLinkHubName) + } + + if actual.PrivateEndpointConnectionName != v.Expected.PrivateEndpointConnectionName { + t.Fatalf("Expected %q but got %q for PrivateEndpointConnectionName", v.Expected.PrivateEndpointConnectionName, actual.PrivateEndpointConnectionName) + } + + } +} + +func TestSegmentsForPrivateLinkHubPrivateEndpointConnectionId(t *testing.T) { + segments := PrivateLinkHubPrivateEndpointConnectionId{}.Segments() + if len(segments) == 0 { + t.Fatalf("PrivateLinkHubPrivateEndpointConnectionId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/synapse/2021-06-01/privateendpointconnections/id_workspace.go b/resource-manager/synapse/2021-06-01/privateendpointconnections/id_workspace.go new file mode 100644 index 00000000000..43ffe165290 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/privateendpointconnections/id_workspace.go @@ -0,0 +1,125 @@ +package privateendpointconnections + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &WorkspaceId{} + +// WorkspaceId is a struct representing the Resource ID for a Workspace +type WorkspaceId struct { + SubscriptionId string + ResourceGroupName string + WorkspaceName string +} + +// NewWorkspaceID returns a new WorkspaceId struct +func NewWorkspaceID(subscriptionId string, resourceGroupName string, workspaceName string) WorkspaceId { + return WorkspaceId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + WorkspaceName: workspaceName, + } +} + +// ParseWorkspaceID parses 'input' into a WorkspaceId +func ParseWorkspaceID(input string) (*WorkspaceId, error) { + parser := resourceids.NewParserFromResourceIdType(&WorkspaceId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := WorkspaceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseWorkspaceIDInsensitively parses 'input' case-insensitively into a WorkspaceId +// note: this method should only be used for API response data and not user input +func ParseWorkspaceIDInsensitively(input string) (*WorkspaceId, error) { + parser := resourceids.NewParserFromResourceIdType(&WorkspaceId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := WorkspaceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *WorkspaceId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.WorkspaceName, ok = input.Parsed["workspaceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "workspaceName", input) + } + + return nil +} + +// ValidateWorkspaceID checks that 'input' can be parsed as a Workspace ID +func ValidateWorkspaceID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseWorkspaceID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Workspace ID +func (id WorkspaceId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Synapse/workspaces/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.WorkspaceName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Workspace ID +func (id WorkspaceId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftSynapse", "Microsoft.Synapse", "Microsoft.Synapse"), + resourceids.StaticSegment("staticWorkspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceName", "workspaceValue"), + } +} + +// String returns a human-readable description of this Workspace ID +func (id WorkspaceId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Workspace Name: %q", id.WorkspaceName), + } + return fmt.Sprintf("Workspace (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/synapse/2021-06-01/privateendpointconnections/id_workspace_test.go b/resource-manager/synapse/2021-06-01/privateendpointconnections/id_workspace_test.go new file mode 100644 index 00000000000..45f894b5ab9 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/privateendpointconnections/id_workspace_test.go @@ -0,0 +1,282 @@ +package privateendpointconnections + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &WorkspaceId{} + +func TestNewWorkspaceID(t *testing.T) { + id := NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.WorkspaceName != "workspaceValue" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceName'", id.WorkspaceName, "workspaceValue") + } +} + +func TestFormatWorkspaceID(t *testing.T) { + actual := NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseWorkspaceID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkspaceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue", + Expected: &WorkspaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkspaceID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + } +} + +func TestParseWorkspaceIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkspaceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue", + Expected: &WorkspaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE", + Expected: &WorkspaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + WorkspaceName: "wOrKsPaCeVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkspaceIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + } +} + +func TestSegmentsForWorkspaceId(t *testing.T) { + segments := WorkspaceId{}.Segments() + if len(segments) == 0 { + t.Fatalf("WorkspaceId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/synapse/2021-06-01/privateendpointconnections/method_create.go b/resource-manager/synapse/2021-06-01/privateendpointconnections/method_create.go new file mode 100644 index 00000000000..c558cc72f69 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/privateendpointconnections/method_create.go @@ -0,0 +1,75 @@ +package privateendpointconnections + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *PrivateEndpointConnection +} + +// Create ... +func (c PrivateEndpointConnectionsClient) Create(ctx context.Context, id PrivateEndpointConnectionId, input PrivateEndpointConnection) (result CreateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// CreateThenPoll performs Create then polls until it's completed +func (c PrivateEndpointConnectionsClient) CreateThenPoll(ctx context.Context, id PrivateEndpointConnectionId, input PrivateEndpointConnection) error { + result, err := c.Create(ctx, id, input) + if err != nil { + return fmt.Errorf("performing Create: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after Create: %+v", err) + } + + return nil +} diff --git a/resource-manager/synapse/2021-06-01/privateendpointconnections/method_delete.go b/resource-manager/synapse/2021-06-01/privateendpointconnections/method_delete.go new file mode 100644 index 00000000000..1315bf3a11d --- /dev/null +++ b/resource-manager/synapse/2021-06-01/privateendpointconnections/method_delete.go @@ -0,0 +1,72 @@ +package privateendpointconnections + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *OperationResource +} + +// Delete ... +func (c PrivateEndpointConnectionsClient) Delete(ctx context.Context, id PrivateEndpointConnectionId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// DeleteThenPoll performs Delete then polls until it's completed +func (c PrivateEndpointConnectionsClient) DeleteThenPoll(ctx context.Context, id PrivateEndpointConnectionId) error { + result, err := c.Delete(ctx, id) + if err != nil { + return fmt.Errorf("performing Delete: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after Delete: %+v", err) + } + + return nil +} diff --git a/resource-manager/synapse/2021-06-01/privateendpointconnections/method_get.go b/resource-manager/synapse/2021-06-01/privateendpointconnections/method_get.go new file mode 100644 index 00000000000..6aeba2f77f9 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/privateendpointconnections/method_get.go @@ -0,0 +1,51 @@ +package privateendpointconnections + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *PrivateEndpointConnection +} + +// Get ... +func (c PrivateEndpointConnectionsClient) Get(ctx context.Context, id PrivateEndpointConnectionId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/synapse/2021-06-01/privateendpointconnections/method_list.go b/resource-manager/synapse/2021-06-01/privateendpointconnections/method_list.go new file mode 100644 index 00000000000..2ccb8a8ab19 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/privateendpointconnections/method_list.go @@ -0,0 +1,91 @@ +package privateendpointconnections + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]PrivateEndpointConnection +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []PrivateEndpointConnection +} + +// List ... +func (c PrivateEndpointConnectionsClient) List(ctx context.Context, id WorkspaceId) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/privateEndpointConnections", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]PrivateEndpointConnection `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListComplete retrieves all the results into a single object +func (c PrivateEndpointConnectionsClient) ListComplete(ctx context.Context, id WorkspaceId) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, PrivateEndpointConnectionOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c PrivateEndpointConnectionsClient) ListCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, predicate PrivateEndpointConnectionOperationPredicate) (result ListCompleteResult, err error) { + items := make([]PrivateEndpointConnection, 0) + + resp, err := c.List(ctx, id) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/synapse/2021-06-01/privateendpointconnections/method_privatelinkhubget.go b/resource-manager/synapse/2021-06-01/privateendpointconnections/method_privatelinkhubget.go new file mode 100644 index 00000000000..f821a25c39c --- /dev/null +++ b/resource-manager/synapse/2021-06-01/privateendpointconnections/method_privatelinkhubget.go @@ -0,0 +1,51 @@ +package privateendpointconnections + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateLinkHubGetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *PrivateEndpointConnectionForPrivateLinkHub +} + +// PrivateLinkHubGet ... +func (c PrivateEndpointConnectionsClient) PrivateLinkHubGet(ctx context.Context, id PrivateLinkHubPrivateEndpointConnectionId) (result PrivateLinkHubGetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/synapse/2021-06-01/privateendpointconnections/method_privatelinkhublist.go b/resource-manager/synapse/2021-06-01/privateendpointconnections/method_privatelinkhublist.go new file mode 100644 index 00000000000..4ad4ed86909 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/privateendpointconnections/method_privatelinkhublist.go @@ -0,0 +1,91 @@ +package privateendpointconnections + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateLinkHubListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]PrivateEndpointConnectionForPrivateLinkHub +} + +type PrivateLinkHubListCompleteResult struct { + LatestHttpResponse *http.Response + Items []PrivateEndpointConnectionForPrivateLinkHub +} + +// PrivateLinkHubList ... +func (c PrivateEndpointConnectionsClient) PrivateLinkHubList(ctx context.Context, id PrivateLinkHubId) (result PrivateLinkHubListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/privateEndpointConnections", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]PrivateEndpointConnectionForPrivateLinkHub `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// PrivateLinkHubListComplete retrieves all the results into a single object +func (c PrivateEndpointConnectionsClient) PrivateLinkHubListComplete(ctx context.Context, id PrivateLinkHubId) (PrivateLinkHubListCompleteResult, error) { + return c.PrivateLinkHubListCompleteMatchingPredicate(ctx, id, PrivateEndpointConnectionForPrivateLinkHubOperationPredicate{}) +} + +// PrivateLinkHubListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c PrivateEndpointConnectionsClient) PrivateLinkHubListCompleteMatchingPredicate(ctx context.Context, id PrivateLinkHubId, predicate PrivateEndpointConnectionForPrivateLinkHubOperationPredicate) (result PrivateLinkHubListCompleteResult, err error) { + items := make([]PrivateEndpointConnectionForPrivateLinkHub, 0) + + resp, err := c.PrivateLinkHubList(ctx, id) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = PrivateLinkHubListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/synapse/2021-06-01/privateendpointconnections/model_erroradditionalinfo.go b/resource-manager/synapse/2021-06-01/privateendpointconnections/model_erroradditionalinfo.go new file mode 100644 index 00000000000..57c1caef3ea --- /dev/null +++ b/resource-manager/synapse/2021-06-01/privateendpointconnections/model_erroradditionalinfo.go @@ -0,0 +1,9 @@ +package privateendpointconnections + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ErrorAdditionalInfo struct { + Info *interface{} `json:"info,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/synapse/2021-06-01/privateendpointconnections/model_errordetail.go b/resource-manager/synapse/2021-06-01/privateendpointconnections/model_errordetail.go new file mode 100644 index 00000000000..85828578b9e --- /dev/null +++ b/resource-manager/synapse/2021-06-01/privateendpointconnections/model_errordetail.go @@ -0,0 +1,12 @@ +package privateendpointconnections + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ErrorDetail struct { + AdditionalInfo *[]ErrorAdditionalInfo `json:"additionalInfo,omitempty"` + Code *string `json:"code,omitempty"` + Details *[]ErrorDetail `json:"details,omitempty"` + Message *string `json:"message,omitempty"` + Target *string `json:"target,omitempty"` +} diff --git a/resource-manager/synapse/2021-06-01/privateendpointconnections/model_operationresource.go b/resource-manager/synapse/2021-06-01/privateendpointconnections/model_operationresource.go new file mode 100644 index 00000000000..3d8cb948e64 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/privateendpointconnections/model_operationresource.go @@ -0,0 +1,45 @@ +package privateendpointconnections + +import ( + "time" + + "github.com/hashicorp/go-azure-helpers/lang/dates" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type OperationResource struct { + EndTime *string `json:"endTime,omitempty"` + Error *ErrorDetail `json:"error,omitempty"` + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + PercentComplete *float64 `json:"percentComplete,omitempty"` + Properties *interface{} `json:"properties,omitempty"` + StartTime *string `json:"startTime,omitempty"` + Status *OperationStatus `json:"status,omitempty"` +} + +func (o *OperationResource) GetEndTimeAsTime() (*time.Time, error) { + if o.EndTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.EndTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *OperationResource) SetEndTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.EndTime = &formatted +} + +func (o *OperationResource) GetStartTimeAsTime() (*time.Time, error) { + if o.StartTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.StartTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *OperationResource) SetStartTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.StartTime = &formatted +} diff --git a/resource-manager/synapse/2021-06-01/privateendpointconnections/model_privateendpoint.go b/resource-manager/synapse/2021-06-01/privateendpointconnections/model_privateendpoint.go new file mode 100644 index 00000000000..1bc8cf2a97c --- /dev/null +++ b/resource-manager/synapse/2021-06-01/privateendpointconnections/model_privateendpoint.go @@ -0,0 +1,8 @@ +package privateendpointconnections + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateEndpoint struct { + Id *string `json:"id,omitempty"` +} diff --git a/resource-manager/synapse/2021-06-01/privateendpointconnections/model_privateendpointconnection.go b/resource-manager/synapse/2021-06-01/privateendpointconnections/model_privateendpointconnection.go new file mode 100644 index 00000000000..fde7f4db0fc --- /dev/null +++ b/resource-manager/synapse/2021-06-01/privateendpointconnections/model_privateendpointconnection.go @@ -0,0 +1,11 @@ +package privateendpointconnections + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateEndpointConnection struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *PrivateEndpointConnectionProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/synapse/2021-06-01/privateendpointconnections/model_privateendpointconnectionforprivatelinkhub.go b/resource-manager/synapse/2021-06-01/privateendpointconnections/model_privateendpointconnectionforprivatelinkhub.go new file mode 100644 index 00000000000..5205fcbeee8 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/privateendpointconnections/model_privateendpointconnectionforprivatelinkhub.go @@ -0,0 +1,11 @@ +package privateendpointconnections + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateEndpointConnectionForPrivateLinkHub struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *PrivateEndpointConnectionProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/synapse/2021-06-01/privateendpointconnections/model_privateendpointconnectionproperties.go b/resource-manager/synapse/2021-06-01/privateendpointconnections/model_privateendpointconnectionproperties.go new file mode 100644 index 00000000000..0a4a3fdf71f --- /dev/null +++ b/resource-manager/synapse/2021-06-01/privateendpointconnections/model_privateendpointconnectionproperties.go @@ -0,0 +1,10 @@ +package privateendpointconnections + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateEndpointConnectionProperties struct { + PrivateEndpoint *PrivateEndpoint `json:"privateEndpoint,omitempty"` + PrivateLinkServiceConnectionState *PrivateLinkServiceConnectionState `json:"privateLinkServiceConnectionState,omitempty"` + ProvisioningState *string `json:"provisioningState,omitempty"` +} diff --git a/resource-manager/synapse/2021-06-01/privateendpointconnections/model_privatelinkserviceconnectionstate.go b/resource-manager/synapse/2021-06-01/privateendpointconnections/model_privatelinkserviceconnectionstate.go new file mode 100644 index 00000000000..3cdc39db45c --- /dev/null +++ b/resource-manager/synapse/2021-06-01/privateendpointconnections/model_privatelinkserviceconnectionstate.go @@ -0,0 +1,10 @@ +package privateendpointconnections + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateLinkServiceConnectionState struct { + ActionsRequired *string `json:"actionsRequired,omitempty"` + Description *string `json:"description,omitempty"` + Status *string `json:"status,omitempty"` +} diff --git a/resource-manager/synapse/2021-06-01/privateendpointconnections/predicates.go b/resource-manager/synapse/2021-06-01/privateendpointconnections/predicates.go new file mode 100644 index 00000000000..7d2bb1e9f1d --- /dev/null +++ b/resource-manager/synapse/2021-06-01/privateendpointconnections/predicates.go @@ -0,0 +1,50 @@ +package privateendpointconnections + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateEndpointConnectionOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p PrivateEndpointConnectionOperationPredicate) Matches(input PrivateEndpointConnection) bool { + + if p.Id != nil && (input.Id == nil || *p.Id != *input.Id) { + return false + } + + if p.Name != nil && (input.Name == nil || *p.Name != *input.Name) { + return false + } + + if p.Type != nil && (input.Type == nil || *p.Type != *input.Type) { + return false + } + + return true +} + +type PrivateEndpointConnectionForPrivateLinkHubOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p PrivateEndpointConnectionForPrivateLinkHubOperationPredicate) Matches(input PrivateEndpointConnectionForPrivateLinkHub) bool { + + if p.Id != nil && (input.Id == nil || *p.Id != *input.Id) { + return false + } + + if p.Name != nil && (input.Name == nil || *p.Name != *input.Name) { + return false + } + + if p.Type != nil && (input.Type == nil || *p.Type != *input.Type) { + return false + } + + return true +} diff --git a/resource-manager/synapse/2021-06-01/privateendpointconnections/version.go b/resource-manager/synapse/2021-06-01/privateendpointconnections/version.go new file mode 100644 index 00000000000..0d17055f179 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/privateendpointconnections/version.go @@ -0,0 +1,12 @@ +package privateendpointconnections + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2021-06-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/privateendpointconnections/%s", defaultApiVersion) +} diff --git a/resource-manager/synapse/2021-06-01/privatelinkhubprivatelinkresources/README.md b/resource-manager/synapse/2021-06-01/privatelinkhubprivatelinkresources/README.md new file mode 100644 index 00000000000..70cb3443f27 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/privatelinkhubprivatelinkresources/README.md @@ -0,0 +1,53 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/synapse/2021-06-01/privatelinkhubprivatelinkresources` Documentation + +The `privatelinkhubprivatelinkresources` SDK allows for interaction with the Azure Resource Manager Service `synapse` (API Version `2021-06-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/synapse/2021-06-01/privatelinkhubprivatelinkresources" +``` + + +### Client Initialization + +```go +client := privatelinkhubprivatelinkresources.NewPrivateLinkHubPrivateLinkResourcesClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `PrivateLinkHubPrivateLinkResourcesClient.Get` + +```go +ctx := context.TODO() +id := privatelinkhubprivatelinkresources.NewPrivateLinkHubPrivateLinkResourceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "privateLinkHubValue", "privateLinkResourceValue") + +read, err := client.Get(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `PrivateLinkHubPrivateLinkResourcesClient.List` + +```go +ctx := context.TODO() +id := privatelinkhubprivatelinkresources.NewPrivateLinkHubID("12345678-1234-9876-4563-123456789012", "example-resource-group", "privateLinkHubValue") + +// alternatively `client.List(ctx, id)` can be used to do batched pagination +items, err := client.ListComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/synapse/2021-06-01/privatelinkhubprivatelinkresources/client.go b/resource-manager/synapse/2021-06-01/privatelinkhubprivatelinkresources/client.go new file mode 100644 index 00000000000..0f87cbcaaf0 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/privatelinkhubprivatelinkresources/client.go @@ -0,0 +1,26 @@ +package privatelinkhubprivatelinkresources + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateLinkHubPrivateLinkResourcesClient struct { + Client *resourcemanager.Client +} + +func NewPrivateLinkHubPrivateLinkResourcesClientWithBaseURI(sdkApi sdkEnv.Api) (*PrivateLinkHubPrivateLinkResourcesClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "privatelinkhubprivatelinkresources", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating PrivateLinkHubPrivateLinkResourcesClient: %+v", err) + } + + return &PrivateLinkHubPrivateLinkResourcesClient{ + Client: client, + }, nil +} diff --git a/resource-manager/synapse/2021-06-01/privatelinkhubprivatelinkresources/id_privatelinkhub.go b/resource-manager/synapse/2021-06-01/privatelinkhubprivatelinkresources/id_privatelinkhub.go new file mode 100644 index 00000000000..886304fd61a --- /dev/null +++ b/resource-manager/synapse/2021-06-01/privatelinkhubprivatelinkresources/id_privatelinkhub.go @@ -0,0 +1,125 @@ +package privatelinkhubprivatelinkresources + +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 = &PrivateLinkHubId{} + +// PrivateLinkHubId is a struct representing the Resource ID for a Private Link Hub +type PrivateLinkHubId struct { + SubscriptionId string + ResourceGroupName string + PrivateLinkHubName string +} + +// NewPrivateLinkHubID returns a new PrivateLinkHubId struct +func NewPrivateLinkHubID(subscriptionId string, resourceGroupName string, privateLinkHubName string) PrivateLinkHubId { + return PrivateLinkHubId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + PrivateLinkHubName: privateLinkHubName, + } +} + +// ParsePrivateLinkHubID parses 'input' into a PrivateLinkHubId +func ParsePrivateLinkHubID(input string) (*PrivateLinkHubId, error) { + parser := resourceids.NewParserFromResourceIdType(&PrivateLinkHubId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := PrivateLinkHubId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParsePrivateLinkHubIDInsensitively parses 'input' case-insensitively into a PrivateLinkHubId +// note: this method should only be used for API response data and not user input +func ParsePrivateLinkHubIDInsensitively(input string) (*PrivateLinkHubId, error) { + parser := resourceids.NewParserFromResourceIdType(&PrivateLinkHubId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := PrivateLinkHubId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *PrivateLinkHubId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.PrivateLinkHubName, ok = input.Parsed["privateLinkHubName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "privateLinkHubName", input) + } + + return nil +} + +// ValidatePrivateLinkHubID checks that 'input' can be parsed as a Private Link Hub ID +func ValidatePrivateLinkHubID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParsePrivateLinkHubID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Private Link Hub ID +func (id PrivateLinkHubId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Synapse/privateLinkHubs/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.PrivateLinkHubName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Private Link Hub ID +func (id PrivateLinkHubId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftSynapse", "Microsoft.Synapse", "Microsoft.Synapse"), + resourceids.StaticSegment("staticPrivateLinkHubs", "privateLinkHubs", "privateLinkHubs"), + resourceids.UserSpecifiedSegment("privateLinkHubName", "privateLinkHubValue"), + } +} + +// String returns a human-readable description of this Private Link Hub ID +func (id PrivateLinkHubId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Private Link Hub Name: %q", id.PrivateLinkHubName), + } + return fmt.Sprintf("Private Link Hub (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/synapse/2021-06-01/privatelinkhubprivatelinkresources/id_privatelinkhub_test.go b/resource-manager/synapse/2021-06-01/privatelinkhubprivatelinkresources/id_privatelinkhub_test.go new file mode 100644 index 00000000000..0bf6fd51df9 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/privatelinkhubprivatelinkresources/id_privatelinkhub_test.go @@ -0,0 +1,282 @@ +package privatelinkhubprivatelinkresources + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &PrivateLinkHubId{} + +func TestNewPrivateLinkHubID(t *testing.T) { + id := NewPrivateLinkHubID("12345678-1234-9876-4563-123456789012", "example-resource-group", "privateLinkHubValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.PrivateLinkHubName != "privateLinkHubValue" { + t.Fatalf("Expected %q but got %q for Segment 'PrivateLinkHubName'", id.PrivateLinkHubName, "privateLinkHubValue") + } +} + +func TestFormatPrivateLinkHubID(t *testing.T) { + actual := NewPrivateLinkHubID("12345678-1234-9876-4563-123456789012", "example-resource-group", "privateLinkHubValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/privateLinkHubs/privateLinkHubValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParsePrivateLinkHubID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *PrivateLinkHubId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/privateLinkHubs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/privateLinkHubs/privateLinkHubValue", + Expected: &PrivateLinkHubId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + PrivateLinkHubName: "privateLinkHubValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/privateLinkHubs/privateLinkHubValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParsePrivateLinkHubID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.PrivateLinkHubName != v.Expected.PrivateLinkHubName { + t.Fatalf("Expected %q but got %q for PrivateLinkHubName", v.Expected.PrivateLinkHubName, actual.PrivateLinkHubName) + } + + } +} + +func TestParsePrivateLinkHubIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *PrivateLinkHubId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/privateLinkHubs", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/pRiVaTeLiNkHuBs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/privateLinkHubs/privateLinkHubValue", + Expected: &PrivateLinkHubId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + PrivateLinkHubName: "privateLinkHubValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/privateLinkHubs/privateLinkHubValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/pRiVaTeLiNkHuBs/pRiVaTeLiNkHuBvAlUe", + Expected: &PrivateLinkHubId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + PrivateLinkHubName: "pRiVaTeLiNkHuBvAlUe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/pRiVaTeLiNkHuBs/pRiVaTeLiNkHuBvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParsePrivateLinkHubIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.PrivateLinkHubName != v.Expected.PrivateLinkHubName { + t.Fatalf("Expected %q but got %q for PrivateLinkHubName", v.Expected.PrivateLinkHubName, actual.PrivateLinkHubName) + } + + } +} + +func TestSegmentsForPrivateLinkHubId(t *testing.T) { + segments := PrivateLinkHubId{}.Segments() + if len(segments) == 0 { + t.Fatalf("PrivateLinkHubId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/synapse/2021-06-01/privatelinkhubprivatelinkresources/id_privatelinkhubprivatelinkresource.go b/resource-manager/synapse/2021-06-01/privatelinkhubprivatelinkresources/id_privatelinkhubprivatelinkresource.go new file mode 100644 index 00000000000..f8954bfb211 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/privatelinkhubprivatelinkresources/id_privatelinkhubprivatelinkresource.go @@ -0,0 +1,134 @@ +package privatelinkhubprivatelinkresources + +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 = &PrivateLinkHubPrivateLinkResourceId{} + +// PrivateLinkHubPrivateLinkResourceId is a struct representing the Resource ID for a Private Link Hub Private Link Resource +type PrivateLinkHubPrivateLinkResourceId struct { + SubscriptionId string + ResourceGroupName string + PrivateLinkHubName string + PrivateLinkResourceName string +} + +// NewPrivateLinkHubPrivateLinkResourceID returns a new PrivateLinkHubPrivateLinkResourceId struct +func NewPrivateLinkHubPrivateLinkResourceID(subscriptionId string, resourceGroupName string, privateLinkHubName string, privateLinkResourceName string) PrivateLinkHubPrivateLinkResourceId { + return PrivateLinkHubPrivateLinkResourceId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + PrivateLinkHubName: privateLinkHubName, + PrivateLinkResourceName: privateLinkResourceName, + } +} + +// ParsePrivateLinkHubPrivateLinkResourceID parses 'input' into a PrivateLinkHubPrivateLinkResourceId +func ParsePrivateLinkHubPrivateLinkResourceID(input string) (*PrivateLinkHubPrivateLinkResourceId, error) { + parser := resourceids.NewParserFromResourceIdType(&PrivateLinkHubPrivateLinkResourceId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := PrivateLinkHubPrivateLinkResourceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParsePrivateLinkHubPrivateLinkResourceIDInsensitively parses 'input' case-insensitively into a PrivateLinkHubPrivateLinkResourceId +// note: this method should only be used for API response data and not user input +func ParsePrivateLinkHubPrivateLinkResourceIDInsensitively(input string) (*PrivateLinkHubPrivateLinkResourceId, error) { + parser := resourceids.NewParserFromResourceIdType(&PrivateLinkHubPrivateLinkResourceId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := PrivateLinkHubPrivateLinkResourceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *PrivateLinkHubPrivateLinkResourceId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.PrivateLinkHubName, ok = input.Parsed["privateLinkHubName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "privateLinkHubName", input) + } + + if id.PrivateLinkResourceName, ok = input.Parsed["privateLinkResourceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "privateLinkResourceName", input) + } + + return nil +} + +// ValidatePrivateLinkHubPrivateLinkResourceID checks that 'input' can be parsed as a Private Link Hub Private Link Resource ID +func ValidatePrivateLinkHubPrivateLinkResourceID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParsePrivateLinkHubPrivateLinkResourceID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Private Link Hub Private Link Resource ID +func (id PrivateLinkHubPrivateLinkResourceId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Synapse/privateLinkHubs/%s/privateLinkResources/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.PrivateLinkHubName, id.PrivateLinkResourceName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Private Link Hub Private Link Resource ID +func (id PrivateLinkHubPrivateLinkResourceId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftSynapse", "Microsoft.Synapse", "Microsoft.Synapse"), + resourceids.StaticSegment("staticPrivateLinkHubs", "privateLinkHubs", "privateLinkHubs"), + resourceids.UserSpecifiedSegment("privateLinkHubName", "privateLinkHubValue"), + resourceids.StaticSegment("staticPrivateLinkResources", "privateLinkResources", "privateLinkResources"), + resourceids.UserSpecifiedSegment("privateLinkResourceName", "privateLinkResourceValue"), + } +} + +// String returns a human-readable description of this Private Link Hub Private Link Resource ID +func (id PrivateLinkHubPrivateLinkResourceId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Private Link Hub Name: %q", id.PrivateLinkHubName), + fmt.Sprintf("Private Link Resource Name: %q", id.PrivateLinkResourceName), + } + return fmt.Sprintf("Private Link Hub Private Link Resource (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/synapse/2021-06-01/privatelinkhubprivatelinkresources/id_privatelinkhubprivatelinkresource_test.go b/resource-manager/synapse/2021-06-01/privatelinkhubprivatelinkresources/id_privatelinkhubprivatelinkresource_test.go new file mode 100644 index 00000000000..10f5d75e27a --- /dev/null +++ b/resource-manager/synapse/2021-06-01/privatelinkhubprivatelinkresources/id_privatelinkhubprivatelinkresource_test.go @@ -0,0 +1,327 @@ +package privatelinkhubprivatelinkresources + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &PrivateLinkHubPrivateLinkResourceId{} + +func TestNewPrivateLinkHubPrivateLinkResourceID(t *testing.T) { + id := NewPrivateLinkHubPrivateLinkResourceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "privateLinkHubValue", "privateLinkResourceValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.PrivateLinkHubName != "privateLinkHubValue" { + t.Fatalf("Expected %q but got %q for Segment 'PrivateLinkHubName'", id.PrivateLinkHubName, "privateLinkHubValue") + } + + if id.PrivateLinkResourceName != "privateLinkResourceValue" { + t.Fatalf("Expected %q but got %q for Segment 'PrivateLinkResourceName'", id.PrivateLinkResourceName, "privateLinkResourceValue") + } +} + +func TestFormatPrivateLinkHubPrivateLinkResourceID(t *testing.T) { + actual := NewPrivateLinkHubPrivateLinkResourceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "privateLinkHubValue", "privateLinkResourceValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/privateLinkHubs/privateLinkHubValue/privateLinkResources/privateLinkResourceValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParsePrivateLinkHubPrivateLinkResourceID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *PrivateLinkHubPrivateLinkResourceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/privateLinkHubs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/privateLinkHubs/privateLinkHubValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/privateLinkHubs/privateLinkHubValue/privateLinkResources", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/privateLinkHubs/privateLinkHubValue/privateLinkResources/privateLinkResourceValue", + Expected: &PrivateLinkHubPrivateLinkResourceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + PrivateLinkHubName: "privateLinkHubValue", + PrivateLinkResourceName: "privateLinkResourceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/privateLinkHubs/privateLinkHubValue/privateLinkResources/privateLinkResourceValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParsePrivateLinkHubPrivateLinkResourceID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.PrivateLinkHubName != v.Expected.PrivateLinkHubName { + t.Fatalf("Expected %q but got %q for PrivateLinkHubName", v.Expected.PrivateLinkHubName, actual.PrivateLinkHubName) + } + + if actual.PrivateLinkResourceName != v.Expected.PrivateLinkResourceName { + t.Fatalf("Expected %q but got %q for PrivateLinkResourceName", v.Expected.PrivateLinkResourceName, actual.PrivateLinkResourceName) + } + + } +} + +func TestParsePrivateLinkHubPrivateLinkResourceIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *PrivateLinkHubPrivateLinkResourceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/privateLinkHubs", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/pRiVaTeLiNkHuBs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/privateLinkHubs/privateLinkHubValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/pRiVaTeLiNkHuBs/pRiVaTeLiNkHuBvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/privateLinkHubs/privateLinkHubValue/privateLinkResources", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/pRiVaTeLiNkHuBs/pRiVaTeLiNkHuBvAlUe/pRiVaTeLiNkReSoUrCeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/privateLinkHubs/privateLinkHubValue/privateLinkResources/privateLinkResourceValue", + Expected: &PrivateLinkHubPrivateLinkResourceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + PrivateLinkHubName: "privateLinkHubValue", + PrivateLinkResourceName: "privateLinkResourceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/privateLinkHubs/privateLinkHubValue/privateLinkResources/privateLinkResourceValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/pRiVaTeLiNkHuBs/pRiVaTeLiNkHuBvAlUe/pRiVaTeLiNkReSoUrCeS/pRiVaTeLiNkReSoUrCeVaLuE", + Expected: &PrivateLinkHubPrivateLinkResourceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + PrivateLinkHubName: "pRiVaTeLiNkHuBvAlUe", + PrivateLinkResourceName: "pRiVaTeLiNkReSoUrCeVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/pRiVaTeLiNkHuBs/pRiVaTeLiNkHuBvAlUe/pRiVaTeLiNkReSoUrCeS/pRiVaTeLiNkReSoUrCeVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParsePrivateLinkHubPrivateLinkResourceIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.PrivateLinkHubName != v.Expected.PrivateLinkHubName { + t.Fatalf("Expected %q but got %q for PrivateLinkHubName", v.Expected.PrivateLinkHubName, actual.PrivateLinkHubName) + } + + if actual.PrivateLinkResourceName != v.Expected.PrivateLinkResourceName { + t.Fatalf("Expected %q but got %q for PrivateLinkResourceName", v.Expected.PrivateLinkResourceName, actual.PrivateLinkResourceName) + } + + } +} + +func TestSegmentsForPrivateLinkHubPrivateLinkResourceId(t *testing.T) { + segments := PrivateLinkHubPrivateLinkResourceId{}.Segments() + if len(segments) == 0 { + t.Fatalf("PrivateLinkHubPrivateLinkResourceId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/synapse/2021-06-01/privatelinkhubprivatelinkresources/method_get.go b/resource-manager/synapse/2021-06-01/privatelinkhubprivatelinkresources/method_get.go new file mode 100644 index 00000000000..5ceac2d0e02 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/privatelinkhubprivatelinkresources/method_get.go @@ -0,0 +1,51 @@ +package privatelinkhubprivatelinkresources + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *PrivateLinkResource +} + +// Get ... +func (c PrivateLinkHubPrivateLinkResourcesClient) Get(ctx context.Context, id PrivateLinkHubPrivateLinkResourceId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/synapse/2021-06-01/privatelinkhubprivatelinkresources/method_list.go b/resource-manager/synapse/2021-06-01/privatelinkhubprivatelinkresources/method_list.go new file mode 100644 index 00000000000..045f614075c --- /dev/null +++ b/resource-manager/synapse/2021-06-01/privatelinkhubprivatelinkresources/method_list.go @@ -0,0 +1,91 @@ +package privatelinkhubprivatelinkresources + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]PrivateLinkResource +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []PrivateLinkResource +} + +// List ... +func (c PrivateLinkHubPrivateLinkResourcesClient) List(ctx context.Context, id PrivateLinkHubId) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/privateLinkResources", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]PrivateLinkResource `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListComplete retrieves all the results into a single object +func (c PrivateLinkHubPrivateLinkResourcesClient) ListComplete(ctx context.Context, id PrivateLinkHubId) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, PrivateLinkResourceOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c PrivateLinkHubPrivateLinkResourcesClient) ListCompleteMatchingPredicate(ctx context.Context, id PrivateLinkHubId, predicate PrivateLinkResourceOperationPredicate) (result ListCompleteResult, err error) { + items := make([]PrivateLinkResource, 0) + + resp, err := c.List(ctx, id) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/synapse/2021-06-01/privatelinkhubprivatelinkresources/model_privatelinkresource.go b/resource-manager/synapse/2021-06-01/privatelinkhubprivatelinkresources/model_privatelinkresource.go new file mode 100644 index 00000000000..1dead3c0e22 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/privatelinkhubprivatelinkresources/model_privatelinkresource.go @@ -0,0 +1,11 @@ +package privatelinkhubprivatelinkresources + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateLinkResource struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *PrivateLinkResourceProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/synapse/2021-06-01/privatelinkhubprivatelinkresources/model_privatelinkresourceproperties.go b/resource-manager/synapse/2021-06-01/privatelinkhubprivatelinkresources/model_privatelinkresourceproperties.go new file mode 100644 index 00000000000..fe72f00966d --- /dev/null +++ b/resource-manager/synapse/2021-06-01/privatelinkhubprivatelinkresources/model_privatelinkresourceproperties.go @@ -0,0 +1,10 @@ +package privatelinkhubprivatelinkresources + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateLinkResourceProperties struct { + GroupId *string `json:"groupId,omitempty"` + RequiredMembers *[]string `json:"requiredMembers,omitempty"` + RequiredZoneNames *[]string `json:"requiredZoneNames,omitempty"` +} diff --git a/resource-manager/synapse/2021-06-01/privatelinkhubprivatelinkresources/predicates.go b/resource-manager/synapse/2021-06-01/privatelinkhubprivatelinkresources/predicates.go new file mode 100644 index 00000000000..4bc6d90ffb4 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/privatelinkhubprivatelinkresources/predicates.go @@ -0,0 +1,27 @@ +package privatelinkhubprivatelinkresources + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateLinkResourceOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p PrivateLinkResourceOperationPredicate) Matches(input PrivateLinkResource) bool { + + if p.Id != nil && (input.Id == nil || *p.Id != *input.Id) { + return false + } + + if p.Name != nil && (input.Name == nil || *p.Name != *input.Name) { + return false + } + + if p.Type != nil && (input.Type == nil || *p.Type != *input.Type) { + return false + } + + return true +} diff --git a/resource-manager/synapse/2021-06-01/privatelinkhubprivatelinkresources/version.go b/resource-manager/synapse/2021-06-01/privatelinkhubprivatelinkresources/version.go new file mode 100644 index 00000000000..889483cf24b --- /dev/null +++ b/resource-manager/synapse/2021-06-01/privatelinkhubprivatelinkresources/version.go @@ -0,0 +1,12 @@ +package privatelinkhubprivatelinkresources + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2021-06-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/privatelinkhubprivatelinkresources/%s", defaultApiVersion) +} diff --git a/resource-manager/synapse/2021-06-01/privatelinkhubs/README.md b/resource-manager/synapse/2021-06-01/privatelinkhubs/README.md new file mode 100644 index 00000000000..bdaf02238bb --- /dev/null +++ b/resource-manager/synapse/2021-06-01/privatelinkhubs/README.md @@ -0,0 +1,157 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/synapse/2021-06-01/privatelinkhubs` Documentation + +The `privatelinkhubs` SDK allows for interaction with the Azure Resource Manager Service `synapse` (API Version `2021-06-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/synapse/2021-06-01/privatelinkhubs" +``` + + +### Client Initialization + +```go +client := privatelinkhubs.NewPrivateLinkHubsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `PrivateLinkHubsClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := privatelinkhubs.NewPrivateLinkHubID("12345678-1234-9876-4563-123456789012", "example-resource-group", "privateLinkHubValue") + +payload := privatelinkhubs.PrivateLinkHub{ + // ... +} + + +read, err := client.CreateOrUpdate(ctx, id, payload) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `PrivateLinkHubsClient.Delete` + +```go +ctx := context.TODO() +id := privatelinkhubs.NewPrivateLinkHubID("12345678-1234-9876-4563-123456789012", "example-resource-group", "privateLinkHubValue") + +if err := client.DeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `PrivateLinkHubsClient.Get` + +```go +ctx := context.TODO() +id := privatelinkhubs.NewPrivateLinkHubID("12345678-1234-9876-4563-123456789012", "example-resource-group", "privateLinkHubValue") + +read, err := client.Get(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `PrivateLinkHubsClient.List` + +```go +ctx := context.TODO() +id := privatelinkhubs.NewSubscriptionID("12345678-1234-9876-4563-123456789012") + +// alternatively `client.List(ctx, id)` can be used to do batched pagination +items, err := client.ListComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `PrivateLinkHubsClient.ListByResourceGroup` + +```go +ctx := context.TODO() +id := privatelinkhubs.NewResourceGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group") + +// alternatively `client.ListByResourceGroup(ctx, id)` can be used to do batched pagination +items, err := client.ListByResourceGroupComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `PrivateLinkHubsClient.PrivateEndpointConnectionsPrivateLinkHubGet` + +```go +ctx := context.TODO() +id := privatelinkhubs.NewPrivateLinkHubPrivateEndpointConnectionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "privateLinkHubValue", "privateEndpointConnectionValue") + +read, err := client.PrivateEndpointConnectionsPrivateLinkHubGet(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `PrivateLinkHubsClient.PrivateEndpointConnectionsPrivateLinkHubList` + +```go +ctx := context.TODO() +id := privatelinkhubs.NewPrivateLinkHubID("12345678-1234-9876-4563-123456789012", "example-resource-group", "privateLinkHubValue") + +// alternatively `client.PrivateEndpointConnectionsPrivateLinkHubList(ctx, id)` can be used to do batched pagination +items, err := client.PrivateEndpointConnectionsPrivateLinkHubListComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `PrivateLinkHubsClient.Update` + +```go +ctx := context.TODO() +id := privatelinkhubs.NewPrivateLinkHubID("12345678-1234-9876-4563-123456789012", "example-resource-group", "privateLinkHubValue") + +payload := privatelinkhubs.PrivateLinkHubPatchInfo{ + // ... +} + + +read, err := client.Update(ctx, id, payload) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` diff --git a/resource-manager/synapse/2021-06-01/privatelinkhubs/client.go b/resource-manager/synapse/2021-06-01/privatelinkhubs/client.go new file mode 100644 index 00000000000..ae4439c026e --- /dev/null +++ b/resource-manager/synapse/2021-06-01/privatelinkhubs/client.go @@ -0,0 +1,26 @@ +package privatelinkhubs + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateLinkHubsClient struct { + Client *resourcemanager.Client +} + +func NewPrivateLinkHubsClientWithBaseURI(sdkApi sdkEnv.Api) (*PrivateLinkHubsClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "privatelinkhubs", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating PrivateLinkHubsClient: %+v", err) + } + + return &PrivateLinkHubsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/synapse/2021-06-01/privatelinkhubs/id_privatelinkhub.go b/resource-manager/synapse/2021-06-01/privatelinkhubs/id_privatelinkhub.go new file mode 100644 index 00000000000..472161c1690 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/privatelinkhubs/id_privatelinkhub.go @@ -0,0 +1,125 @@ +package privatelinkhubs + +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 = &PrivateLinkHubId{} + +// PrivateLinkHubId is a struct representing the Resource ID for a Private Link Hub +type PrivateLinkHubId struct { + SubscriptionId string + ResourceGroupName string + PrivateLinkHubName string +} + +// NewPrivateLinkHubID returns a new PrivateLinkHubId struct +func NewPrivateLinkHubID(subscriptionId string, resourceGroupName string, privateLinkHubName string) PrivateLinkHubId { + return PrivateLinkHubId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + PrivateLinkHubName: privateLinkHubName, + } +} + +// ParsePrivateLinkHubID parses 'input' into a PrivateLinkHubId +func ParsePrivateLinkHubID(input string) (*PrivateLinkHubId, error) { + parser := resourceids.NewParserFromResourceIdType(&PrivateLinkHubId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := PrivateLinkHubId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParsePrivateLinkHubIDInsensitively parses 'input' case-insensitively into a PrivateLinkHubId +// note: this method should only be used for API response data and not user input +func ParsePrivateLinkHubIDInsensitively(input string) (*PrivateLinkHubId, error) { + parser := resourceids.NewParserFromResourceIdType(&PrivateLinkHubId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := PrivateLinkHubId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *PrivateLinkHubId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.PrivateLinkHubName, ok = input.Parsed["privateLinkHubName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "privateLinkHubName", input) + } + + return nil +} + +// ValidatePrivateLinkHubID checks that 'input' can be parsed as a Private Link Hub ID +func ValidatePrivateLinkHubID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParsePrivateLinkHubID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Private Link Hub ID +func (id PrivateLinkHubId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Synapse/privateLinkHubs/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.PrivateLinkHubName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Private Link Hub ID +func (id PrivateLinkHubId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftSynapse", "Microsoft.Synapse", "Microsoft.Synapse"), + resourceids.StaticSegment("staticPrivateLinkHubs", "privateLinkHubs", "privateLinkHubs"), + resourceids.UserSpecifiedSegment("privateLinkHubName", "privateLinkHubValue"), + } +} + +// String returns a human-readable description of this Private Link Hub ID +func (id PrivateLinkHubId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Private Link Hub Name: %q", id.PrivateLinkHubName), + } + return fmt.Sprintf("Private Link Hub (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/synapse/2021-06-01/privatelinkhubs/id_privatelinkhub_test.go b/resource-manager/synapse/2021-06-01/privatelinkhubs/id_privatelinkhub_test.go new file mode 100644 index 00000000000..89a5976b581 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/privatelinkhubs/id_privatelinkhub_test.go @@ -0,0 +1,282 @@ +package privatelinkhubs + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &PrivateLinkHubId{} + +func TestNewPrivateLinkHubID(t *testing.T) { + id := NewPrivateLinkHubID("12345678-1234-9876-4563-123456789012", "example-resource-group", "privateLinkHubValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.PrivateLinkHubName != "privateLinkHubValue" { + t.Fatalf("Expected %q but got %q for Segment 'PrivateLinkHubName'", id.PrivateLinkHubName, "privateLinkHubValue") + } +} + +func TestFormatPrivateLinkHubID(t *testing.T) { + actual := NewPrivateLinkHubID("12345678-1234-9876-4563-123456789012", "example-resource-group", "privateLinkHubValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/privateLinkHubs/privateLinkHubValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParsePrivateLinkHubID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *PrivateLinkHubId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/privateLinkHubs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/privateLinkHubs/privateLinkHubValue", + Expected: &PrivateLinkHubId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + PrivateLinkHubName: "privateLinkHubValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/privateLinkHubs/privateLinkHubValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParsePrivateLinkHubID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.PrivateLinkHubName != v.Expected.PrivateLinkHubName { + t.Fatalf("Expected %q but got %q for PrivateLinkHubName", v.Expected.PrivateLinkHubName, actual.PrivateLinkHubName) + } + + } +} + +func TestParsePrivateLinkHubIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *PrivateLinkHubId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/privateLinkHubs", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/pRiVaTeLiNkHuBs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/privateLinkHubs/privateLinkHubValue", + Expected: &PrivateLinkHubId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + PrivateLinkHubName: "privateLinkHubValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/privateLinkHubs/privateLinkHubValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/pRiVaTeLiNkHuBs/pRiVaTeLiNkHuBvAlUe", + Expected: &PrivateLinkHubId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + PrivateLinkHubName: "pRiVaTeLiNkHuBvAlUe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/pRiVaTeLiNkHuBs/pRiVaTeLiNkHuBvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParsePrivateLinkHubIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.PrivateLinkHubName != v.Expected.PrivateLinkHubName { + t.Fatalf("Expected %q but got %q for PrivateLinkHubName", v.Expected.PrivateLinkHubName, actual.PrivateLinkHubName) + } + + } +} + +func TestSegmentsForPrivateLinkHubId(t *testing.T) { + segments := PrivateLinkHubId{}.Segments() + if len(segments) == 0 { + t.Fatalf("PrivateLinkHubId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/synapse/2021-06-01/privatelinkhubs/id_privatelinkhubprivateendpointconnection.go b/resource-manager/synapse/2021-06-01/privatelinkhubs/id_privatelinkhubprivateendpointconnection.go new file mode 100644 index 00000000000..7c2f990ae9d --- /dev/null +++ b/resource-manager/synapse/2021-06-01/privatelinkhubs/id_privatelinkhubprivateendpointconnection.go @@ -0,0 +1,134 @@ +package privatelinkhubs + +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 = &PrivateLinkHubPrivateEndpointConnectionId{} + +// PrivateLinkHubPrivateEndpointConnectionId is a struct representing the Resource ID for a Private Link Hub Private Endpoint Connection +type PrivateLinkHubPrivateEndpointConnectionId struct { + SubscriptionId string + ResourceGroupName string + PrivateLinkHubName string + PrivateEndpointConnectionName string +} + +// NewPrivateLinkHubPrivateEndpointConnectionID returns a new PrivateLinkHubPrivateEndpointConnectionId struct +func NewPrivateLinkHubPrivateEndpointConnectionID(subscriptionId string, resourceGroupName string, privateLinkHubName string, privateEndpointConnectionName string) PrivateLinkHubPrivateEndpointConnectionId { + return PrivateLinkHubPrivateEndpointConnectionId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + PrivateLinkHubName: privateLinkHubName, + PrivateEndpointConnectionName: privateEndpointConnectionName, + } +} + +// ParsePrivateLinkHubPrivateEndpointConnectionID parses 'input' into a PrivateLinkHubPrivateEndpointConnectionId +func ParsePrivateLinkHubPrivateEndpointConnectionID(input string) (*PrivateLinkHubPrivateEndpointConnectionId, error) { + parser := resourceids.NewParserFromResourceIdType(&PrivateLinkHubPrivateEndpointConnectionId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := PrivateLinkHubPrivateEndpointConnectionId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParsePrivateLinkHubPrivateEndpointConnectionIDInsensitively parses 'input' case-insensitively into a PrivateLinkHubPrivateEndpointConnectionId +// note: this method should only be used for API response data and not user input +func ParsePrivateLinkHubPrivateEndpointConnectionIDInsensitively(input string) (*PrivateLinkHubPrivateEndpointConnectionId, error) { + parser := resourceids.NewParserFromResourceIdType(&PrivateLinkHubPrivateEndpointConnectionId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := PrivateLinkHubPrivateEndpointConnectionId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *PrivateLinkHubPrivateEndpointConnectionId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.PrivateLinkHubName, ok = input.Parsed["privateLinkHubName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "privateLinkHubName", input) + } + + if id.PrivateEndpointConnectionName, ok = input.Parsed["privateEndpointConnectionName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "privateEndpointConnectionName", input) + } + + return nil +} + +// ValidatePrivateLinkHubPrivateEndpointConnectionID checks that 'input' can be parsed as a Private Link Hub Private Endpoint Connection ID +func ValidatePrivateLinkHubPrivateEndpointConnectionID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParsePrivateLinkHubPrivateEndpointConnectionID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Private Link Hub Private Endpoint Connection ID +func (id PrivateLinkHubPrivateEndpointConnectionId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Synapse/privateLinkHubs/%s/privateEndpointConnections/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.PrivateLinkHubName, id.PrivateEndpointConnectionName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Private Link Hub Private Endpoint Connection ID +func (id PrivateLinkHubPrivateEndpointConnectionId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftSynapse", "Microsoft.Synapse", "Microsoft.Synapse"), + resourceids.StaticSegment("staticPrivateLinkHubs", "privateLinkHubs", "privateLinkHubs"), + resourceids.UserSpecifiedSegment("privateLinkHubName", "privateLinkHubValue"), + resourceids.StaticSegment("staticPrivateEndpointConnections", "privateEndpointConnections", "privateEndpointConnections"), + resourceids.UserSpecifiedSegment("privateEndpointConnectionName", "privateEndpointConnectionValue"), + } +} + +// String returns a human-readable description of this Private Link Hub Private Endpoint Connection ID +func (id PrivateLinkHubPrivateEndpointConnectionId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Private Link Hub Name: %q", id.PrivateLinkHubName), + fmt.Sprintf("Private Endpoint Connection Name: %q", id.PrivateEndpointConnectionName), + } + return fmt.Sprintf("Private Link Hub Private Endpoint Connection (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/synapse/2021-06-01/privatelinkhubs/id_privatelinkhubprivateendpointconnection_test.go b/resource-manager/synapse/2021-06-01/privatelinkhubs/id_privatelinkhubprivateendpointconnection_test.go new file mode 100644 index 00000000000..da5b449a11b --- /dev/null +++ b/resource-manager/synapse/2021-06-01/privatelinkhubs/id_privatelinkhubprivateendpointconnection_test.go @@ -0,0 +1,327 @@ +package privatelinkhubs + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &PrivateLinkHubPrivateEndpointConnectionId{} + +func TestNewPrivateLinkHubPrivateEndpointConnectionID(t *testing.T) { + id := NewPrivateLinkHubPrivateEndpointConnectionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "privateLinkHubValue", "privateEndpointConnectionValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.PrivateLinkHubName != "privateLinkHubValue" { + t.Fatalf("Expected %q but got %q for Segment 'PrivateLinkHubName'", id.PrivateLinkHubName, "privateLinkHubValue") + } + + if id.PrivateEndpointConnectionName != "privateEndpointConnectionValue" { + t.Fatalf("Expected %q but got %q for Segment 'PrivateEndpointConnectionName'", id.PrivateEndpointConnectionName, "privateEndpointConnectionValue") + } +} + +func TestFormatPrivateLinkHubPrivateEndpointConnectionID(t *testing.T) { + actual := NewPrivateLinkHubPrivateEndpointConnectionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "privateLinkHubValue", "privateEndpointConnectionValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/privateLinkHubs/privateLinkHubValue/privateEndpointConnections/privateEndpointConnectionValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParsePrivateLinkHubPrivateEndpointConnectionID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *PrivateLinkHubPrivateEndpointConnectionId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/privateLinkHubs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/privateLinkHubs/privateLinkHubValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/privateLinkHubs/privateLinkHubValue/privateEndpointConnections", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/privateLinkHubs/privateLinkHubValue/privateEndpointConnections/privateEndpointConnectionValue", + Expected: &PrivateLinkHubPrivateEndpointConnectionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + PrivateLinkHubName: "privateLinkHubValue", + PrivateEndpointConnectionName: "privateEndpointConnectionValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/privateLinkHubs/privateLinkHubValue/privateEndpointConnections/privateEndpointConnectionValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParsePrivateLinkHubPrivateEndpointConnectionID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.PrivateLinkHubName != v.Expected.PrivateLinkHubName { + t.Fatalf("Expected %q but got %q for PrivateLinkHubName", v.Expected.PrivateLinkHubName, actual.PrivateLinkHubName) + } + + if actual.PrivateEndpointConnectionName != v.Expected.PrivateEndpointConnectionName { + t.Fatalf("Expected %q but got %q for PrivateEndpointConnectionName", v.Expected.PrivateEndpointConnectionName, actual.PrivateEndpointConnectionName) + } + + } +} + +func TestParsePrivateLinkHubPrivateEndpointConnectionIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *PrivateLinkHubPrivateEndpointConnectionId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/privateLinkHubs", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/pRiVaTeLiNkHuBs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/privateLinkHubs/privateLinkHubValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/pRiVaTeLiNkHuBs/pRiVaTeLiNkHuBvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/privateLinkHubs/privateLinkHubValue/privateEndpointConnections", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/pRiVaTeLiNkHuBs/pRiVaTeLiNkHuBvAlUe/pRiVaTeEnDpOiNtCoNnEcTiOnS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/privateLinkHubs/privateLinkHubValue/privateEndpointConnections/privateEndpointConnectionValue", + Expected: &PrivateLinkHubPrivateEndpointConnectionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + PrivateLinkHubName: "privateLinkHubValue", + PrivateEndpointConnectionName: "privateEndpointConnectionValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/privateLinkHubs/privateLinkHubValue/privateEndpointConnections/privateEndpointConnectionValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/pRiVaTeLiNkHuBs/pRiVaTeLiNkHuBvAlUe/pRiVaTeEnDpOiNtCoNnEcTiOnS/pRiVaTeEnDpOiNtCoNnEcTiOnVaLuE", + Expected: &PrivateLinkHubPrivateEndpointConnectionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + PrivateLinkHubName: "pRiVaTeLiNkHuBvAlUe", + PrivateEndpointConnectionName: "pRiVaTeEnDpOiNtCoNnEcTiOnVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/pRiVaTeLiNkHuBs/pRiVaTeLiNkHuBvAlUe/pRiVaTeEnDpOiNtCoNnEcTiOnS/pRiVaTeEnDpOiNtCoNnEcTiOnVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParsePrivateLinkHubPrivateEndpointConnectionIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.PrivateLinkHubName != v.Expected.PrivateLinkHubName { + t.Fatalf("Expected %q but got %q for PrivateLinkHubName", v.Expected.PrivateLinkHubName, actual.PrivateLinkHubName) + } + + if actual.PrivateEndpointConnectionName != v.Expected.PrivateEndpointConnectionName { + t.Fatalf("Expected %q but got %q for PrivateEndpointConnectionName", v.Expected.PrivateEndpointConnectionName, actual.PrivateEndpointConnectionName) + } + + } +} + +func TestSegmentsForPrivateLinkHubPrivateEndpointConnectionId(t *testing.T) { + segments := PrivateLinkHubPrivateEndpointConnectionId{}.Segments() + if len(segments) == 0 { + t.Fatalf("PrivateLinkHubPrivateEndpointConnectionId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/synapse/2021-06-01/privatelinkhubs/method_createorupdate.go b/resource-manager/synapse/2021-06-01/privatelinkhubs/method_createorupdate.go new file mode 100644 index 00000000000..63d426cfea2 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/privatelinkhubs/method_createorupdate.go @@ -0,0 +1,56 @@ +package privatelinkhubs + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *PrivateLinkHub +} + +// CreateOrUpdate ... +func (c PrivateLinkHubsClient) CreateOrUpdate(ctx context.Context, id PrivateLinkHubId, input PrivateLinkHub) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/synapse/2021-06-01/privatelinkhubs/method_delete.go b/resource-manager/synapse/2021-06-01/privatelinkhubs/method_delete.go new file mode 100644 index 00000000000..e1ccc047ec0 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/privatelinkhubs/method_delete.go @@ -0,0 +1,71 @@ +package privatelinkhubs + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// Delete ... +func (c PrivateLinkHubsClient) Delete(ctx context.Context, id PrivateLinkHubId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// DeleteThenPoll performs Delete then polls until it's completed +func (c PrivateLinkHubsClient) DeleteThenPoll(ctx context.Context, id PrivateLinkHubId) error { + result, err := c.Delete(ctx, id) + if err != nil { + return fmt.Errorf("performing Delete: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after Delete: %+v", err) + } + + return nil +} diff --git a/resource-manager/synapse/2021-06-01/privatelinkhubs/method_get.go b/resource-manager/synapse/2021-06-01/privatelinkhubs/method_get.go new file mode 100644 index 00000000000..acbcad05180 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/privatelinkhubs/method_get.go @@ -0,0 +1,51 @@ +package privatelinkhubs + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *PrivateLinkHub +} + +// Get ... +func (c PrivateLinkHubsClient) Get(ctx context.Context, id PrivateLinkHubId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/synapse/2021-06-01/privatelinkhubs/method_list.go b/resource-manager/synapse/2021-06-01/privatelinkhubs/method_list.go new file mode 100644 index 00000000000..1a65798f08d --- /dev/null +++ b/resource-manager/synapse/2021-06-01/privatelinkhubs/method_list.go @@ -0,0 +1,92 @@ +package privatelinkhubs + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]PrivateLinkHub +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []PrivateLinkHub +} + +// List ... +func (c PrivateLinkHubsClient) List(ctx context.Context, id commonids.SubscriptionId) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/providers/Microsoft.Synapse/privateLinkHubs", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]PrivateLinkHub `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListComplete retrieves all the results into a single object +func (c PrivateLinkHubsClient) ListComplete(ctx context.Context, id commonids.SubscriptionId) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, PrivateLinkHubOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c PrivateLinkHubsClient) ListCompleteMatchingPredicate(ctx context.Context, id commonids.SubscriptionId, predicate PrivateLinkHubOperationPredicate) (result ListCompleteResult, err error) { + items := make([]PrivateLinkHub, 0) + + resp, err := c.List(ctx, id) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/synapse/2021-06-01/privatelinkhubs/method_listbyresourcegroup.go b/resource-manager/synapse/2021-06-01/privatelinkhubs/method_listbyresourcegroup.go new file mode 100644 index 00000000000..c4b8a79a35f --- /dev/null +++ b/resource-manager/synapse/2021-06-01/privatelinkhubs/method_listbyresourcegroup.go @@ -0,0 +1,92 @@ +package privatelinkhubs + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListByResourceGroupOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]PrivateLinkHub +} + +type ListByResourceGroupCompleteResult struct { + LatestHttpResponse *http.Response + Items []PrivateLinkHub +} + +// ListByResourceGroup ... +func (c PrivateLinkHubsClient) ListByResourceGroup(ctx context.Context, id commonids.ResourceGroupId) (result ListByResourceGroupOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/providers/Microsoft.Synapse/privateLinkHubs", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]PrivateLinkHub `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByResourceGroupComplete retrieves all the results into a single object +func (c PrivateLinkHubsClient) ListByResourceGroupComplete(ctx context.Context, id commonids.ResourceGroupId) (ListByResourceGroupCompleteResult, error) { + return c.ListByResourceGroupCompleteMatchingPredicate(ctx, id, PrivateLinkHubOperationPredicate{}) +} + +// ListByResourceGroupCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c PrivateLinkHubsClient) ListByResourceGroupCompleteMatchingPredicate(ctx context.Context, id commonids.ResourceGroupId, predicate PrivateLinkHubOperationPredicate) (result ListByResourceGroupCompleteResult, err error) { + items := make([]PrivateLinkHub, 0) + + resp, err := c.ListByResourceGroup(ctx, id) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByResourceGroupCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/synapse/2021-06-01/privatelinkhubs/method_privateendpointconnectionsprivatelinkhubget.go b/resource-manager/synapse/2021-06-01/privatelinkhubs/method_privateendpointconnectionsprivatelinkhubget.go new file mode 100644 index 00000000000..274068deb2a --- /dev/null +++ b/resource-manager/synapse/2021-06-01/privatelinkhubs/method_privateendpointconnectionsprivatelinkhubget.go @@ -0,0 +1,51 @@ +package privatelinkhubs + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateEndpointConnectionsPrivateLinkHubGetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *PrivateEndpointConnectionForPrivateLinkHub +} + +// PrivateEndpointConnectionsPrivateLinkHubGet ... +func (c PrivateLinkHubsClient) PrivateEndpointConnectionsPrivateLinkHubGet(ctx context.Context, id PrivateLinkHubPrivateEndpointConnectionId) (result PrivateEndpointConnectionsPrivateLinkHubGetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/synapse/2021-06-01/privatelinkhubs/method_privateendpointconnectionsprivatelinkhublist.go b/resource-manager/synapse/2021-06-01/privatelinkhubs/method_privateendpointconnectionsprivatelinkhublist.go new file mode 100644 index 00000000000..405fc8ba446 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/privatelinkhubs/method_privateendpointconnectionsprivatelinkhublist.go @@ -0,0 +1,91 @@ +package privatelinkhubs + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateEndpointConnectionsPrivateLinkHubListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]PrivateEndpointConnectionForPrivateLinkHub +} + +type PrivateEndpointConnectionsPrivateLinkHubListCompleteResult struct { + LatestHttpResponse *http.Response + Items []PrivateEndpointConnectionForPrivateLinkHub +} + +// PrivateEndpointConnectionsPrivateLinkHubList ... +func (c PrivateLinkHubsClient) PrivateEndpointConnectionsPrivateLinkHubList(ctx context.Context, id PrivateLinkHubId) (result PrivateEndpointConnectionsPrivateLinkHubListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/privateEndpointConnections", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]PrivateEndpointConnectionForPrivateLinkHub `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// PrivateEndpointConnectionsPrivateLinkHubListComplete retrieves all the results into a single object +func (c PrivateLinkHubsClient) PrivateEndpointConnectionsPrivateLinkHubListComplete(ctx context.Context, id PrivateLinkHubId) (PrivateEndpointConnectionsPrivateLinkHubListCompleteResult, error) { + return c.PrivateEndpointConnectionsPrivateLinkHubListCompleteMatchingPredicate(ctx, id, PrivateEndpointConnectionForPrivateLinkHubOperationPredicate{}) +} + +// PrivateEndpointConnectionsPrivateLinkHubListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c PrivateLinkHubsClient) PrivateEndpointConnectionsPrivateLinkHubListCompleteMatchingPredicate(ctx context.Context, id PrivateLinkHubId, predicate PrivateEndpointConnectionForPrivateLinkHubOperationPredicate) (result PrivateEndpointConnectionsPrivateLinkHubListCompleteResult, err error) { + items := make([]PrivateEndpointConnectionForPrivateLinkHub, 0) + + resp, err := c.PrivateEndpointConnectionsPrivateLinkHubList(ctx, id) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = PrivateEndpointConnectionsPrivateLinkHubListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/synapse/2021-06-01/privatelinkhubs/method_update.go b/resource-manager/synapse/2021-06-01/privatelinkhubs/method_update.go new file mode 100644 index 00000000000..020191bb0a7 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/privatelinkhubs/method_update.go @@ -0,0 +1,56 @@ +package privatelinkhubs + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type UpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *PrivateLinkHub +} + +// Update ... +func (c PrivateLinkHubsClient) Update(ctx context.Context, id PrivateLinkHubId, input PrivateLinkHubPatchInfo) (result UpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPatch, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/synapse/2021-06-01/privatelinkhubs/model_privateendpoint.go b/resource-manager/synapse/2021-06-01/privatelinkhubs/model_privateendpoint.go new file mode 100644 index 00000000000..aae047b87aa --- /dev/null +++ b/resource-manager/synapse/2021-06-01/privatelinkhubs/model_privateendpoint.go @@ -0,0 +1,8 @@ +package privatelinkhubs + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateEndpoint struct { + Id *string `json:"id,omitempty"` +} diff --git a/resource-manager/synapse/2021-06-01/privatelinkhubs/model_privateendpointconnectionforprivatelinkhub.go b/resource-manager/synapse/2021-06-01/privatelinkhubs/model_privateendpointconnectionforprivatelinkhub.go new file mode 100644 index 00000000000..52290cb1481 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/privatelinkhubs/model_privateendpointconnectionforprivatelinkhub.go @@ -0,0 +1,11 @@ +package privatelinkhubs + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateEndpointConnectionForPrivateLinkHub struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *PrivateEndpointConnectionProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/synapse/2021-06-01/privatelinkhubs/model_privateendpointconnectionforprivatelinkhubbasic.go b/resource-manager/synapse/2021-06-01/privatelinkhubs/model_privateendpointconnectionforprivatelinkhubbasic.go new file mode 100644 index 00000000000..fadceef6dd9 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/privatelinkhubs/model_privateendpointconnectionforprivatelinkhubbasic.go @@ -0,0 +1,9 @@ +package privatelinkhubs + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateEndpointConnectionForPrivateLinkHubBasic struct { + Id *string `json:"id,omitempty"` + Properties *PrivateEndpointConnectionProperties `json:"properties,omitempty"` +} diff --git a/resource-manager/synapse/2021-06-01/privatelinkhubs/model_privateendpointconnectionproperties.go b/resource-manager/synapse/2021-06-01/privatelinkhubs/model_privateendpointconnectionproperties.go new file mode 100644 index 00000000000..e68c6c2091c --- /dev/null +++ b/resource-manager/synapse/2021-06-01/privatelinkhubs/model_privateendpointconnectionproperties.go @@ -0,0 +1,10 @@ +package privatelinkhubs + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateEndpointConnectionProperties struct { + PrivateEndpoint *PrivateEndpoint `json:"privateEndpoint,omitempty"` + PrivateLinkServiceConnectionState *PrivateLinkServiceConnectionState `json:"privateLinkServiceConnectionState,omitempty"` + ProvisioningState *string `json:"provisioningState,omitempty"` +} diff --git a/resource-manager/synapse/2021-06-01/privatelinkhubs/model_privatelinkhub.go b/resource-manager/synapse/2021-06-01/privatelinkhubs/model_privatelinkhub.go new file mode 100644 index 00000000000..c692f9357a7 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/privatelinkhubs/model_privatelinkhub.go @@ -0,0 +1,13 @@ +package privatelinkhubs + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateLinkHub struct { + Id *string `json:"id,omitempty"` + Location string `json:"location"` + Name *string `json:"name,omitempty"` + Properties *PrivateLinkHubProperties `json:"properties,omitempty"` + Tags *map[string]string `json:"tags,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/synapse/2021-06-01/privatelinkhubs/model_privatelinkhubpatchinfo.go b/resource-manager/synapse/2021-06-01/privatelinkhubs/model_privatelinkhubpatchinfo.go new file mode 100644 index 00000000000..fc00bf56f08 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/privatelinkhubs/model_privatelinkhubpatchinfo.go @@ -0,0 +1,8 @@ +package privatelinkhubs + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateLinkHubPatchInfo struct { + Tags *map[string]string `json:"tags,omitempty"` +} diff --git a/resource-manager/synapse/2021-06-01/privatelinkhubs/model_privatelinkhubproperties.go b/resource-manager/synapse/2021-06-01/privatelinkhubs/model_privatelinkhubproperties.go new file mode 100644 index 00000000000..60fd12d482e --- /dev/null +++ b/resource-manager/synapse/2021-06-01/privatelinkhubs/model_privatelinkhubproperties.go @@ -0,0 +1,9 @@ +package privatelinkhubs + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateLinkHubProperties struct { + PrivateEndpointConnections *[]PrivateEndpointConnectionForPrivateLinkHubBasic `json:"privateEndpointConnections,omitempty"` + ProvisioningState *string `json:"provisioningState,omitempty"` +} diff --git a/resource-manager/synapse/2021-06-01/privatelinkhubs/model_privatelinkserviceconnectionstate.go b/resource-manager/synapse/2021-06-01/privatelinkhubs/model_privatelinkserviceconnectionstate.go new file mode 100644 index 00000000000..75c7fd26d04 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/privatelinkhubs/model_privatelinkserviceconnectionstate.go @@ -0,0 +1,10 @@ +package privatelinkhubs + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateLinkServiceConnectionState struct { + ActionsRequired *string `json:"actionsRequired,omitempty"` + Description *string `json:"description,omitempty"` + Status *string `json:"status,omitempty"` +} diff --git a/resource-manager/synapse/2021-06-01/privatelinkhubs/predicates.go b/resource-manager/synapse/2021-06-01/privatelinkhubs/predicates.go new file mode 100644 index 00000000000..3226a287923 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/privatelinkhubs/predicates.go @@ -0,0 +1,55 @@ +package privatelinkhubs + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateEndpointConnectionForPrivateLinkHubOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p PrivateEndpointConnectionForPrivateLinkHubOperationPredicate) Matches(input PrivateEndpointConnectionForPrivateLinkHub) bool { + + if p.Id != nil && (input.Id == nil || *p.Id != *input.Id) { + return false + } + + if p.Name != nil && (input.Name == nil || *p.Name != *input.Name) { + return false + } + + if p.Type != nil && (input.Type == nil || *p.Type != *input.Type) { + return false + } + + return true +} + +type PrivateLinkHubOperationPredicate struct { + Id *string + Location *string + Name *string + Type *string +} + +func (p PrivateLinkHubOperationPredicate) Matches(input PrivateLinkHub) bool { + + if p.Id != nil && (input.Id == nil || *p.Id != *input.Id) { + return false + } + + if p.Location != nil && *p.Location != input.Location { + return false + } + + if p.Name != nil && (input.Name == nil || *p.Name != *input.Name) { + return false + } + + if p.Type != nil && (input.Type == nil || *p.Type != *input.Type) { + return false + } + + return true +} diff --git a/resource-manager/synapse/2021-06-01/privatelinkhubs/version.go b/resource-manager/synapse/2021-06-01/privatelinkhubs/version.go new file mode 100644 index 00000000000..9e7bbd29ff1 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/privatelinkhubs/version.go @@ -0,0 +1,12 @@ +package privatelinkhubs + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2021-06-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/privatelinkhubs/%s", defaultApiVersion) +} diff --git a/resource-manager/synapse/2021-06-01/privatelinkresources/README.md b/resource-manager/synapse/2021-06-01/privatelinkresources/README.md new file mode 100644 index 00000000000..a8d6ad30d67 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/privatelinkresources/README.md @@ -0,0 +1,53 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/synapse/2021-06-01/privatelinkresources` Documentation + +The `privatelinkresources` SDK allows for interaction with the Azure Resource Manager Service `synapse` (API Version `2021-06-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/synapse/2021-06-01/privatelinkresources" +``` + + +### Client Initialization + +```go +client := privatelinkresources.NewPrivateLinkResourcesClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `PrivateLinkResourcesClient.Get` + +```go +ctx := context.TODO() +id := privatelinkresources.NewPrivateLinkResourceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "privateLinkResourceValue") + +read, err := client.Get(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `PrivateLinkResourcesClient.List` + +```go +ctx := context.TODO() +id := privatelinkresources.NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue") + +// alternatively `client.List(ctx, id)` can be used to do batched pagination +items, err := client.ListComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/synapse/2021-06-01/privatelinkresources/client.go b/resource-manager/synapse/2021-06-01/privatelinkresources/client.go new file mode 100644 index 00000000000..e6e22caa746 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/privatelinkresources/client.go @@ -0,0 +1,26 @@ +package privatelinkresources + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateLinkResourcesClient struct { + Client *resourcemanager.Client +} + +func NewPrivateLinkResourcesClientWithBaseURI(sdkApi sdkEnv.Api) (*PrivateLinkResourcesClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "privatelinkresources", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating PrivateLinkResourcesClient: %+v", err) + } + + return &PrivateLinkResourcesClient{ + Client: client, + }, nil +} diff --git a/resource-manager/synapse/2021-06-01/privatelinkresources/id_privatelinkresource.go b/resource-manager/synapse/2021-06-01/privatelinkresources/id_privatelinkresource.go new file mode 100644 index 00000000000..e0d3aa1bfec --- /dev/null +++ b/resource-manager/synapse/2021-06-01/privatelinkresources/id_privatelinkresource.go @@ -0,0 +1,134 @@ +package privatelinkresources + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &PrivateLinkResourceId{} + +// PrivateLinkResourceId is a struct representing the Resource ID for a Private Link Resource +type PrivateLinkResourceId struct { + SubscriptionId string + ResourceGroupName string + WorkspaceName string + PrivateLinkResourceName string +} + +// NewPrivateLinkResourceID returns a new PrivateLinkResourceId struct +func NewPrivateLinkResourceID(subscriptionId string, resourceGroupName string, workspaceName string, privateLinkResourceName string) PrivateLinkResourceId { + return PrivateLinkResourceId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + WorkspaceName: workspaceName, + PrivateLinkResourceName: privateLinkResourceName, + } +} + +// ParsePrivateLinkResourceID parses 'input' into a PrivateLinkResourceId +func ParsePrivateLinkResourceID(input string) (*PrivateLinkResourceId, error) { + parser := resourceids.NewParserFromResourceIdType(&PrivateLinkResourceId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := PrivateLinkResourceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParsePrivateLinkResourceIDInsensitively parses 'input' case-insensitively into a PrivateLinkResourceId +// note: this method should only be used for API response data and not user input +func ParsePrivateLinkResourceIDInsensitively(input string) (*PrivateLinkResourceId, error) { + parser := resourceids.NewParserFromResourceIdType(&PrivateLinkResourceId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := PrivateLinkResourceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *PrivateLinkResourceId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.WorkspaceName, ok = input.Parsed["workspaceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "workspaceName", input) + } + + if id.PrivateLinkResourceName, ok = input.Parsed["privateLinkResourceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "privateLinkResourceName", input) + } + + return nil +} + +// ValidatePrivateLinkResourceID checks that 'input' can be parsed as a Private Link Resource ID +func ValidatePrivateLinkResourceID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParsePrivateLinkResourceID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Private Link Resource ID +func (id PrivateLinkResourceId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Synapse/workspaces/%s/privateLinkResources/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.WorkspaceName, id.PrivateLinkResourceName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Private Link Resource ID +func (id PrivateLinkResourceId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftSynapse", "Microsoft.Synapse", "Microsoft.Synapse"), + resourceids.StaticSegment("staticWorkspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceName", "workspaceValue"), + resourceids.StaticSegment("staticPrivateLinkResources", "privateLinkResources", "privateLinkResources"), + resourceids.UserSpecifiedSegment("privateLinkResourceName", "privateLinkResourceValue"), + } +} + +// String returns a human-readable description of this Private Link Resource ID +func (id PrivateLinkResourceId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Workspace Name: %q", id.WorkspaceName), + fmt.Sprintf("Private Link Resource Name: %q", id.PrivateLinkResourceName), + } + return fmt.Sprintf("Private Link Resource (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/synapse/2021-06-01/privatelinkresources/id_privatelinkresource_test.go b/resource-manager/synapse/2021-06-01/privatelinkresources/id_privatelinkresource_test.go new file mode 100644 index 00000000000..7ec86475653 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/privatelinkresources/id_privatelinkresource_test.go @@ -0,0 +1,327 @@ +package privatelinkresources + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &PrivateLinkResourceId{} + +func TestNewPrivateLinkResourceID(t *testing.T) { + id := NewPrivateLinkResourceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "privateLinkResourceValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.WorkspaceName != "workspaceValue" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceName'", id.WorkspaceName, "workspaceValue") + } + + if id.PrivateLinkResourceName != "privateLinkResourceValue" { + t.Fatalf("Expected %q but got %q for Segment 'PrivateLinkResourceName'", id.PrivateLinkResourceName, "privateLinkResourceValue") + } +} + +func TestFormatPrivateLinkResourceID(t *testing.T) { + actual := NewPrivateLinkResourceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "privateLinkResourceValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/privateLinkResources/privateLinkResourceValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParsePrivateLinkResourceID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *PrivateLinkResourceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/privateLinkResources", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/privateLinkResources/privateLinkResourceValue", + Expected: &PrivateLinkResourceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + PrivateLinkResourceName: "privateLinkResourceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/privateLinkResources/privateLinkResourceValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParsePrivateLinkResourceID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + if actual.PrivateLinkResourceName != v.Expected.PrivateLinkResourceName { + t.Fatalf("Expected %q but got %q for PrivateLinkResourceName", v.Expected.PrivateLinkResourceName, actual.PrivateLinkResourceName) + } + + } +} + +func TestParsePrivateLinkResourceIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *PrivateLinkResourceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/privateLinkResources", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/pRiVaTeLiNkReSoUrCeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/privateLinkResources/privateLinkResourceValue", + Expected: &PrivateLinkResourceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + PrivateLinkResourceName: "privateLinkResourceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/privateLinkResources/privateLinkResourceValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/pRiVaTeLiNkReSoUrCeS/pRiVaTeLiNkReSoUrCeVaLuE", + Expected: &PrivateLinkResourceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + WorkspaceName: "wOrKsPaCeVaLuE", + PrivateLinkResourceName: "pRiVaTeLiNkReSoUrCeVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/pRiVaTeLiNkReSoUrCeS/pRiVaTeLiNkReSoUrCeVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParsePrivateLinkResourceIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + if actual.PrivateLinkResourceName != v.Expected.PrivateLinkResourceName { + t.Fatalf("Expected %q but got %q for PrivateLinkResourceName", v.Expected.PrivateLinkResourceName, actual.PrivateLinkResourceName) + } + + } +} + +func TestSegmentsForPrivateLinkResourceId(t *testing.T) { + segments := PrivateLinkResourceId{}.Segments() + if len(segments) == 0 { + t.Fatalf("PrivateLinkResourceId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/synapse/2021-06-01/privatelinkresources/id_workspace.go b/resource-manager/synapse/2021-06-01/privatelinkresources/id_workspace.go new file mode 100644 index 00000000000..4e30cce5fe0 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/privatelinkresources/id_workspace.go @@ -0,0 +1,125 @@ +package privatelinkresources + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &WorkspaceId{} + +// WorkspaceId is a struct representing the Resource ID for a Workspace +type WorkspaceId struct { + SubscriptionId string + ResourceGroupName string + WorkspaceName string +} + +// NewWorkspaceID returns a new WorkspaceId struct +func NewWorkspaceID(subscriptionId string, resourceGroupName string, workspaceName string) WorkspaceId { + return WorkspaceId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + WorkspaceName: workspaceName, + } +} + +// ParseWorkspaceID parses 'input' into a WorkspaceId +func ParseWorkspaceID(input string) (*WorkspaceId, error) { + parser := resourceids.NewParserFromResourceIdType(&WorkspaceId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := WorkspaceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseWorkspaceIDInsensitively parses 'input' case-insensitively into a WorkspaceId +// note: this method should only be used for API response data and not user input +func ParseWorkspaceIDInsensitively(input string) (*WorkspaceId, error) { + parser := resourceids.NewParserFromResourceIdType(&WorkspaceId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := WorkspaceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *WorkspaceId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.WorkspaceName, ok = input.Parsed["workspaceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "workspaceName", input) + } + + return nil +} + +// ValidateWorkspaceID checks that 'input' can be parsed as a Workspace ID +func ValidateWorkspaceID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseWorkspaceID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Workspace ID +func (id WorkspaceId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Synapse/workspaces/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.WorkspaceName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Workspace ID +func (id WorkspaceId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftSynapse", "Microsoft.Synapse", "Microsoft.Synapse"), + resourceids.StaticSegment("staticWorkspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceName", "workspaceValue"), + } +} + +// String returns a human-readable description of this Workspace ID +func (id WorkspaceId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Workspace Name: %q", id.WorkspaceName), + } + return fmt.Sprintf("Workspace (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/synapse/2021-06-01/privatelinkresources/id_workspace_test.go b/resource-manager/synapse/2021-06-01/privatelinkresources/id_workspace_test.go new file mode 100644 index 00000000000..8f55bc9d0b0 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/privatelinkresources/id_workspace_test.go @@ -0,0 +1,282 @@ +package privatelinkresources + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &WorkspaceId{} + +func TestNewWorkspaceID(t *testing.T) { + id := NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.WorkspaceName != "workspaceValue" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceName'", id.WorkspaceName, "workspaceValue") + } +} + +func TestFormatWorkspaceID(t *testing.T) { + actual := NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseWorkspaceID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkspaceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue", + Expected: &WorkspaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkspaceID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + } +} + +func TestParseWorkspaceIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkspaceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue", + Expected: &WorkspaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE", + Expected: &WorkspaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + WorkspaceName: "wOrKsPaCeVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkspaceIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + } +} + +func TestSegmentsForWorkspaceId(t *testing.T) { + segments := WorkspaceId{}.Segments() + if len(segments) == 0 { + t.Fatalf("WorkspaceId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/synapse/2021-06-01/privatelinkresources/method_get.go b/resource-manager/synapse/2021-06-01/privatelinkresources/method_get.go new file mode 100644 index 00000000000..91ef7aa27f4 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/privatelinkresources/method_get.go @@ -0,0 +1,51 @@ +package privatelinkresources + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *PrivateLinkResource +} + +// Get ... +func (c PrivateLinkResourcesClient) Get(ctx context.Context, id PrivateLinkResourceId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/synapse/2021-06-01/privatelinkresources/method_list.go b/resource-manager/synapse/2021-06-01/privatelinkresources/method_list.go new file mode 100644 index 00000000000..893803d7e7c --- /dev/null +++ b/resource-manager/synapse/2021-06-01/privatelinkresources/method_list.go @@ -0,0 +1,91 @@ +package privatelinkresources + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]PrivateLinkResource +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []PrivateLinkResource +} + +// List ... +func (c PrivateLinkResourcesClient) List(ctx context.Context, id WorkspaceId) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/privateLinkResources", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]PrivateLinkResource `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListComplete retrieves all the results into a single object +func (c PrivateLinkResourcesClient) ListComplete(ctx context.Context, id WorkspaceId) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, PrivateLinkResourceOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c PrivateLinkResourcesClient) ListCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, predicate PrivateLinkResourceOperationPredicate) (result ListCompleteResult, err error) { + items := make([]PrivateLinkResource, 0) + + resp, err := c.List(ctx, id) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/synapse/2021-06-01/privatelinkresources/model_privatelinkresource.go b/resource-manager/synapse/2021-06-01/privatelinkresources/model_privatelinkresource.go new file mode 100644 index 00000000000..69e8ae0e57a --- /dev/null +++ b/resource-manager/synapse/2021-06-01/privatelinkresources/model_privatelinkresource.go @@ -0,0 +1,11 @@ +package privatelinkresources + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateLinkResource struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *PrivateLinkResourceProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/synapse/2021-06-01/privatelinkresources/model_privatelinkresourceproperties.go b/resource-manager/synapse/2021-06-01/privatelinkresources/model_privatelinkresourceproperties.go new file mode 100644 index 00000000000..3c98012cdd1 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/privatelinkresources/model_privatelinkresourceproperties.go @@ -0,0 +1,10 @@ +package privatelinkresources + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateLinkResourceProperties struct { + GroupId *string `json:"groupId,omitempty"` + RequiredMembers *[]string `json:"requiredMembers,omitempty"` + RequiredZoneNames *[]string `json:"requiredZoneNames,omitempty"` +} diff --git a/resource-manager/synapse/2021-06-01/privatelinkresources/predicates.go b/resource-manager/synapse/2021-06-01/privatelinkresources/predicates.go new file mode 100644 index 00000000000..19b771c3994 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/privatelinkresources/predicates.go @@ -0,0 +1,27 @@ +package privatelinkresources + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateLinkResourceOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p PrivateLinkResourceOperationPredicate) Matches(input PrivateLinkResource) bool { + + if p.Id != nil && (input.Id == nil || *p.Id != *input.Id) { + return false + } + + if p.Name != nil && (input.Name == nil || *p.Name != *input.Name) { + return false + } + + if p.Type != nil && (input.Type == nil || *p.Type != *input.Type) { + return false + } + + return true +} diff --git a/resource-manager/synapse/2021-06-01/privatelinkresources/version.go b/resource-manager/synapse/2021-06-01/privatelinkresources/version.go new file mode 100644 index 00000000000..4ee29f52669 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/privatelinkresources/version.go @@ -0,0 +1,12 @@ +package privatelinkresources + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2021-06-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/privatelinkresources/%s", defaultApiVersion) +} diff --git a/resource-manager/synapse/2021-06-01/recoverablesqlpools/README.md b/resource-manager/synapse/2021-06-01/recoverablesqlpools/README.md new file mode 100644 index 00000000000..2b930b39be4 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/recoverablesqlpools/README.md @@ -0,0 +1,53 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/synapse/2021-06-01/recoverablesqlpools` Documentation + +The `recoverablesqlpools` SDK allows for interaction with the Azure Resource Manager Service `synapse` (API Version `2021-06-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/synapse/2021-06-01/recoverablesqlpools" +``` + + +### Client Initialization + +```go +client := recoverablesqlpools.NewRecoverableSqlPoolsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `RecoverableSqlPoolsClient.WorkspaceManagedSqlServerRecoverableSqlPoolsGet` + +```go +ctx := context.TODO() +id := recoverablesqlpools.NewRecoverableSqlPoolID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "recoverableSqlPoolValue") + +read, err := client.WorkspaceManagedSqlServerRecoverableSqlPoolsGet(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `RecoverableSqlPoolsClient.WorkspaceManagedSqlServerRecoverableSqlPoolsList` + +```go +ctx := context.TODO() +id := recoverablesqlpools.NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue") + +// alternatively `client.WorkspaceManagedSqlServerRecoverableSqlPoolsList(ctx, id)` can be used to do batched pagination +items, err := client.WorkspaceManagedSqlServerRecoverableSqlPoolsListComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/synapse/2021-06-01/recoverablesqlpools/client.go b/resource-manager/synapse/2021-06-01/recoverablesqlpools/client.go new file mode 100644 index 00000000000..51c4725df89 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/recoverablesqlpools/client.go @@ -0,0 +1,26 @@ +package recoverablesqlpools + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RecoverableSqlPoolsClient struct { + Client *resourcemanager.Client +} + +func NewRecoverableSqlPoolsClientWithBaseURI(sdkApi sdkEnv.Api) (*RecoverableSqlPoolsClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "recoverablesqlpools", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating RecoverableSqlPoolsClient: %+v", err) + } + + return &RecoverableSqlPoolsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/synapse/2021-06-01/recoverablesqlpools/id_recoverablesqlpool.go b/resource-manager/synapse/2021-06-01/recoverablesqlpools/id_recoverablesqlpool.go new file mode 100644 index 00000000000..fc76511137e --- /dev/null +++ b/resource-manager/synapse/2021-06-01/recoverablesqlpools/id_recoverablesqlpool.go @@ -0,0 +1,134 @@ +package recoverablesqlpools + +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 = &RecoverableSqlPoolId{} + +// RecoverableSqlPoolId is a struct representing the Resource ID for a Recoverable Sql Pool +type RecoverableSqlPoolId struct { + SubscriptionId string + ResourceGroupName string + WorkspaceName string + RecoverableSqlPoolName string +} + +// NewRecoverableSqlPoolID returns a new RecoverableSqlPoolId struct +func NewRecoverableSqlPoolID(subscriptionId string, resourceGroupName string, workspaceName string, recoverableSqlPoolName string) RecoverableSqlPoolId { + return RecoverableSqlPoolId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + WorkspaceName: workspaceName, + RecoverableSqlPoolName: recoverableSqlPoolName, + } +} + +// ParseRecoverableSqlPoolID parses 'input' into a RecoverableSqlPoolId +func ParseRecoverableSqlPoolID(input string) (*RecoverableSqlPoolId, error) { + parser := resourceids.NewParserFromResourceIdType(&RecoverableSqlPoolId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := RecoverableSqlPoolId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseRecoverableSqlPoolIDInsensitively parses 'input' case-insensitively into a RecoverableSqlPoolId +// note: this method should only be used for API response data and not user input +func ParseRecoverableSqlPoolIDInsensitively(input string) (*RecoverableSqlPoolId, error) { + parser := resourceids.NewParserFromResourceIdType(&RecoverableSqlPoolId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := RecoverableSqlPoolId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *RecoverableSqlPoolId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.WorkspaceName, ok = input.Parsed["workspaceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "workspaceName", input) + } + + if id.RecoverableSqlPoolName, ok = input.Parsed["recoverableSqlPoolName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "recoverableSqlPoolName", input) + } + + return nil +} + +// ValidateRecoverableSqlPoolID checks that 'input' can be parsed as a Recoverable Sql Pool ID +func ValidateRecoverableSqlPoolID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseRecoverableSqlPoolID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Recoverable Sql Pool ID +func (id RecoverableSqlPoolId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Synapse/workspaces/%s/recoverableSqlPools/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.WorkspaceName, id.RecoverableSqlPoolName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Recoverable Sql Pool ID +func (id RecoverableSqlPoolId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftSynapse", "Microsoft.Synapse", "Microsoft.Synapse"), + resourceids.StaticSegment("staticWorkspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceName", "workspaceValue"), + resourceids.StaticSegment("staticRecoverableSqlPools", "recoverableSqlPools", "recoverableSqlPools"), + resourceids.UserSpecifiedSegment("recoverableSqlPoolName", "recoverableSqlPoolValue"), + } +} + +// String returns a human-readable description of this Recoverable Sql Pool ID +func (id RecoverableSqlPoolId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Workspace Name: %q", id.WorkspaceName), + fmt.Sprintf("Recoverable Sql Pool Name: %q", id.RecoverableSqlPoolName), + } + return fmt.Sprintf("Recoverable Sql Pool (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/synapse/2021-06-01/recoverablesqlpools/id_recoverablesqlpool_test.go b/resource-manager/synapse/2021-06-01/recoverablesqlpools/id_recoverablesqlpool_test.go new file mode 100644 index 00000000000..ca1d764dece --- /dev/null +++ b/resource-manager/synapse/2021-06-01/recoverablesqlpools/id_recoverablesqlpool_test.go @@ -0,0 +1,327 @@ +package recoverablesqlpools + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &RecoverableSqlPoolId{} + +func TestNewRecoverableSqlPoolID(t *testing.T) { + id := NewRecoverableSqlPoolID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "recoverableSqlPoolValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.WorkspaceName != "workspaceValue" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceName'", id.WorkspaceName, "workspaceValue") + } + + if id.RecoverableSqlPoolName != "recoverableSqlPoolValue" { + t.Fatalf("Expected %q but got %q for Segment 'RecoverableSqlPoolName'", id.RecoverableSqlPoolName, "recoverableSqlPoolValue") + } +} + +func TestFormatRecoverableSqlPoolID(t *testing.T) { + actual := NewRecoverableSqlPoolID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "recoverableSqlPoolValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/recoverableSqlPools/recoverableSqlPoolValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseRecoverableSqlPoolID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *RecoverableSqlPoolId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/recoverableSqlPools", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/recoverableSqlPools/recoverableSqlPoolValue", + Expected: &RecoverableSqlPoolId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + RecoverableSqlPoolName: "recoverableSqlPoolValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/recoverableSqlPools/recoverableSqlPoolValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseRecoverableSqlPoolID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + if actual.RecoverableSqlPoolName != v.Expected.RecoverableSqlPoolName { + t.Fatalf("Expected %q but got %q for RecoverableSqlPoolName", v.Expected.RecoverableSqlPoolName, actual.RecoverableSqlPoolName) + } + + } +} + +func TestParseRecoverableSqlPoolIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *RecoverableSqlPoolId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/recoverableSqlPools", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/rEcOvErAbLeSqLpOoLs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/recoverableSqlPools/recoverableSqlPoolValue", + Expected: &RecoverableSqlPoolId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + RecoverableSqlPoolName: "recoverableSqlPoolValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/recoverableSqlPools/recoverableSqlPoolValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/rEcOvErAbLeSqLpOoLs/rEcOvErAbLeSqLpOoLvAlUe", + Expected: &RecoverableSqlPoolId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + WorkspaceName: "wOrKsPaCeVaLuE", + RecoverableSqlPoolName: "rEcOvErAbLeSqLpOoLvAlUe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/rEcOvErAbLeSqLpOoLs/rEcOvErAbLeSqLpOoLvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseRecoverableSqlPoolIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + if actual.RecoverableSqlPoolName != v.Expected.RecoverableSqlPoolName { + t.Fatalf("Expected %q but got %q for RecoverableSqlPoolName", v.Expected.RecoverableSqlPoolName, actual.RecoverableSqlPoolName) + } + + } +} + +func TestSegmentsForRecoverableSqlPoolId(t *testing.T) { + segments := RecoverableSqlPoolId{}.Segments() + if len(segments) == 0 { + t.Fatalf("RecoverableSqlPoolId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/synapse/2021-06-01/recoverablesqlpools/id_workspace.go b/resource-manager/synapse/2021-06-01/recoverablesqlpools/id_workspace.go new file mode 100644 index 00000000000..9687c38b49e --- /dev/null +++ b/resource-manager/synapse/2021-06-01/recoverablesqlpools/id_workspace.go @@ -0,0 +1,125 @@ +package recoverablesqlpools + +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 = &WorkspaceId{} + +// WorkspaceId is a struct representing the Resource ID for a Workspace +type WorkspaceId struct { + SubscriptionId string + ResourceGroupName string + WorkspaceName string +} + +// NewWorkspaceID returns a new WorkspaceId struct +func NewWorkspaceID(subscriptionId string, resourceGroupName string, workspaceName string) WorkspaceId { + return WorkspaceId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + WorkspaceName: workspaceName, + } +} + +// ParseWorkspaceID parses 'input' into a WorkspaceId +func ParseWorkspaceID(input string) (*WorkspaceId, error) { + parser := resourceids.NewParserFromResourceIdType(&WorkspaceId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := WorkspaceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseWorkspaceIDInsensitively parses 'input' case-insensitively into a WorkspaceId +// note: this method should only be used for API response data and not user input +func ParseWorkspaceIDInsensitively(input string) (*WorkspaceId, error) { + parser := resourceids.NewParserFromResourceIdType(&WorkspaceId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := WorkspaceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *WorkspaceId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.WorkspaceName, ok = input.Parsed["workspaceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "workspaceName", input) + } + + return nil +} + +// ValidateWorkspaceID checks that 'input' can be parsed as a Workspace ID +func ValidateWorkspaceID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseWorkspaceID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Workspace ID +func (id WorkspaceId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Synapse/workspaces/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.WorkspaceName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Workspace ID +func (id WorkspaceId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftSynapse", "Microsoft.Synapse", "Microsoft.Synapse"), + resourceids.StaticSegment("staticWorkspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceName", "workspaceValue"), + } +} + +// String returns a human-readable description of this Workspace ID +func (id WorkspaceId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Workspace Name: %q", id.WorkspaceName), + } + return fmt.Sprintf("Workspace (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/synapse/2021-06-01/recoverablesqlpools/id_workspace_test.go b/resource-manager/synapse/2021-06-01/recoverablesqlpools/id_workspace_test.go new file mode 100644 index 00000000000..d023256cb4f --- /dev/null +++ b/resource-manager/synapse/2021-06-01/recoverablesqlpools/id_workspace_test.go @@ -0,0 +1,282 @@ +package recoverablesqlpools + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &WorkspaceId{} + +func TestNewWorkspaceID(t *testing.T) { + id := NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.WorkspaceName != "workspaceValue" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceName'", id.WorkspaceName, "workspaceValue") + } +} + +func TestFormatWorkspaceID(t *testing.T) { + actual := NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseWorkspaceID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkspaceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue", + Expected: &WorkspaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkspaceID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + } +} + +func TestParseWorkspaceIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkspaceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue", + Expected: &WorkspaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE", + Expected: &WorkspaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + WorkspaceName: "wOrKsPaCeVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkspaceIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + } +} + +func TestSegmentsForWorkspaceId(t *testing.T) { + segments := WorkspaceId{}.Segments() + if len(segments) == 0 { + t.Fatalf("WorkspaceId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/synapse/2021-06-01/recoverablesqlpools/method_workspacemanagedsqlserverrecoverablesqlpoolsget.go b/resource-manager/synapse/2021-06-01/recoverablesqlpools/method_workspacemanagedsqlserverrecoverablesqlpoolsget.go new file mode 100644 index 00000000000..af4602bad11 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/recoverablesqlpools/method_workspacemanagedsqlserverrecoverablesqlpoolsget.go @@ -0,0 +1,51 @@ +package recoverablesqlpools + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type WorkspaceManagedSqlServerRecoverableSqlPoolsGetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *RecoverableSqlPool +} + +// WorkspaceManagedSqlServerRecoverableSqlPoolsGet ... +func (c RecoverableSqlPoolsClient) WorkspaceManagedSqlServerRecoverableSqlPoolsGet(ctx context.Context, id RecoverableSqlPoolId) (result WorkspaceManagedSqlServerRecoverableSqlPoolsGetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/synapse/2021-06-01/recoverablesqlpools/method_workspacemanagedsqlserverrecoverablesqlpoolslist.go b/resource-manager/synapse/2021-06-01/recoverablesqlpools/method_workspacemanagedsqlserverrecoverablesqlpoolslist.go new file mode 100644 index 00000000000..bbd120457c9 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/recoverablesqlpools/method_workspacemanagedsqlserverrecoverablesqlpoolslist.go @@ -0,0 +1,91 @@ +package recoverablesqlpools + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type WorkspaceManagedSqlServerRecoverableSqlPoolsListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]RecoverableSqlPool +} + +type WorkspaceManagedSqlServerRecoverableSqlPoolsListCompleteResult struct { + LatestHttpResponse *http.Response + Items []RecoverableSqlPool +} + +// WorkspaceManagedSqlServerRecoverableSqlPoolsList ... +func (c RecoverableSqlPoolsClient) WorkspaceManagedSqlServerRecoverableSqlPoolsList(ctx context.Context, id WorkspaceId) (result WorkspaceManagedSqlServerRecoverableSqlPoolsListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/recoverableSqlPools", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]RecoverableSqlPool `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// WorkspaceManagedSqlServerRecoverableSqlPoolsListComplete retrieves all the results into a single object +func (c RecoverableSqlPoolsClient) WorkspaceManagedSqlServerRecoverableSqlPoolsListComplete(ctx context.Context, id WorkspaceId) (WorkspaceManagedSqlServerRecoverableSqlPoolsListCompleteResult, error) { + return c.WorkspaceManagedSqlServerRecoverableSqlPoolsListCompleteMatchingPredicate(ctx, id, RecoverableSqlPoolOperationPredicate{}) +} + +// WorkspaceManagedSqlServerRecoverableSqlPoolsListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c RecoverableSqlPoolsClient) WorkspaceManagedSqlServerRecoverableSqlPoolsListCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, predicate RecoverableSqlPoolOperationPredicate) (result WorkspaceManagedSqlServerRecoverableSqlPoolsListCompleteResult, err error) { + items := make([]RecoverableSqlPool, 0) + + resp, err := c.WorkspaceManagedSqlServerRecoverableSqlPoolsList(ctx, id) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = WorkspaceManagedSqlServerRecoverableSqlPoolsListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/synapse/2021-06-01/recoverablesqlpools/model_recoverablesqlpool.go b/resource-manager/synapse/2021-06-01/recoverablesqlpools/model_recoverablesqlpool.go new file mode 100644 index 00000000000..5a87f72d977 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/recoverablesqlpools/model_recoverablesqlpool.go @@ -0,0 +1,11 @@ +package recoverablesqlpools + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RecoverableSqlPool struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *RecoverableSqlPoolProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/synapse/2021-06-01/recoverablesqlpools/model_recoverablesqlpoolproperties.go b/resource-manager/synapse/2021-06-01/recoverablesqlpools/model_recoverablesqlpoolproperties.go new file mode 100644 index 00000000000..1e93ffb5fc5 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/recoverablesqlpools/model_recoverablesqlpoolproperties.go @@ -0,0 +1,29 @@ +package recoverablesqlpools + +import ( + "time" + + "github.com/hashicorp/go-azure-helpers/lang/dates" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RecoverableSqlPoolProperties struct { + Edition *string `json:"edition,omitempty"` + ElasticPoolName *string `json:"elasticPoolName,omitempty"` + LastAvailableBackupDate *string `json:"lastAvailableBackupDate,omitempty"` + ServiceLevelObjective *string `json:"serviceLevelObjective,omitempty"` +} + +func (o *RecoverableSqlPoolProperties) GetLastAvailableBackupDateAsTime() (*time.Time, error) { + if o.LastAvailableBackupDate == nil { + return nil, nil + } + return dates.ParseAsFormat(o.LastAvailableBackupDate, "2006-01-02T15:04:05Z07:00") +} + +func (o *RecoverableSqlPoolProperties) SetLastAvailableBackupDateAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.LastAvailableBackupDate = &formatted +} diff --git a/resource-manager/synapse/2021-06-01/recoverablesqlpools/predicates.go b/resource-manager/synapse/2021-06-01/recoverablesqlpools/predicates.go new file mode 100644 index 00000000000..b8c6e86ad4c --- /dev/null +++ b/resource-manager/synapse/2021-06-01/recoverablesqlpools/predicates.go @@ -0,0 +1,27 @@ +package recoverablesqlpools + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RecoverableSqlPoolOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p RecoverableSqlPoolOperationPredicate) Matches(input RecoverableSqlPool) bool { + + if p.Id != nil && (input.Id == nil || *p.Id != *input.Id) { + return false + } + + if p.Name != nil && (input.Name == nil || *p.Name != *input.Name) { + return false + } + + if p.Type != nil && (input.Type == nil || *p.Type != *input.Type) { + return false + } + + return true +} diff --git a/resource-manager/synapse/2021-06-01/recoverablesqlpools/version.go b/resource-manager/synapse/2021-06-01/recoverablesqlpools/version.go new file mode 100644 index 00000000000..39235cf8b4e --- /dev/null +++ b/resource-manager/synapse/2021-06-01/recoverablesqlpools/version.go @@ -0,0 +1,12 @@ +package recoverablesqlpools + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2021-06-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/recoverablesqlpools/%s", defaultApiVersion) +} diff --git a/resource-manager/synapse/2021-06-01/restorabledroppedsqlpools/README.md b/resource-manager/synapse/2021-06-01/restorabledroppedsqlpools/README.md new file mode 100644 index 00000000000..599e9ca09d5 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/restorabledroppedsqlpools/README.md @@ -0,0 +1,52 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/synapse/2021-06-01/restorabledroppedsqlpools` Documentation + +The `restorabledroppedsqlpools` SDK allows for interaction with the Azure Resource Manager Service `synapse` (API Version `2021-06-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/synapse/2021-06-01/restorabledroppedsqlpools" +``` + + +### Client Initialization + +```go +client := restorabledroppedsqlpools.NewRestorableDroppedSqlPoolsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `RestorableDroppedSqlPoolsClient.Get` + +```go +ctx := context.TODO() +id := restorabledroppedsqlpools.NewRestorableDroppedSqlPoolID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "restorableDroppedSqlPoolIdValue") + +read, err := client.Get(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `RestorableDroppedSqlPoolsClient.ListByWorkspace` + +```go +ctx := context.TODO() +id := restorabledroppedsqlpools.NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue") + +read, err := client.ListByWorkspace(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` diff --git a/resource-manager/synapse/2021-06-01/restorabledroppedsqlpools/client.go b/resource-manager/synapse/2021-06-01/restorabledroppedsqlpools/client.go new file mode 100644 index 00000000000..80489b66b37 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/restorabledroppedsqlpools/client.go @@ -0,0 +1,26 @@ +package restorabledroppedsqlpools + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RestorableDroppedSqlPoolsClient struct { + Client *resourcemanager.Client +} + +func NewRestorableDroppedSqlPoolsClientWithBaseURI(sdkApi sdkEnv.Api) (*RestorableDroppedSqlPoolsClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "restorabledroppedsqlpools", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating RestorableDroppedSqlPoolsClient: %+v", err) + } + + return &RestorableDroppedSqlPoolsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/synapse/2021-06-01/restorabledroppedsqlpools/id_restorabledroppedsqlpool.go b/resource-manager/synapse/2021-06-01/restorabledroppedsqlpools/id_restorabledroppedsqlpool.go new file mode 100644 index 00000000000..580fe39456c --- /dev/null +++ b/resource-manager/synapse/2021-06-01/restorabledroppedsqlpools/id_restorabledroppedsqlpool.go @@ -0,0 +1,134 @@ +package restorabledroppedsqlpools + +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 = &RestorableDroppedSqlPoolId{} + +// RestorableDroppedSqlPoolId is a struct representing the Resource ID for a Restorable Dropped Sql Pool +type RestorableDroppedSqlPoolId struct { + SubscriptionId string + ResourceGroupName string + WorkspaceName string + RestorableDroppedSqlPoolId string +} + +// NewRestorableDroppedSqlPoolID returns a new RestorableDroppedSqlPoolId struct +func NewRestorableDroppedSqlPoolID(subscriptionId string, resourceGroupName string, workspaceName string, restorableDroppedSqlPoolId string) RestorableDroppedSqlPoolId { + return RestorableDroppedSqlPoolId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + WorkspaceName: workspaceName, + RestorableDroppedSqlPoolId: restorableDroppedSqlPoolId, + } +} + +// ParseRestorableDroppedSqlPoolID parses 'input' into a RestorableDroppedSqlPoolId +func ParseRestorableDroppedSqlPoolID(input string) (*RestorableDroppedSqlPoolId, error) { + parser := resourceids.NewParserFromResourceIdType(&RestorableDroppedSqlPoolId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := RestorableDroppedSqlPoolId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseRestorableDroppedSqlPoolIDInsensitively parses 'input' case-insensitively into a RestorableDroppedSqlPoolId +// note: this method should only be used for API response data and not user input +func ParseRestorableDroppedSqlPoolIDInsensitively(input string) (*RestorableDroppedSqlPoolId, error) { + parser := resourceids.NewParserFromResourceIdType(&RestorableDroppedSqlPoolId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := RestorableDroppedSqlPoolId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *RestorableDroppedSqlPoolId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.WorkspaceName, ok = input.Parsed["workspaceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "workspaceName", input) + } + + if id.RestorableDroppedSqlPoolId, ok = input.Parsed["restorableDroppedSqlPoolId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "restorableDroppedSqlPoolId", input) + } + + return nil +} + +// ValidateRestorableDroppedSqlPoolID checks that 'input' can be parsed as a Restorable Dropped Sql Pool ID +func ValidateRestorableDroppedSqlPoolID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseRestorableDroppedSqlPoolID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Restorable Dropped Sql Pool ID +func (id RestorableDroppedSqlPoolId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Synapse/workspaces/%s/restorableDroppedSqlPools/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.WorkspaceName, id.RestorableDroppedSqlPoolId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Restorable Dropped Sql Pool ID +func (id RestorableDroppedSqlPoolId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftSynapse", "Microsoft.Synapse", "Microsoft.Synapse"), + resourceids.StaticSegment("staticWorkspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceName", "workspaceValue"), + resourceids.StaticSegment("staticRestorableDroppedSqlPools", "restorableDroppedSqlPools", "restorableDroppedSqlPools"), + resourceids.UserSpecifiedSegment("restorableDroppedSqlPoolId", "restorableDroppedSqlPoolIdValue"), + } +} + +// String returns a human-readable description of this Restorable Dropped Sql Pool ID +func (id RestorableDroppedSqlPoolId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Workspace Name: %q", id.WorkspaceName), + fmt.Sprintf("Restorable Dropped Sql Pool: %q", id.RestorableDroppedSqlPoolId), + } + return fmt.Sprintf("Restorable Dropped Sql Pool (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/synapse/2021-06-01/restorabledroppedsqlpools/id_restorabledroppedsqlpool_test.go b/resource-manager/synapse/2021-06-01/restorabledroppedsqlpools/id_restorabledroppedsqlpool_test.go new file mode 100644 index 00000000000..11bbf539122 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/restorabledroppedsqlpools/id_restorabledroppedsqlpool_test.go @@ -0,0 +1,327 @@ +package restorabledroppedsqlpools + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &RestorableDroppedSqlPoolId{} + +func TestNewRestorableDroppedSqlPoolID(t *testing.T) { + id := NewRestorableDroppedSqlPoolID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "restorableDroppedSqlPoolIdValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.WorkspaceName != "workspaceValue" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceName'", id.WorkspaceName, "workspaceValue") + } + + if id.RestorableDroppedSqlPoolId != "restorableDroppedSqlPoolIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'RestorableDroppedSqlPoolId'", id.RestorableDroppedSqlPoolId, "restorableDroppedSqlPoolIdValue") + } +} + +func TestFormatRestorableDroppedSqlPoolID(t *testing.T) { + actual := NewRestorableDroppedSqlPoolID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "restorableDroppedSqlPoolIdValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/restorableDroppedSqlPools/restorableDroppedSqlPoolIdValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseRestorableDroppedSqlPoolID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *RestorableDroppedSqlPoolId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/restorableDroppedSqlPools", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/restorableDroppedSqlPools/restorableDroppedSqlPoolIdValue", + Expected: &RestorableDroppedSqlPoolId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + RestorableDroppedSqlPoolId: "restorableDroppedSqlPoolIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/restorableDroppedSqlPools/restorableDroppedSqlPoolIdValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseRestorableDroppedSqlPoolID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + if actual.RestorableDroppedSqlPoolId != v.Expected.RestorableDroppedSqlPoolId { + t.Fatalf("Expected %q but got %q for RestorableDroppedSqlPoolId", v.Expected.RestorableDroppedSqlPoolId, actual.RestorableDroppedSqlPoolId) + } + + } +} + +func TestParseRestorableDroppedSqlPoolIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *RestorableDroppedSqlPoolId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/restorableDroppedSqlPools", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/rEsToRaBlEdRoPpEdSqLpOoLs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/restorableDroppedSqlPools/restorableDroppedSqlPoolIdValue", + Expected: &RestorableDroppedSqlPoolId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + RestorableDroppedSqlPoolId: "restorableDroppedSqlPoolIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/restorableDroppedSqlPools/restorableDroppedSqlPoolIdValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/rEsToRaBlEdRoPpEdSqLpOoLs/rEsToRaBlEdRoPpEdSqLpOoLiDvAlUe", + Expected: &RestorableDroppedSqlPoolId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + WorkspaceName: "wOrKsPaCeVaLuE", + RestorableDroppedSqlPoolId: "rEsToRaBlEdRoPpEdSqLpOoLiDvAlUe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/rEsToRaBlEdRoPpEdSqLpOoLs/rEsToRaBlEdRoPpEdSqLpOoLiDvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseRestorableDroppedSqlPoolIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + if actual.RestorableDroppedSqlPoolId != v.Expected.RestorableDroppedSqlPoolId { + t.Fatalf("Expected %q but got %q for RestorableDroppedSqlPoolId", v.Expected.RestorableDroppedSqlPoolId, actual.RestorableDroppedSqlPoolId) + } + + } +} + +func TestSegmentsForRestorableDroppedSqlPoolId(t *testing.T) { + segments := RestorableDroppedSqlPoolId{}.Segments() + if len(segments) == 0 { + t.Fatalf("RestorableDroppedSqlPoolId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/synapse/2021-06-01/restorabledroppedsqlpools/id_workspace.go b/resource-manager/synapse/2021-06-01/restorabledroppedsqlpools/id_workspace.go new file mode 100644 index 00000000000..c8b8071cc07 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/restorabledroppedsqlpools/id_workspace.go @@ -0,0 +1,125 @@ +package restorabledroppedsqlpools + +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 = &WorkspaceId{} + +// WorkspaceId is a struct representing the Resource ID for a Workspace +type WorkspaceId struct { + SubscriptionId string + ResourceGroupName string + WorkspaceName string +} + +// NewWorkspaceID returns a new WorkspaceId struct +func NewWorkspaceID(subscriptionId string, resourceGroupName string, workspaceName string) WorkspaceId { + return WorkspaceId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + WorkspaceName: workspaceName, + } +} + +// ParseWorkspaceID parses 'input' into a WorkspaceId +func ParseWorkspaceID(input string) (*WorkspaceId, error) { + parser := resourceids.NewParserFromResourceIdType(&WorkspaceId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := WorkspaceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseWorkspaceIDInsensitively parses 'input' case-insensitively into a WorkspaceId +// note: this method should only be used for API response data and not user input +func ParseWorkspaceIDInsensitively(input string) (*WorkspaceId, error) { + parser := resourceids.NewParserFromResourceIdType(&WorkspaceId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := WorkspaceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *WorkspaceId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.WorkspaceName, ok = input.Parsed["workspaceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "workspaceName", input) + } + + return nil +} + +// ValidateWorkspaceID checks that 'input' can be parsed as a Workspace ID +func ValidateWorkspaceID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseWorkspaceID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Workspace ID +func (id WorkspaceId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Synapse/workspaces/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.WorkspaceName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Workspace ID +func (id WorkspaceId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftSynapse", "Microsoft.Synapse", "Microsoft.Synapse"), + resourceids.StaticSegment("staticWorkspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceName", "workspaceValue"), + } +} + +// String returns a human-readable description of this Workspace ID +func (id WorkspaceId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Workspace Name: %q", id.WorkspaceName), + } + return fmt.Sprintf("Workspace (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/synapse/2021-06-01/restorabledroppedsqlpools/id_workspace_test.go b/resource-manager/synapse/2021-06-01/restorabledroppedsqlpools/id_workspace_test.go new file mode 100644 index 00000000000..ea4982ef27f --- /dev/null +++ b/resource-manager/synapse/2021-06-01/restorabledroppedsqlpools/id_workspace_test.go @@ -0,0 +1,282 @@ +package restorabledroppedsqlpools + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &WorkspaceId{} + +func TestNewWorkspaceID(t *testing.T) { + id := NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.WorkspaceName != "workspaceValue" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceName'", id.WorkspaceName, "workspaceValue") + } +} + +func TestFormatWorkspaceID(t *testing.T) { + actual := NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseWorkspaceID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkspaceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue", + Expected: &WorkspaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkspaceID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + } +} + +func TestParseWorkspaceIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkspaceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue", + Expected: &WorkspaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE", + Expected: &WorkspaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + WorkspaceName: "wOrKsPaCeVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkspaceIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + } +} + +func TestSegmentsForWorkspaceId(t *testing.T) { + segments := WorkspaceId{}.Segments() + if len(segments) == 0 { + t.Fatalf("WorkspaceId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/synapse/2021-06-01/restorabledroppedsqlpools/method_get.go b/resource-manager/synapse/2021-06-01/restorabledroppedsqlpools/method_get.go new file mode 100644 index 00000000000..4076d8a693a --- /dev/null +++ b/resource-manager/synapse/2021-06-01/restorabledroppedsqlpools/method_get.go @@ -0,0 +1,51 @@ +package restorabledroppedsqlpools + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *RestorableDroppedSqlPool +} + +// Get ... +func (c RestorableDroppedSqlPoolsClient) Get(ctx context.Context, id RestorableDroppedSqlPoolId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/synapse/2021-06-01/restorabledroppedsqlpools/method_listbyworkspace.go b/resource-manager/synapse/2021-06-01/restorabledroppedsqlpools/method_listbyworkspace.go new file mode 100644 index 00000000000..ba7491a8ee2 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/restorabledroppedsqlpools/method_listbyworkspace.go @@ -0,0 +1,52 @@ +package restorabledroppedsqlpools + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListByWorkspaceOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *RestorableDroppedSqlPoolListResult +} + +// ListByWorkspace ... +func (c RestorableDroppedSqlPoolsClient) ListByWorkspace(ctx context.Context, id WorkspaceId) (result ListByWorkspaceOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/restorableDroppedSqlPools", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/synapse/2021-06-01/restorabledroppedsqlpools/model_restorabledroppedsqlpool.go b/resource-manager/synapse/2021-06-01/restorabledroppedsqlpools/model_restorabledroppedsqlpool.go new file mode 100644 index 00000000000..0376e6ce103 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/restorabledroppedsqlpools/model_restorabledroppedsqlpool.go @@ -0,0 +1,12 @@ +package restorabledroppedsqlpools + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RestorableDroppedSqlPool struct { + Id *string `json:"id,omitempty"` + Location *string `json:"location,omitempty"` + Name *string `json:"name,omitempty"` + Properties *RestorableDroppedSqlPoolProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/synapse/2021-06-01/restorabledroppedsqlpools/model_restorabledroppedsqlpoollistresult.go b/resource-manager/synapse/2021-06-01/restorabledroppedsqlpools/model_restorabledroppedsqlpoollistresult.go new file mode 100644 index 00000000000..d6b81f49aea --- /dev/null +++ b/resource-manager/synapse/2021-06-01/restorabledroppedsqlpools/model_restorabledroppedsqlpoollistresult.go @@ -0,0 +1,8 @@ +package restorabledroppedsqlpools + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RestorableDroppedSqlPoolListResult struct { + Value []RestorableDroppedSqlPool `json:"value"` +} diff --git a/resource-manager/synapse/2021-06-01/restorabledroppedsqlpools/model_restorabledroppedsqlpoolproperties.go b/resource-manager/synapse/2021-06-01/restorabledroppedsqlpools/model_restorabledroppedsqlpoolproperties.go new file mode 100644 index 00000000000..d810dde077a --- /dev/null +++ b/resource-manager/synapse/2021-06-01/restorabledroppedsqlpools/model_restorabledroppedsqlpoolproperties.go @@ -0,0 +1,57 @@ +package restorabledroppedsqlpools + +import ( + "time" + + "github.com/hashicorp/go-azure-helpers/lang/dates" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RestorableDroppedSqlPoolProperties struct { + CreationDate *string `json:"creationDate,omitempty"` + DatabaseName *string `json:"databaseName,omitempty"` + DeletionDate *string `json:"deletionDate,omitempty"` + EarliestRestoreDate *string `json:"earliestRestoreDate,omitempty"` + Edition *string `json:"edition,omitempty"` + ElasticPoolName *string `json:"elasticPoolName,omitempty"` + MaxSizeBytes *string `json:"maxSizeBytes,omitempty"` + ServiceLevelObjective *string `json:"serviceLevelObjective,omitempty"` +} + +func (o *RestorableDroppedSqlPoolProperties) GetCreationDateAsTime() (*time.Time, error) { + if o.CreationDate == nil { + return nil, nil + } + return dates.ParseAsFormat(o.CreationDate, "2006-01-02T15:04:05Z07:00") +} + +func (o *RestorableDroppedSqlPoolProperties) SetCreationDateAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.CreationDate = &formatted +} + +func (o *RestorableDroppedSqlPoolProperties) GetDeletionDateAsTime() (*time.Time, error) { + if o.DeletionDate == nil { + return nil, nil + } + return dates.ParseAsFormat(o.DeletionDate, "2006-01-02T15:04:05Z07:00") +} + +func (o *RestorableDroppedSqlPoolProperties) SetDeletionDateAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.DeletionDate = &formatted +} + +func (o *RestorableDroppedSqlPoolProperties) GetEarliestRestoreDateAsTime() (*time.Time, error) { + if o.EarliestRestoreDate == nil { + return nil, nil + } + return dates.ParseAsFormat(o.EarliestRestoreDate, "2006-01-02T15:04:05Z07:00") +} + +func (o *RestorableDroppedSqlPoolProperties) SetEarliestRestoreDateAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.EarliestRestoreDate = &formatted +} diff --git a/resource-manager/synapse/2021-06-01/restorabledroppedsqlpools/version.go b/resource-manager/synapse/2021-06-01/restorabledroppedsqlpools/version.go new file mode 100644 index 00000000000..f9cc6b02a06 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/restorabledroppedsqlpools/version.go @@ -0,0 +1,12 @@ +package restorabledroppedsqlpools + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2021-06-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/restorabledroppedsqlpools/%s", defaultApiVersion) +} diff --git a/resource-manager/synapse/2021-06-01/sensitivitylabels/client.go b/resource-manager/synapse/2021-06-01/sensitivitylabels/client.go new file mode 100644 index 00000000000..b4f48c1b8f8 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sensitivitylabels/client.go @@ -0,0 +1,26 @@ +package sensitivitylabels + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SensitivityLabelsClient struct { + Client *resourcemanager.Client +} + +func NewSensitivityLabelsClientWithBaseURI(sdkApi sdkEnv.Api) (*SensitivityLabelsClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "sensitivitylabels", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating SensitivityLabelsClient: %+v", err) + } + + return &SensitivityLabelsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/synapse/2021-06-01/sensitivitylabels/id_column.go b/resource-manager/synapse/2021-06-01/sensitivitylabels/id_column.go new file mode 100644 index 00000000000..07fd0757549 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sensitivitylabels/id_column.go @@ -0,0 +1,161 @@ +package sensitivitylabels + +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 = &ColumnId{} + +// ColumnId is a struct representing the Resource ID for a Column +type ColumnId struct { + SubscriptionId string + ResourceGroupName string + WorkspaceName string + SqlPoolName string + SchemaName string + TableName string + ColumnName string +} + +// NewColumnID returns a new ColumnId struct +func NewColumnID(subscriptionId string, resourceGroupName string, workspaceName string, sqlPoolName string, schemaName string, tableName string, columnName string) ColumnId { + return ColumnId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + WorkspaceName: workspaceName, + SqlPoolName: sqlPoolName, + SchemaName: schemaName, + TableName: tableName, + ColumnName: columnName, + } +} + +// ParseColumnID parses 'input' into a ColumnId +func ParseColumnID(input string) (*ColumnId, error) { + parser := resourceids.NewParserFromResourceIdType(&ColumnId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ColumnId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseColumnIDInsensitively parses 'input' case-insensitively into a ColumnId +// note: this method should only be used for API response data and not user input +func ParseColumnIDInsensitively(input string) (*ColumnId, error) { + parser := resourceids.NewParserFromResourceIdType(&ColumnId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ColumnId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ColumnId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.WorkspaceName, ok = input.Parsed["workspaceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "workspaceName", input) + } + + if id.SqlPoolName, ok = input.Parsed["sqlPoolName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "sqlPoolName", input) + } + + if id.SchemaName, ok = input.Parsed["schemaName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "schemaName", input) + } + + if id.TableName, ok = input.Parsed["tableName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "tableName", input) + } + + if id.ColumnName, ok = input.Parsed["columnName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "columnName", input) + } + + return nil +} + +// ValidateColumnID checks that 'input' can be parsed as a Column ID +func ValidateColumnID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseColumnID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Column ID +func (id ColumnId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Synapse/workspaces/%s/sqlPools/%s/schemas/%s/tables/%s/columns/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.WorkspaceName, id.SqlPoolName, id.SchemaName, id.TableName, id.ColumnName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Column ID +func (id ColumnId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftSynapse", "Microsoft.Synapse", "Microsoft.Synapse"), + resourceids.StaticSegment("staticWorkspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceName", "workspaceValue"), + resourceids.StaticSegment("staticSqlPools", "sqlPools", "sqlPools"), + resourceids.UserSpecifiedSegment("sqlPoolName", "sqlPoolValue"), + resourceids.StaticSegment("staticSchemas", "schemas", "schemas"), + resourceids.UserSpecifiedSegment("schemaName", "schemaValue"), + resourceids.StaticSegment("staticTables", "tables", "tables"), + resourceids.UserSpecifiedSegment("tableName", "tableValue"), + resourceids.StaticSegment("staticColumns", "columns", "columns"), + resourceids.UserSpecifiedSegment("columnName", "columnValue"), + } +} + +// String returns a human-readable description of this Column ID +func (id ColumnId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Workspace Name: %q", id.WorkspaceName), + fmt.Sprintf("Sql Pool Name: %q", id.SqlPoolName), + fmt.Sprintf("Schema Name: %q", id.SchemaName), + fmt.Sprintf("Table Name: %q", id.TableName), + fmt.Sprintf("Column Name: %q", id.ColumnName), + } + return fmt.Sprintf("Column (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/synapse/2021-06-01/sensitivitylabels/id_column_test.go b/resource-manager/synapse/2021-06-01/sensitivitylabels/id_column_test.go new file mode 100644 index 00000000000..ff3e104db64 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sensitivitylabels/id_column_test.go @@ -0,0 +1,462 @@ +package sensitivitylabels + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &ColumnId{} + +func TestNewColumnID(t *testing.T) { + id := NewColumnID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "sqlPoolValue", "schemaValue", "tableValue", "columnValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.WorkspaceName != "workspaceValue" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceName'", id.WorkspaceName, "workspaceValue") + } + + if id.SqlPoolName != "sqlPoolValue" { + t.Fatalf("Expected %q but got %q for Segment 'SqlPoolName'", id.SqlPoolName, "sqlPoolValue") + } + + if id.SchemaName != "schemaValue" { + t.Fatalf("Expected %q but got %q for Segment 'SchemaName'", id.SchemaName, "schemaValue") + } + + if id.TableName != "tableValue" { + t.Fatalf("Expected %q but got %q for Segment 'TableName'", id.TableName, "tableValue") + } + + if id.ColumnName != "columnValue" { + t.Fatalf("Expected %q but got %q for Segment 'ColumnName'", id.ColumnName, "columnValue") + } +} + +func TestFormatColumnID(t *testing.T) { + actual := NewColumnID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "sqlPoolValue", "schemaValue", "tableValue", "columnValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/schemas/schemaValue/tables/tableValue/columns/columnValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseColumnID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ColumnId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/schemas", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/schemas/schemaValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/schemas/schemaValue/tables", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/schemas/schemaValue/tables/tableValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/schemas/schemaValue/tables/tableValue/columns", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/schemas/schemaValue/tables/tableValue/columns/columnValue", + Expected: &ColumnId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + SqlPoolName: "sqlPoolValue", + SchemaName: "schemaValue", + TableName: "tableValue", + ColumnName: "columnValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/schemas/schemaValue/tables/tableValue/columns/columnValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseColumnID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + if actual.SqlPoolName != v.Expected.SqlPoolName { + t.Fatalf("Expected %q but got %q for SqlPoolName", v.Expected.SqlPoolName, actual.SqlPoolName) + } + + if actual.SchemaName != v.Expected.SchemaName { + t.Fatalf("Expected %q but got %q for SchemaName", v.Expected.SchemaName, actual.SchemaName) + } + + if actual.TableName != v.Expected.TableName { + t.Fatalf("Expected %q but got %q for TableName", v.Expected.TableName, actual.TableName) + } + + if actual.ColumnName != v.Expected.ColumnName { + t.Fatalf("Expected %q but got %q for ColumnName", v.Expected.ColumnName, actual.ColumnName) + } + + } +} + +func TestParseColumnIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ColumnId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/sQlPoOlS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/sQlPoOlS/sQlPoOlVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/schemas", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/sQlPoOlS/sQlPoOlVaLuE/sChEmAs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/schemas/schemaValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/sQlPoOlS/sQlPoOlVaLuE/sChEmAs/sChEmAvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/schemas/schemaValue/tables", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/sQlPoOlS/sQlPoOlVaLuE/sChEmAs/sChEmAvAlUe/tAbLeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/schemas/schemaValue/tables/tableValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/sQlPoOlS/sQlPoOlVaLuE/sChEmAs/sChEmAvAlUe/tAbLeS/tAbLeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/schemas/schemaValue/tables/tableValue/columns", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/sQlPoOlS/sQlPoOlVaLuE/sChEmAs/sChEmAvAlUe/tAbLeS/tAbLeVaLuE/cOlUmNs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/schemas/schemaValue/tables/tableValue/columns/columnValue", + Expected: &ColumnId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + SqlPoolName: "sqlPoolValue", + SchemaName: "schemaValue", + TableName: "tableValue", + ColumnName: "columnValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/schemas/schemaValue/tables/tableValue/columns/columnValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/sQlPoOlS/sQlPoOlVaLuE/sChEmAs/sChEmAvAlUe/tAbLeS/tAbLeVaLuE/cOlUmNs/cOlUmNvAlUe", + Expected: &ColumnId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + WorkspaceName: "wOrKsPaCeVaLuE", + SqlPoolName: "sQlPoOlVaLuE", + SchemaName: "sChEmAvAlUe", + TableName: "tAbLeVaLuE", + ColumnName: "cOlUmNvAlUe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/sQlPoOlS/sQlPoOlVaLuE/sChEmAs/sChEmAvAlUe/tAbLeS/tAbLeVaLuE/cOlUmNs/cOlUmNvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseColumnIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + if actual.SqlPoolName != v.Expected.SqlPoolName { + t.Fatalf("Expected %q but got %q for SqlPoolName", v.Expected.SqlPoolName, actual.SqlPoolName) + } + + if actual.SchemaName != v.Expected.SchemaName { + t.Fatalf("Expected %q but got %q for SchemaName", v.Expected.SchemaName, actual.SchemaName) + } + + if actual.TableName != v.Expected.TableName { + t.Fatalf("Expected %q but got %q for TableName", v.Expected.TableName, actual.TableName) + } + + if actual.ColumnName != v.Expected.ColumnName { + t.Fatalf("Expected %q but got %q for ColumnName", v.Expected.ColumnName, actual.ColumnName) + } + + } +} + +func TestSegmentsForColumnId(t *testing.T) { + segments := ColumnId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ColumnId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/synapse/2021-06-01/sensitivitylabels/method_sqlpoolsensitivitylabelsdisablerecommendation.go b/resource-manager/synapse/2021-06-01/sensitivitylabels/method_sqlpoolsensitivitylabelsdisablerecommendation.go new file mode 100644 index 00000000000..fc6c574b8e7 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sensitivitylabels/method_sqlpoolsensitivitylabelsdisablerecommendation.go @@ -0,0 +1,47 @@ +package sensitivitylabels + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SqlPoolSensitivityLabelsDisableRecommendationOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// SqlPoolSensitivityLabelsDisableRecommendation ... +func (c SensitivityLabelsClient) SqlPoolSensitivityLabelsDisableRecommendation(ctx context.Context, id ColumnId) (result SqlPoolSensitivityLabelsDisableRecommendationOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/sensitivityLabels/recommended/disable", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/synapse/2021-06-01/sensitivitylabels/method_sqlpoolsensitivitylabelsenablerecommendation.go b/resource-manager/synapse/2021-06-01/sensitivitylabels/method_sqlpoolsensitivitylabelsenablerecommendation.go new file mode 100644 index 00000000000..42b65b2e45e --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sensitivitylabels/method_sqlpoolsensitivitylabelsenablerecommendation.go @@ -0,0 +1,47 @@ +package sensitivitylabels + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SqlPoolSensitivityLabelsEnableRecommendationOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// SqlPoolSensitivityLabelsEnableRecommendation ... +func (c SensitivityLabelsClient) SqlPoolSensitivityLabelsEnableRecommendation(ctx context.Context, id ColumnId) (result SqlPoolSensitivityLabelsEnableRecommendationOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/sensitivityLabels/recommended/enable", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/synapse/2021-06-01/sensitivitylabels/version.go b/resource-manager/synapse/2021-06-01/sensitivitylabels/version.go new file mode 100644 index 00000000000..7cbeb72994c --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sensitivitylabels/version.go @@ -0,0 +1,12 @@ +package sensitivitylabels + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2021-06-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/sensitivitylabels/%s", defaultApiVersion) +} diff --git a/resource-manager/synapse/2021-06-01/sqlpools/README.md b/resource-manager/synapse/2021-06-01/sqlpools/README.md new file mode 100644 index 00000000000..e8cb6e72882 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpools/README.md @@ -0,0 +1,160 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/synapse/2021-06-01/sqlpools` Documentation + +The `sqlpools` SDK allows for interaction with the Azure Resource Manager Service `synapse` (API Version `2021-06-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/synapse/2021-06-01/sqlpools" +``` + + +### Client Initialization + +```go +client := sqlpools.NewSqlPoolsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `SqlPoolsClient.Create` + +```go +ctx := context.TODO() +id := sqlpools.NewSqlPoolID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "sqlPoolValue") + +payload := sqlpools.SqlPool{ + // ... +} + + +if err := client.CreateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `SqlPoolsClient.Delete` + +```go +ctx := context.TODO() +id := sqlpools.NewSqlPoolID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "sqlPoolValue") + +if err := client.DeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `SqlPoolsClient.Get` + +```go +ctx := context.TODO() +id := sqlpools.NewSqlPoolID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "sqlPoolValue") + +read, err := client.Get(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `SqlPoolsClient.ListByWorkspace` + +```go +ctx := context.TODO() +id := sqlpools.NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue") + +// alternatively `client.ListByWorkspace(ctx, id)` can be used to do batched pagination +items, err := client.ListByWorkspaceComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `SqlPoolsClient.Pause` + +```go +ctx := context.TODO() +id := sqlpools.NewSqlPoolID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "sqlPoolValue") + +if err := client.PauseThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `SqlPoolsClient.Resume` + +```go +ctx := context.TODO() +id := sqlpools.NewSqlPoolID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "sqlPoolValue") + +if err := client.ResumeThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `SqlPoolsClient.SqlPoolMetadataSyncConfigsCreate` + +```go +ctx := context.TODO() +id := sqlpools.NewSqlPoolID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "sqlPoolValue") + +payload := sqlpools.MetadataSyncConfig{ + // ... +} + + +read, err := client.SqlPoolMetadataSyncConfigsCreate(ctx, id, payload) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `SqlPoolsClient.SqlPoolMetadataSyncConfigsGet` + +```go +ctx := context.TODO() +id := sqlpools.NewSqlPoolID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "sqlPoolValue") + +read, err := client.SqlPoolMetadataSyncConfigsGet(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `SqlPoolsClient.Update` + +```go +ctx := context.TODO() +id := sqlpools.NewSqlPoolID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "sqlPoolValue") + +payload := sqlpools.SqlPoolPatchInfo{ + // ... +} + + +if err := client.UpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` diff --git a/resource-manager/synapse/2021-06-01/sqlpools/client.go b/resource-manager/synapse/2021-06-01/sqlpools/client.go new file mode 100644 index 00000000000..3dda53d9532 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpools/client.go @@ -0,0 +1,26 @@ +package sqlpools + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SqlPoolsClient struct { + Client *resourcemanager.Client +} + +func NewSqlPoolsClientWithBaseURI(sdkApi sdkEnv.Api) (*SqlPoolsClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "sqlpools", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating SqlPoolsClient: %+v", err) + } + + return &SqlPoolsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/synapse/2021-06-01/sqlpools/constants.go b/resource-manager/synapse/2021-06-01/sqlpools/constants.go new file mode 100644 index 00000000000..1df53624c80 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpools/constants.go @@ -0,0 +1,98 @@ +package sqlpools + +import ( + "encoding/json" + "fmt" + "strings" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateMode string + +const ( + CreateModeDefault CreateMode = "Default" + CreateModePointInTimeRestore CreateMode = "PointInTimeRestore" + CreateModeRecovery CreateMode = "Recovery" + CreateModeRestore CreateMode = "Restore" +) + +func PossibleValuesForCreateMode() []string { + return []string{ + string(CreateModeDefault), + string(CreateModePointInTimeRestore), + string(CreateModeRecovery), + string(CreateModeRestore), + } +} + +func (s *CreateMode) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseCreateMode(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseCreateMode(input string) (*CreateMode, error) { + vals := map[string]CreateMode{ + "default": CreateModeDefault, + "pointintimerestore": CreateModePointInTimeRestore, + "recovery": CreateModeRecovery, + "restore": CreateModeRestore, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := CreateMode(input) + return &out, nil +} + +type StorageAccountType string + +const ( + StorageAccountTypeGRS StorageAccountType = "GRS" + StorageAccountTypeLRS StorageAccountType = "LRS" +) + +func PossibleValuesForStorageAccountType() []string { + return []string{ + string(StorageAccountTypeGRS), + string(StorageAccountTypeLRS), + } +} + +func (s *StorageAccountType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseStorageAccountType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseStorageAccountType(input string) (*StorageAccountType, error) { + vals := map[string]StorageAccountType{ + "grs": StorageAccountTypeGRS, + "lrs": StorageAccountTypeLRS, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := StorageAccountType(input) + return &out, nil +} diff --git a/resource-manager/synapse/2021-06-01/sqlpools/id_sqlpool.go b/resource-manager/synapse/2021-06-01/sqlpools/id_sqlpool.go new file mode 100644 index 00000000000..78808817751 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpools/id_sqlpool.go @@ -0,0 +1,134 @@ +package sqlpools + +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 = &SqlPoolId{} + +// SqlPoolId is a struct representing the Resource ID for a Sql Pool +type SqlPoolId struct { + SubscriptionId string + ResourceGroupName string + WorkspaceName string + SqlPoolName string +} + +// NewSqlPoolID returns a new SqlPoolId struct +func NewSqlPoolID(subscriptionId string, resourceGroupName string, workspaceName string, sqlPoolName string) SqlPoolId { + return SqlPoolId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + WorkspaceName: workspaceName, + SqlPoolName: sqlPoolName, + } +} + +// ParseSqlPoolID parses 'input' into a SqlPoolId +func ParseSqlPoolID(input string) (*SqlPoolId, error) { + parser := resourceids.NewParserFromResourceIdType(&SqlPoolId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := SqlPoolId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseSqlPoolIDInsensitively parses 'input' case-insensitively into a SqlPoolId +// note: this method should only be used for API response data and not user input +func ParseSqlPoolIDInsensitively(input string) (*SqlPoolId, error) { + parser := resourceids.NewParserFromResourceIdType(&SqlPoolId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := SqlPoolId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *SqlPoolId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.WorkspaceName, ok = input.Parsed["workspaceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "workspaceName", input) + } + + if id.SqlPoolName, ok = input.Parsed["sqlPoolName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "sqlPoolName", input) + } + + return nil +} + +// ValidateSqlPoolID checks that 'input' can be parsed as a Sql Pool ID +func ValidateSqlPoolID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseSqlPoolID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Sql Pool ID +func (id SqlPoolId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Synapse/workspaces/%s/sqlPools/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.WorkspaceName, id.SqlPoolName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Sql Pool ID +func (id SqlPoolId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftSynapse", "Microsoft.Synapse", "Microsoft.Synapse"), + resourceids.StaticSegment("staticWorkspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceName", "workspaceValue"), + resourceids.StaticSegment("staticSqlPools", "sqlPools", "sqlPools"), + resourceids.UserSpecifiedSegment("sqlPoolName", "sqlPoolValue"), + } +} + +// String returns a human-readable description of this Sql Pool ID +func (id SqlPoolId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Workspace Name: %q", id.WorkspaceName), + fmt.Sprintf("Sql Pool Name: %q", id.SqlPoolName), + } + return fmt.Sprintf("Sql Pool (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/synapse/2021-06-01/sqlpools/id_sqlpool_test.go b/resource-manager/synapse/2021-06-01/sqlpools/id_sqlpool_test.go new file mode 100644 index 00000000000..9653f83b383 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpools/id_sqlpool_test.go @@ -0,0 +1,327 @@ +package sqlpools + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &SqlPoolId{} + +func TestNewSqlPoolID(t *testing.T) { + id := NewSqlPoolID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "sqlPoolValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.WorkspaceName != "workspaceValue" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceName'", id.WorkspaceName, "workspaceValue") + } + + if id.SqlPoolName != "sqlPoolValue" { + t.Fatalf("Expected %q but got %q for Segment 'SqlPoolName'", id.SqlPoolName, "sqlPoolValue") + } +} + +func TestFormatSqlPoolID(t *testing.T) { + actual := NewSqlPoolID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "sqlPoolValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseSqlPoolID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *SqlPoolId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue", + Expected: &SqlPoolId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + SqlPoolName: "sqlPoolValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseSqlPoolID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + if actual.SqlPoolName != v.Expected.SqlPoolName { + t.Fatalf("Expected %q but got %q for SqlPoolName", v.Expected.SqlPoolName, actual.SqlPoolName) + } + + } +} + +func TestParseSqlPoolIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *SqlPoolId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/sQlPoOlS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue", + Expected: &SqlPoolId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + SqlPoolName: "sqlPoolValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/sQlPoOlS/sQlPoOlVaLuE", + Expected: &SqlPoolId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + WorkspaceName: "wOrKsPaCeVaLuE", + SqlPoolName: "sQlPoOlVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/sQlPoOlS/sQlPoOlVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseSqlPoolIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + if actual.SqlPoolName != v.Expected.SqlPoolName { + t.Fatalf("Expected %q but got %q for SqlPoolName", v.Expected.SqlPoolName, actual.SqlPoolName) + } + + } +} + +func TestSegmentsForSqlPoolId(t *testing.T) { + segments := SqlPoolId{}.Segments() + if len(segments) == 0 { + t.Fatalf("SqlPoolId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/synapse/2021-06-01/sqlpools/id_workspace.go b/resource-manager/synapse/2021-06-01/sqlpools/id_workspace.go new file mode 100644 index 00000000000..0642589fe59 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpools/id_workspace.go @@ -0,0 +1,125 @@ +package sqlpools + +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 = &WorkspaceId{} + +// WorkspaceId is a struct representing the Resource ID for a Workspace +type WorkspaceId struct { + SubscriptionId string + ResourceGroupName string + WorkspaceName string +} + +// NewWorkspaceID returns a new WorkspaceId struct +func NewWorkspaceID(subscriptionId string, resourceGroupName string, workspaceName string) WorkspaceId { + return WorkspaceId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + WorkspaceName: workspaceName, + } +} + +// ParseWorkspaceID parses 'input' into a WorkspaceId +func ParseWorkspaceID(input string) (*WorkspaceId, error) { + parser := resourceids.NewParserFromResourceIdType(&WorkspaceId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := WorkspaceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseWorkspaceIDInsensitively parses 'input' case-insensitively into a WorkspaceId +// note: this method should only be used for API response data and not user input +func ParseWorkspaceIDInsensitively(input string) (*WorkspaceId, error) { + parser := resourceids.NewParserFromResourceIdType(&WorkspaceId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := WorkspaceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *WorkspaceId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.WorkspaceName, ok = input.Parsed["workspaceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "workspaceName", input) + } + + return nil +} + +// ValidateWorkspaceID checks that 'input' can be parsed as a Workspace ID +func ValidateWorkspaceID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseWorkspaceID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Workspace ID +func (id WorkspaceId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Synapse/workspaces/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.WorkspaceName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Workspace ID +func (id WorkspaceId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftSynapse", "Microsoft.Synapse", "Microsoft.Synapse"), + resourceids.StaticSegment("staticWorkspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceName", "workspaceValue"), + } +} + +// String returns a human-readable description of this Workspace ID +func (id WorkspaceId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Workspace Name: %q", id.WorkspaceName), + } + return fmt.Sprintf("Workspace (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/synapse/2021-06-01/sqlpools/id_workspace_test.go b/resource-manager/synapse/2021-06-01/sqlpools/id_workspace_test.go new file mode 100644 index 00000000000..fa8b6829bdf --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpools/id_workspace_test.go @@ -0,0 +1,282 @@ +package sqlpools + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &WorkspaceId{} + +func TestNewWorkspaceID(t *testing.T) { + id := NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.WorkspaceName != "workspaceValue" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceName'", id.WorkspaceName, "workspaceValue") + } +} + +func TestFormatWorkspaceID(t *testing.T) { + actual := NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseWorkspaceID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkspaceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue", + Expected: &WorkspaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkspaceID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + } +} + +func TestParseWorkspaceIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkspaceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue", + Expected: &WorkspaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE", + Expected: &WorkspaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + WorkspaceName: "wOrKsPaCeVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkspaceIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + } +} + +func TestSegmentsForWorkspaceId(t *testing.T) { + segments := WorkspaceId{}.Segments() + if len(segments) == 0 { + t.Fatalf("WorkspaceId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/synapse/2021-06-01/sqlpools/method_create.go b/resource-manager/synapse/2021-06-01/sqlpools/method_create.go new file mode 100644 index 00000000000..a4e01e46e10 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpools/method_create.go @@ -0,0 +1,75 @@ +package sqlpools + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *SqlPool +} + +// Create ... +func (c SqlPoolsClient) Create(ctx context.Context, id SqlPoolId, input SqlPool) (result CreateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// CreateThenPoll performs Create then polls until it's completed +func (c SqlPoolsClient) CreateThenPoll(ctx context.Context, id SqlPoolId, input SqlPool) error { + result, err := c.Create(ctx, id, input) + if err != nil { + return fmt.Errorf("performing Create: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after Create: %+v", err) + } + + return nil +} diff --git a/resource-manager/synapse/2021-06-01/sqlpools/method_delete.go b/resource-manager/synapse/2021-06-01/sqlpools/method_delete.go new file mode 100644 index 00000000000..84185d08306 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpools/method_delete.go @@ -0,0 +1,72 @@ +package sqlpools + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *SqlPool +} + +// Delete ... +func (c SqlPoolsClient) Delete(ctx context.Context, id SqlPoolId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// DeleteThenPoll performs Delete then polls until it's completed +func (c SqlPoolsClient) DeleteThenPoll(ctx context.Context, id SqlPoolId) error { + result, err := c.Delete(ctx, id) + if err != nil { + return fmt.Errorf("performing Delete: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after Delete: %+v", err) + } + + return nil +} diff --git a/resource-manager/synapse/2021-06-01/sqlpools/method_get.go b/resource-manager/synapse/2021-06-01/sqlpools/method_get.go new file mode 100644 index 00000000000..f37b313e797 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpools/method_get.go @@ -0,0 +1,51 @@ +package sqlpools + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *SqlPool +} + +// Get ... +func (c SqlPoolsClient) Get(ctx context.Context, id SqlPoolId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/synapse/2021-06-01/sqlpools/method_listbyworkspace.go b/resource-manager/synapse/2021-06-01/sqlpools/method_listbyworkspace.go new file mode 100644 index 00000000000..f2101cab213 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpools/method_listbyworkspace.go @@ -0,0 +1,91 @@ +package sqlpools + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListByWorkspaceOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]SqlPool +} + +type ListByWorkspaceCompleteResult struct { + LatestHttpResponse *http.Response + Items []SqlPool +} + +// ListByWorkspace ... +func (c SqlPoolsClient) ListByWorkspace(ctx context.Context, id WorkspaceId) (result ListByWorkspaceOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/sqlPools", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]SqlPool `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByWorkspaceComplete retrieves all the results into a single object +func (c SqlPoolsClient) ListByWorkspaceComplete(ctx context.Context, id WorkspaceId) (ListByWorkspaceCompleteResult, error) { + return c.ListByWorkspaceCompleteMatchingPredicate(ctx, id, SqlPoolOperationPredicate{}) +} + +// ListByWorkspaceCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c SqlPoolsClient) ListByWorkspaceCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, predicate SqlPoolOperationPredicate) (result ListByWorkspaceCompleteResult, err error) { + items := make([]SqlPool, 0) + + resp, err := c.ListByWorkspace(ctx, id) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByWorkspaceCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/synapse/2021-06-01/sqlpools/method_pause.go b/resource-manager/synapse/2021-06-01/sqlpools/method_pause.go new file mode 100644 index 00000000000..65b26855bff --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpools/method_pause.go @@ -0,0 +1,71 @@ +package sqlpools + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PauseOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *SqlPool +} + +// Pause ... +func (c SqlPoolsClient) Pause(ctx context.Context, id SqlPoolId) (result PauseOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/pause", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// PauseThenPoll performs Pause then polls until it's completed +func (c SqlPoolsClient) PauseThenPoll(ctx context.Context, id SqlPoolId) error { + result, err := c.Pause(ctx, id) + if err != nil { + return fmt.Errorf("performing Pause: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after Pause: %+v", err) + } + + return nil +} diff --git a/resource-manager/synapse/2021-06-01/sqlpools/method_resume.go b/resource-manager/synapse/2021-06-01/sqlpools/method_resume.go new file mode 100644 index 00000000000..360af36c3da --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpools/method_resume.go @@ -0,0 +1,71 @@ +package sqlpools + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ResumeOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *SqlPool +} + +// Resume ... +func (c SqlPoolsClient) Resume(ctx context.Context, id SqlPoolId) (result ResumeOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/resume", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// ResumeThenPoll performs Resume then polls until it's completed +func (c SqlPoolsClient) ResumeThenPoll(ctx context.Context, id SqlPoolId) error { + result, err := c.Resume(ctx, id) + if err != nil { + return fmt.Errorf("performing Resume: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after Resume: %+v", err) + } + + return nil +} diff --git a/resource-manager/synapse/2021-06-01/sqlpools/method_sqlpoolmetadatasyncconfigscreate.go b/resource-manager/synapse/2021-06-01/sqlpools/method_sqlpoolmetadatasyncconfigscreate.go new file mode 100644 index 00000000000..c45c81619c3 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpools/method_sqlpoolmetadatasyncconfigscreate.go @@ -0,0 +1,56 @@ +package sqlpools + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SqlPoolMetadataSyncConfigsCreateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *MetadataSyncConfig +} + +// SqlPoolMetadataSyncConfigsCreate ... +func (c SqlPoolsClient) SqlPoolMetadataSyncConfigsCreate(ctx context.Context, id SqlPoolId, input MetadataSyncConfig) (result SqlPoolMetadataSyncConfigsCreateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: fmt.Sprintf("%s/metadataSync/config", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/synapse/2021-06-01/sqlpools/method_sqlpoolmetadatasyncconfigsget.go b/resource-manager/synapse/2021-06-01/sqlpools/method_sqlpoolmetadatasyncconfigsget.go new file mode 100644 index 00000000000..49e563fe6e8 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpools/method_sqlpoolmetadatasyncconfigsget.go @@ -0,0 +1,52 @@ +package sqlpools + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SqlPoolMetadataSyncConfigsGetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *MetadataSyncConfig +} + +// SqlPoolMetadataSyncConfigsGet ... +func (c SqlPoolsClient) SqlPoolMetadataSyncConfigsGet(ctx context.Context, id SqlPoolId) (result SqlPoolMetadataSyncConfigsGetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/metadataSync/config", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/synapse/2021-06-01/sqlpools/method_update.go b/resource-manager/synapse/2021-06-01/sqlpools/method_update.go new file mode 100644 index 00000000000..7393d0da44e --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpools/method_update.go @@ -0,0 +1,75 @@ +package sqlpools + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type UpdateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *SqlPool +} + +// Update ... +func (c SqlPoolsClient) Update(ctx context.Context, id SqlPoolId, input SqlPoolPatchInfo) (result UpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPatch, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// UpdateThenPoll performs Update then polls until it's completed +func (c SqlPoolsClient) UpdateThenPoll(ctx context.Context, id SqlPoolId, input SqlPoolPatchInfo) error { + result, err := c.Update(ctx, id, input) + if err != nil { + return fmt.Errorf("performing Update: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after Update: %+v", err) + } + + return nil +} diff --git a/resource-manager/synapse/2021-06-01/sqlpools/model_metadatasyncconfig.go b/resource-manager/synapse/2021-06-01/sqlpools/model_metadatasyncconfig.go new file mode 100644 index 00000000000..f1da8adff30 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpools/model_metadatasyncconfig.go @@ -0,0 +1,11 @@ +package sqlpools + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MetadataSyncConfig struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *MetadataSyncConfigProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/synapse/2021-06-01/sqlpools/model_metadatasyncconfigproperties.go b/resource-manager/synapse/2021-06-01/sqlpools/model_metadatasyncconfigproperties.go new file mode 100644 index 00000000000..990622a3fe1 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpools/model_metadatasyncconfigproperties.go @@ -0,0 +1,9 @@ +package sqlpools + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MetadataSyncConfigProperties struct { + Enabled *bool `json:"enabled,omitempty"` + SyncIntervalInMinutes *int64 `json:"syncIntervalInMinutes,omitempty"` +} diff --git a/resource-manager/synapse/2021-06-01/sqlpools/model_sku.go b/resource-manager/synapse/2021-06-01/sqlpools/model_sku.go new file mode 100644 index 00000000000..7a3169dc102 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpools/model_sku.go @@ -0,0 +1,10 @@ +package sqlpools + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Sku struct { + Capacity *int64 `json:"capacity,omitempty"` + Name *string `json:"name,omitempty"` + Tier *string `json:"tier,omitempty"` +} diff --git a/resource-manager/synapse/2021-06-01/sqlpools/model_sqlpool.go b/resource-manager/synapse/2021-06-01/sqlpools/model_sqlpool.go new file mode 100644 index 00000000000..44dfa0fe017 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpools/model_sqlpool.go @@ -0,0 +1,14 @@ +package sqlpools + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SqlPool struct { + Id *string `json:"id,omitempty"` + Location string `json:"location"` + Name *string `json:"name,omitempty"` + Properties *SqlPoolResourceProperties `json:"properties,omitempty"` + Sku *Sku `json:"sku,omitempty"` + Tags *map[string]string `json:"tags,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/synapse/2021-06-01/sqlpools/model_sqlpoolpatchinfo.go b/resource-manager/synapse/2021-06-01/sqlpools/model_sqlpoolpatchinfo.go new file mode 100644 index 00000000000..faa84878335 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpools/model_sqlpoolpatchinfo.go @@ -0,0 +1,11 @@ +package sqlpools + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SqlPoolPatchInfo struct { + Location *string `json:"location,omitempty"` + Properties *SqlPoolResourceProperties `json:"properties,omitempty"` + Sku *Sku `json:"sku,omitempty"` + Tags *map[string]string `json:"tags,omitempty"` +} diff --git a/resource-manager/synapse/2021-06-01/sqlpools/model_sqlpoolresourceproperties.go b/resource-manager/synapse/2021-06-01/sqlpools/model_sqlpoolresourceproperties.go new file mode 100644 index 00000000000..fa9add05507 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpools/model_sqlpoolresourceproperties.go @@ -0,0 +1,60 @@ +package sqlpools + +import ( + "time" + + "github.com/hashicorp/go-azure-helpers/lang/dates" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SqlPoolResourceProperties struct { + Collation *string `json:"collation,omitempty"` + CreateMode *CreateMode `json:"createMode,omitempty"` + CreationDate *string `json:"creationDate,omitempty"` + MaxSizeBytes *int64 `json:"maxSizeBytes,omitempty"` + ProvisioningState *string `json:"provisioningState,omitempty"` + RecoverableDatabaseId *string `json:"recoverableDatabaseId,omitempty"` + RestorePointInTime *string `json:"restorePointInTime,omitempty"` + SourceDatabaseDeletionDate *string `json:"sourceDatabaseDeletionDate,omitempty"` + SourceDatabaseId *string `json:"sourceDatabaseId,omitempty"` + Status *string `json:"status,omitempty"` + StorageAccountType *StorageAccountType `json:"storageAccountType,omitempty"` +} + +func (o *SqlPoolResourceProperties) GetCreationDateAsTime() (*time.Time, error) { + if o.CreationDate == nil { + return nil, nil + } + return dates.ParseAsFormat(o.CreationDate, "2006-01-02T15:04:05Z07:00") +} + +func (o *SqlPoolResourceProperties) SetCreationDateAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.CreationDate = &formatted +} + +func (o *SqlPoolResourceProperties) GetRestorePointInTimeAsTime() (*time.Time, error) { + if o.RestorePointInTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.RestorePointInTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *SqlPoolResourceProperties) SetRestorePointInTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.RestorePointInTime = &formatted +} + +func (o *SqlPoolResourceProperties) GetSourceDatabaseDeletionDateAsTime() (*time.Time, error) { + if o.SourceDatabaseDeletionDate == nil { + return nil, nil + } + return dates.ParseAsFormat(o.SourceDatabaseDeletionDate, "2006-01-02T15:04:05Z07:00") +} + +func (o *SqlPoolResourceProperties) SetSourceDatabaseDeletionDateAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.SourceDatabaseDeletionDate = &formatted +} diff --git a/resource-manager/synapse/2021-06-01/sqlpools/predicates.go b/resource-manager/synapse/2021-06-01/sqlpools/predicates.go new file mode 100644 index 00000000000..2e5229fb8fe --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpools/predicates.go @@ -0,0 +1,32 @@ +package sqlpools + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SqlPoolOperationPredicate struct { + Id *string + Location *string + Name *string + Type *string +} + +func (p SqlPoolOperationPredicate) Matches(input SqlPool) bool { + + if p.Id != nil && (input.Id == nil || *p.Id != *input.Id) { + return false + } + + if p.Location != nil && *p.Location != input.Location { + return false + } + + if p.Name != nil && (input.Name == nil || *p.Name != *input.Name) { + return false + } + + if p.Type != nil && (input.Type == nil || *p.Type != *input.Type) { + return false + } + + return true +} diff --git a/resource-manager/synapse/2021-06-01/sqlpools/version.go b/resource-manager/synapse/2021-06-01/sqlpools/version.go new file mode 100644 index 00000000000..e587a19b45f --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpools/version.go @@ -0,0 +1,12 @@ +package sqlpools + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2021-06-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/sqlpools/%s", defaultApiVersion) +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolsbackup/README.md b/resource-manager/synapse/2021-06-01/sqlpoolsbackup/README.md new file mode 100644 index 00000000000..eb9a88df2c2 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolsbackup/README.md @@ -0,0 +1,37 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/synapse/2021-06-01/sqlpoolsbackup` Documentation + +The `sqlpoolsbackup` SDK allows for interaction with the Azure Resource Manager Service `synapse` (API Version `2021-06-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/synapse/2021-06-01/sqlpoolsbackup" +``` + + +### Client Initialization + +```go +client := sqlpoolsbackup.NewSqlPoolsBackupClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `SqlPoolsBackupClient.SqlPoolRestorePointsList` + +```go +ctx := context.TODO() +id := sqlpoolsbackup.NewSqlPoolID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "sqlPoolValue") + +// alternatively `client.SqlPoolRestorePointsList(ctx, id)` can be used to do batched pagination +items, err := client.SqlPoolRestorePointsListComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/synapse/2021-06-01/sqlpoolsbackup/client.go b/resource-manager/synapse/2021-06-01/sqlpoolsbackup/client.go new file mode 100644 index 00000000000..aa32ca34338 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolsbackup/client.go @@ -0,0 +1,26 @@ +package sqlpoolsbackup + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SqlPoolsBackupClient struct { + Client *resourcemanager.Client +} + +func NewSqlPoolsBackupClientWithBaseURI(sdkApi sdkEnv.Api) (*SqlPoolsBackupClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "sqlpoolsbackup", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating SqlPoolsBackupClient: %+v", err) + } + + return &SqlPoolsBackupClient{ + Client: client, + }, nil +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolsbackup/constants.go b/resource-manager/synapse/2021-06-01/sqlpoolsbackup/constants.go new file mode 100644 index 00000000000..2476191ef76 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolsbackup/constants.go @@ -0,0 +1,51 @@ +package sqlpoolsbackup + +import ( + "encoding/json" + "fmt" + "strings" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RestorePointType string + +const ( + RestorePointTypeCONTINUOUS RestorePointType = "CONTINUOUS" + RestorePointTypeDISCRETE RestorePointType = "DISCRETE" +) + +func PossibleValuesForRestorePointType() []string { + return []string{ + string(RestorePointTypeCONTINUOUS), + string(RestorePointTypeDISCRETE), + } +} + +func (s *RestorePointType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseRestorePointType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseRestorePointType(input string) (*RestorePointType, error) { + vals := map[string]RestorePointType{ + "continuous": RestorePointTypeCONTINUOUS, + "discrete": RestorePointTypeDISCRETE, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := RestorePointType(input) + return &out, nil +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolsbackup/id_sqlpool.go b/resource-manager/synapse/2021-06-01/sqlpoolsbackup/id_sqlpool.go new file mode 100644 index 00000000000..1c6c7b57445 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolsbackup/id_sqlpool.go @@ -0,0 +1,134 @@ +package sqlpoolsbackup + +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 = &SqlPoolId{} + +// SqlPoolId is a struct representing the Resource ID for a Sql Pool +type SqlPoolId struct { + SubscriptionId string + ResourceGroupName string + WorkspaceName string + SqlPoolName string +} + +// NewSqlPoolID returns a new SqlPoolId struct +func NewSqlPoolID(subscriptionId string, resourceGroupName string, workspaceName string, sqlPoolName string) SqlPoolId { + return SqlPoolId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + WorkspaceName: workspaceName, + SqlPoolName: sqlPoolName, + } +} + +// ParseSqlPoolID parses 'input' into a SqlPoolId +func ParseSqlPoolID(input string) (*SqlPoolId, error) { + parser := resourceids.NewParserFromResourceIdType(&SqlPoolId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := SqlPoolId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseSqlPoolIDInsensitively parses 'input' case-insensitively into a SqlPoolId +// note: this method should only be used for API response data and not user input +func ParseSqlPoolIDInsensitively(input string) (*SqlPoolId, error) { + parser := resourceids.NewParserFromResourceIdType(&SqlPoolId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := SqlPoolId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *SqlPoolId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.WorkspaceName, ok = input.Parsed["workspaceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "workspaceName", input) + } + + if id.SqlPoolName, ok = input.Parsed["sqlPoolName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "sqlPoolName", input) + } + + return nil +} + +// ValidateSqlPoolID checks that 'input' can be parsed as a Sql Pool ID +func ValidateSqlPoolID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseSqlPoolID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Sql Pool ID +func (id SqlPoolId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Synapse/workspaces/%s/sqlPools/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.WorkspaceName, id.SqlPoolName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Sql Pool ID +func (id SqlPoolId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftSynapse", "Microsoft.Synapse", "Microsoft.Synapse"), + resourceids.StaticSegment("staticWorkspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceName", "workspaceValue"), + resourceids.StaticSegment("staticSqlPools", "sqlPools", "sqlPools"), + resourceids.UserSpecifiedSegment("sqlPoolName", "sqlPoolValue"), + } +} + +// String returns a human-readable description of this Sql Pool ID +func (id SqlPoolId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Workspace Name: %q", id.WorkspaceName), + fmt.Sprintf("Sql Pool Name: %q", id.SqlPoolName), + } + return fmt.Sprintf("Sql Pool (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolsbackup/id_sqlpool_test.go b/resource-manager/synapse/2021-06-01/sqlpoolsbackup/id_sqlpool_test.go new file mode 100644 index 00000000000..5323a24989a --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolsbackup/id_sqlpool_test.go @@ -0,0 +1,327 @@ +package sqlpoolsbackup + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &SqlPoolId{} + +func TestNewSqlPoolID(t *testing.T) { + id := NewSqlPoolID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "sqlPoolValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.WorkspaceName != "workspaceValue" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceName'", id.WorkspaceName, "workspaceValue") + } + + if id.SqlPoolName != "sqlPoolValue" { + t.Fatalf("Expected %q but got %q for Segment 'SqlPoolName'", id.SqlPoolName, "sqlPoolValue") + } +} + +func TestFormatSqlPoolID(t *testing.T) { + actual := NewSqlPoolID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "sqlPoolValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseSqlPoolID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *SqlPoolId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue", + Expected: &SqlPoolId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + SqlPoolName: "sqlPoolValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseSqlPoolID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + if actual.SqlPoolName != v.Expected.SqlPoolName { + t.Fatalf("Expected %q but got %q for SqlPoolName", v.Expected.SqlPoolName, actual.SqlPoolName) + } + + } +} + +func TestParseSqlPoolIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *SqlPoolId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/sQlPoOlS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue", + Expected: &SqlPoolId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + SqlPoolName: "sqlPoolValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/sQlPoOlS/sQlPoOlVaLuE", + Expected: &SqlPoolId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + WorkspaceName: "wOrKsPaCeVaLuE", + SqlPoolName: "sQlPoOlVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/sQlPoOlS/sQlPoOlVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseSqlPoolIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + if actual.SqlPoolName != v.Expected.SqlPoolName { + t.Fatalf("Expected %q but got %q for SqlPoolName", v.Expected.SqlPoolName, actual.SqlPoolName) + } + + } +} + +func TestSegmentsForSqlPoolId(t *testing.T) { + segments := SqlPoolId{}.Segments() + if len(segments) == 0 { + t.Fatalf("SqlPoolId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolsbackup/method_sqlpoolrestorepointslist.go b/resource-manager/synapse/2021-06-01/sqlpoolsbackup/method_sqlpoolrestorepointslist.go new file mode 100644 index 00000000000..5756b331040 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolsbackup/method_sqlpoolrestorepointslist.go @@ -0,0 +1,91 @@ +package sqlpoolsbackup + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SqlPoolRestorePointsListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]RestorePoint +} + +type SqlPoolRestorePointsListCompleteResult struct { + LatestHttpResponse *http.Response + Items []RestorePoint +} + +// SqlPoolRestorePointsList ... +func (c SqlPoolsBackupClient) SqlPoolRestorePointsList(ctx context.Context, id SqlPoolId) (result SqlPoolRestorePointsListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/restorePoints", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]RestorePoint `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// SqlPoolRestorePointsListComplete retrieves all the results into a single object +func (c SqlPoolsBackupClient) SqlPoolRestorePointsListComplete(ctx context.Context, id SqlPoolId) (SqlPoolRestorePointsListCompleteResult, error) { + return c.SqlPoolRestorePointsListCompleteMatchingPredicate(ctx, id, RestorePointOperationPredicate{}) +} + +// SqlPoolRestorePointsListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c SqlPoolsBackupClient) SqlPoolRestorePointsListCompleteMatchingPredicate(ctx context.Context, id SqlPoolId, predicate RestorePointOperationPredicate) (result SqlPoolRestorePointsListCompleteResult, err error) { + items := make([]RestorePoint, 0) + + resp, err := c.SqlPoolRestorePointsList(ctx, id) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = SqlPoolRestorePointsListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolsbackup/model_restorepoint.go b/resource-manager/synapse/2021-06-01/sqlpoolsbackup/model_restorepoint.go new file mode 100644 index 00000000000..447fe4728b0 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolsbackup/model_restorepoint.go @@ -0,0 +1,12 @@ +package sqlpoolsbackup + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RestorePoint struct { + Id *string `json:"id,omitempty"` + Location *string `json:"location,omitempty"` + Name *string `json:"name,omitempty"` + Properties *RestorePointProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolsbackup/model_restorepointproperties.go b/resource-manager/synapse/2021-06-01/sqlpoolsbackup/model_restorepointproperties.go new file mode 100644 index 00000000000..6b2723453b7 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolsbackup/model_restorepointproperties.go @@ -0,0 +1,41 @@ +package sqlpoolsbackup + +import ( + "time" + + "github.com/hashicorp/go-azure-helpers/lang/dates" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RestorePointProperties struct { + EarliestRestoreDate *string `json:"earliestRestoreDate,omitempty"` + RestorePointCreationDate *string `json:"restorePointCreationDate,omitempty"` + RestorePointLabel *string `json:"restorePointLabel,omitempty"` + RestorePointType *RestorePointType `json:"restorePointType,omitempty"` +} + +func (o *RestorePointProperties) GetEarliestRestoreDateAsTime() (*time.Time, error) { + if o.EarliestRestoreDate == nil { + return nil, nil + } + return dates.ParseAsFormat(o.EarliestRestoreDate, "2006-01-02T15:04:05Z07:00") +} + +func (o *RestorePointProperties) SetEarliestRestoreDateAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.EarliestRestoreDate = &formatted +} + +func (o *RestorePointProperties) GetRestorePointCreationDateAsTime() (*time.Time, error) { + if o.RestorePointCreationDate == nil { + return nil, nil + } + return dates.ParseAsFormat(o.RestorePointCreationDate, "2006-01-02T15:04:05Z07:00") +} + +func (o *RestorePointProperties) SetRestorePointCreationDateAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.RestorePointCreationDate = &formatted +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolsbackup/predicates.go b/resource-manager/synapse/2021-06-01/sqlpoolsbackup/predicates.go new file mode 100644 index 00000000000..0355ed4e7b5 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolsbackup/predicates.go @@ -0,0 +1,32 @@ +package sqlpoolsbackup + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RestorePointOperationPredicate struct { + Id *string + Location *string + Name *string + Type *string +} + +func (p RestorePointOperationPredicate) Matches(input RestorePoint) bool { + + if p.Id != nil && (input.Id == nil || *p.Id != *input.Id) { + return false + } + + if p.Location != nil && (input.Location == nil || *p.Location != *input.Location) { + return false + } + + if p.Name != nil && (input.Name == nil || *p.Name != *input.Name) { + return false + } + + if p.Type != nil && (input.Type == nil || *p.Type != *input.Type) { + return false + } + + return true +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolsbackup/version.go b/resource-manager/synapse/2021-06-01/sqlpoolsbackup/version.go new file mode 100644 index 00000000000..0c5cc4bb6df --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolsbackup/version.go @@ -0,0 +1,12 @@ +package sqlpoolsbackup + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2021-06-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/sqlpoolsbackup/%s", defaultApiVersion) +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolsblobauditing/README.md b/resource-manager/synapse/2021-06-01/sqlpoolsblobauditing/README.md new file mode 100644 index 00000000000..247dd83306d --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolsblobauditing/README.md @@ -0,0 +1,37 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/synapse/2021-06-01/sqlpoolsblobauditing` Documentation + +The `sqlpoolsblobauditing` SDK allows for interaction with the Azure Resource Manager Service `synapse` (API Version `2021-06-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/synapse/2021-06-01/sqlpoolsblobauditing" +``` + + +### Client Initialization + +```go +client := sqlpoolsblobauditing.NewSqlPoolsBlobAuditingClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `SqlPoolsBlobAuditingClient.ExtendedSqlPoolBlobAuditingPoliciesListBySqlPool` + +```go +ctx := context.TODO() +id := sqlpoolsblobauditing.NewSqlPoolID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "sqlPoolValue") + +// alternatively `client.ExtendedSqlPoolBlobAuditingPoliciesListBySqlPool(ctx, id)` can be used to do batched pagination +items, err := client.ExtendedSqlPoolBlobAuditingPoliciesListBySqlPoolComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/synapse/2021-06-01/sqlpoolsblobauditing/client.go b/resource-manager/synapse/2021-06-01/sqlpoolsblobauditing/client.go new file mode 100644 index 00000000000..ba0872a7420 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolsblobauditing/client.go @@ -0,0 +1,26 @@ +package sqlpoolsblobauditing + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SqlPoolsBlobAuditingClient struct { + Client *resourcemanager.Client +} + +func NewSqlPoolsBlobAuditingClientWithBaseURI(sdkApi sdkEnv.Api) (*SqlPoolsBlobAuditingClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "sqlpoolsblobauditing", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating SqlPoolsBlobAuditingClient: %+v", err) + } + + return &SqlPoolsBlobAuditingClient{ + Client: client, + }, nil +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolsblobauditing/constants.go b/resource-manager/synapse/2021-06-01/sqlpoolsblobauditing/constants.go new file mode 100644 index 00000000000..f0ac9059d93 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolsblobauditing/constants.go @@ -0,0 +1,51 @@ +package sqlpoolsblobauditing + +import ( + "encoding/json" + "fmt" + "strings" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type BlobAuditingPolicyState string + +const ( + BlobAuditingPolicyStateDisabled BlobAuditingPolicyState = "Disabled" + BlobAuditingPolicyStateEnabled BlobAuditingPolicyState = "Enabled" +) + +func PossibleValuesForBlobAuditingPolicyState() []string { + return []string{ + string(BlobAuditingPolicyStateDisabled), + string(BlobAuditingPolicyStateEnabled), + } +} + +func (s *BlobAuditingPolicyState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseBlobAuditingPolicyState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseBlobAuditingPolicyState(input string) (*BlobAuditingPolicyState, error) { + vals := map[string]BlobAuditingPolicyState{ + "disabled": BlobAuditingPolicyStateDisabled, + "enabled": BlobAuditingPolicyStateEnabled, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := BlobAuditingPolicyState(input) + return &out, nil +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolsblobauditing/id_sqlpool.go b/resource-manager/synapse/2021-06-01/sqlpoolsblobauditing/id_sqlpool.go new file mode 100644 index 00000000000..ab72c96df3d --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolsblobauditing/id_sqlpool.go @@ -0,0 +1,134 @@ +package sqlpoolsblobauditing + +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 = &SqlPoolId{} + +// SqlPoolId is a struct representing the Resource ID for a Sql Pool +type SqlPoolId struct { + SubscriptionId string + ResourceGroupName string + WorkspaceName string + SqlPoolName string +} + +// NewSqlPoolID returns a new SqlPoolId struct +func NewSqlPoolID(subscriptionId string, resourceGroupName string, workspaceName string, sqlPoolName string) SqlPoolId { + return SqlPoolId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + WorkspaceName: workspaceName, + SqlPoolName: sqlPoolName, + } +} + +// ParseSqlPoolID parses 'input' into a SqlPoolId +func ParseSqlPoolID(input string) (*SqlPoolId, error) { + parser := resourceids.NewParserFromResourceIdType(&SqlPoolId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := SqlPoolId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseSqlPoolIDInsensitively parses 'input' case-insensitively into a SqlPoolId +// note: this method should only be used for API response data and not user input +func ParseSqlPoolIDInsensitively(input string) (*SqlPoolId, error) { + parser := resourceids.NewParserFromResourceIdType(&SqlPoolId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := SqlPoolId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *SqlPoolId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.WorkspaceName, ok = input.Parsed["workspaceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "workspaceName", input) + } + + if id.SqlPoolName, ok = input.Parsed["sqlPoolName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "sqlPoolName", input) + } + + return nil +} + +// ValidateSqlPoolID checks that 'input' can be parsed as a Sql Pool ID +func ValidateSqlPoolID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseSqlPoolID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Sql Pool ID +func (id SqlPoolId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Synapse/workspaces/%s/sqlPools/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.WorkspaceName, id.SqlPoolName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Sql Pool ID +func (id SqlPoolId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftSynapse", "Microsoft.Synapse", "Microsoft.Synapse"), + resourceids.StaticSegment("staticWorkspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceName", "workspaceValue"), + resourceids.StaticSegment("staticSqlPools", "sqlPools", "sqlPools"), + resourceids.UserSpecifiedSegment("sqlPoolName", "sqlPoolValue"), + } +} + +// String returns a human-readable description of this Sql Pool ID +func (id SqlPoolId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Workspace Name: %q", id.WorkspaceName), + fmt.Sprintf("Sql Pool Name: %q", id.SqlPoolName), + } + return fmt.Sprintf("Sql Pool (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolsblobauditing/id_sqlpool_test.go b/resource-manager/synapse/2021-06-01/sqlpoolsblobauditing/id_sqlpool_test.go new file mode 100644 index 00000000000..24f4f831786 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolsblobauditing/id_sqlpool_test.go @@ -0,0 +1,327 @@ +package sqlpoolsblobauditing + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &SqlPoolId{} + +func TestNewSqlPoolID(t *testing.T) { + id := NewSqlPoolID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "sqlPoolValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.WorkspaceName != "workspaceValue" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceName'", id.WorkspaceName, "workspaceValue") + } + + if id.SqlPoolName != "sqlPoolValue" { + t.Fatalf("Expected %q but got %q for Segment 'SqlPoolName'", id.SqlPoolName, "sqlPoolValue") + } +} + +func TestFormatSqlPoolID(t *testing.T) { + actual := NewSqlPoolID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "sqlPoolValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseSqlPoolID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *SqlPoolId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue", + Expected: &SqlPoolId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + SqlPoolName: "sqlPoolValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseSqlPoolID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + if actual.SqlPoolName != v.Expected.SqlPoolName { + t.Fatalf("Expected %q but got %q for SqlPoolName", v.Expected.SqlPoolName, actual.SqlPoolName) + } + + } +} + +func TestParseSqlPoolIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *SqlPoolId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/sQlPoOlS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue", + Expected: &SqlPoolId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + SqlPoolName: "sqlPoolValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/sQlPoOlS/sQlPoOlVaLuE", + Expected: &SqlPoolId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + WorkspaceName: "wOrKsPaCeVaLuE", + SqlPoolName: "sQlPoOlVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/sQlPoOlS/sQlPoOlVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseSqlPoolIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + if actual.SqlPoolName != v.Expected.SqlPoolName { + t.Fatalf("Expected %q but got %q for SqlPoolName", v.Expected.SqlPoolName, actual.SqlPoolName) + } + + } +} + +func TestSegmentsForSqlPoolId(t *testing.T) { + segments := SqlPoolId{}.Segments() + if len(segments) == 0 { + t.Fatalf("SqlPoolId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolsblobauditing/method_extendedsqlpoolblobauditingpolicieslistbysqlpool.go b/resource-manager/synapse/2021-06-01/sqlpoolsblobauditing/method_extendedsqlpoolblobauditingpolicieslistbysqlpool.go new file mode 100644 index 00000000000..1bba0dc368d --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolsblobauditing/method_extendedsqlpoolblobauditingpolicieslistbysqlpool.go @@ -0,0 +1,91 @@ +package sqlpoolsblobauditing + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ExtendedSqlPoolBlobAuditingPoliciesListBySqlPoolOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]ExtendedSqlPoolBlobAuditingPolicy +} + +type ExtendedSqlPoolBlobAuditingPoliciesListBySqlPoolCompleteResult struct { + LatestHttpResponse *http.Response + Items []ExtendedSqlPoolBlobAuditingPolicy +} + +// ExtendedSqlPoolBlobAuditingPoliciesListBySqlPool ... +func (c SqlPoolsBlobAuditingClient) ExtendedSqlPoolBlobAuditingPoliciesListBySqlPool(ctx context.Context, id SqlPoolId) (result ExtendedSqlPoolBlobAuditingPoliciesListBySqlPoolOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/extendedAuditingSettings", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]ExtendedSqlPoolBlobAuditingPolicy `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ExtendedSqlPoolBlobAuditingPoliciesListBySqlPoolComplete retrieves all the results into a single object +func (c SqlPoolsBlobAuditingClient) ExtendedSqlPoolBlobAuditingPoliciesListBySqlPoolComplete(ctx context.Context, id SqlPoolId) (ExtendedSqlPoolBlobAuditingPoliciesListBySqlPoolCompleteResult, error) { + return c.ExtendedSqlPoolBlobAuditingPoliciesListBySqlPoolCompleteMatchingPredicate(ctx, id, ExtendedSqlPoolBlobAuditingPolicyOperationPredicate{}) +} + +// ExtendedSqlPoolBlobAuditingPoliciesListBySqlPoolCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c SqlPoolsBlobAuditingClient) ExtendedSqlPoolBlobAuditingPoliciesListBySqlPoolCompleteMatchingPredicate(ctx context.Context, id SqlPoolId, predicate ExtendedSqlPoolBlobAuditingPolicyOperationPredicate) (result ExtendedSqlPoolBlobAuditingPoliciesListBySqlPoolCompleteResult, err error) { + items := make([]ExtendedSqlPoolBlobAuditingPolicy, 0) + + resp, err := c.ExtendedSqlPoolBlobAuditingPoliciesListBySqlPool(ctx, id) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ExtendedSqlPoolBlobAuditingPoliciesListBySqlPoolCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolsblobauditing/model_extendedsqlpoolblobauditingpolicy.go b/resource-manager/synapse/2021-06-01/sqlpoolsblobauditing/model_extendedsqlpoolblobauditingpolicy.go new file mode 100644 index 00000000000..0d7e71ef4da --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolsblobauditing/model_extendedsqlpoolblobauditingpolicy.go @@ -0,0 +1,11 @@ +package sqlpoolsblobauditing + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ExtendedSqlPoolBlobAuditingPolicy struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *ExtendedSqlPoolBlobAuditingPolicyProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolsblobauditing/model_extendedsqlpoolblobauditingpolicyproperties.go b/resource-manager/synapse/2021-06-01/sqlpoolsblobauditing/model_extendedsqlpoolblobauditingpolicyproperties.go new file mode 100644 index 00000000000..fc86879ff4d --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolsblobauditing/model_extendedsqlpoolblobauditingpolicyproperties.go @@ -0,0 +1,17 @@ +package sqlpoolsblobauditing + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ExtendedSqlPoolBlobAuditingPolicyProperties struct { + AuditActionsAndGroups *[]string `json:"auditActionsAndGroups,omitempty"` + IsAzureMonitorTargetEnabled *bool `json:"isAzureMonitorTargetEnabled,omitempty"` + IsStorageSecondaryKeyInUse *bool `json:"isStorageSecondaryKeyInUse,omitempty"` + PredicateExpression *string `json:"predicateExpression,omitempty"` + QueueDelayMs *int64 `json:"queueDelayMs,omitempty"` + RetentionDays *int64 `json:"retentionDays,omitempty"` + State BlobAuditingPolicyState `json:"state"` + StorageAccountAccessKey *string `json:"storageAccountAccessKey,omitempty"` + StorageAccountSubscriptionId *string `json:"storageAccountSubscriptionId,omitempty"` + StorageEndpoint *string `json:"storageEndpoint,omitempty"` +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolsblobauditing/predicates.go b/resource-manager/synapse/2021-06-01/sqlpoolsblobauditing/predicates.go new file mode 100644 index 00000000000..6ed0f55329f --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolsblobauditing/predicates.go @@ -0,0 +1,27 @@ +package sqlpoolsblobauditing + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ExtendedSqlPoolBlobAuditingPolicyOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p ExtendedSqlPoolBlobAuditingPolicyOperationPredicate) Matches(input ExtendedSqlPoolBlobAuditingPolicy) bool { + + if p.Id != nil && (input.Id == nil || *p.Id != *input.Id) { + return false + } + + if p.Name != nil && (input.Name == nil || *p.Name != *input.Name) { + return false + } + + if p.Type != nil && (input.Type == nil || *p.Type != *input.Type) { + return false + } + + return true +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolsblobauditing/version.go b/resource-manager/synapse/2021-06-01/sqlpoolsblobauditing/version.go new file mode 100644 index 00000000000..dd59d0f9d19 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolsblobauditing/version.go @@ -0,0 +1,12 @@ +package sqlpoolsblobauditing + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2021-06-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/sqlpoolsblobauditing/%s", defaultApiVersion) +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolsconnectionpolicies/README.md b/resource-manager/synapse/2021-06-01/sqlpoolsconnectionpolicies/README.md new file mode 100644 index 00000000000..161da8c823a --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolsconnectionpolicies/README.md @@ -0,0 +1,36 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/synapse/2021-06-01/sqlpoolsconnectionpolicies` Documentation + +The `sqlpoolsconnectionpolicies` SDK allows for interaction with the Azure Resource Manager Service `synapse` (API Version `2021-06-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/synapse/2021-06-01/sqlpoolsconnectionpolicies" +``` + + +### Client Initialization + +```go +client := sqlpoolsconnectionpolicies.NewSqlPoolsConnectionPoliciesClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `SqlPoolsConnectionPoliciesClient.SqlPoolConnectionPoliciesGet` + +```go +ctx := context.TODO() +id := sqlpoolsconnectionpolicies.NewSqlPoolID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "sqlPoolValue") + +read, err := client.SqlPoolConnectionPoliciesGet(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` diff --git a/resource-manager/synapse/2021-06-01/sqlpoolsconnectionpolicies/client.go b/resource-manager/synapse/2021-06-01/sqlpoolsconnectionpolicies/client.go new file mode 100644 index 00000000000..a4b41beb503 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolsconnectionpolicies/client.go @@ -0,0 +1,26 @@ +package sqlpoolsconnectionpolicies + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SqlPoolsConnectionPoliciesClient struct { + Client *resourcemanager.Client +} + +func NewSqlPoolsConnectionPoliciesClientWithBaseURI(sdkApi sdkEnv.Api) (*SqlPoolsConnectionPoliciesClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "sqlpoolsconnectionpolicies", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating SqlPoolsConnectionPoliciesClient: %+v", err) + } + + return &SqlPoolsConnectionPoliciesClient{ + Client: client, + }, nil +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolsconnectionpolicies/id_sqlpool.go b/resource-manager/synapse/2021-06-01/sqlpoolsconnectionpolicies/id_sqlpool.go new file mode 100644 index 00000000000..c1a1a38bf5e --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolsconnectionpolicies/id_sqlpool.go @@ -0,0 +1,134 @@ +package sqlpoolsconnectionpolicies + +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 = &SqlPoolId{} + +// SqlPoolId is a struct representing the Resource ID for a Sql Pool +type SqlPoolId struct { + SubscriptionId string + ResourceGroupName string + WorkspaceName string + SqlPoolName string +} + +// NewSqlPoolID returns a new SqlPoolId struct +func NewSqlPoolID(subscriptionId string, resourceGroupName string, workspaceName string, sqlPoolName string) SqlPoolId { + return SqlPoolId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + WorkspaceName: workspaceName, + SqlPoolName: sqlPoolName, + } +} + +// ParseSqlPoolID parses 'input' into a SqlPoolId +func ParseSqlPoolID(input string) (*SqlPoolId, error) { + parser := resourceids.NewParserFromResourceIdType(&SqlPoolId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := SqlPoolId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseSqlPoolIDInsensitively parses 'input' case-insensitively into a SqlPoolId +// note: this method should only be used for API response data and not user input +func ParseSqlPoolIDInsensitively(input string) (*SqlPoolId, error) { + parser := resourceids.NewParserFromResourceIdType(&SqlPoolId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := SqlPoolId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *SqlPoolId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.WorkspaceName, ok = input.Parsed["workspaceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "workspaceName", input) + } + + if id.SqlPoolName, ok = input.Parsed["sqlPoolName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "sqlPoolName", input) + } + + return nil +} + +// ValidateSqlPoolID checks that 'input' can be parsed as a Sql Pool ID +func ValidateSqlPoolID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseSqlPoolID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Sql Pool ID +func (id SqlPoolId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Synapse/workspaces/%s/sqlPools/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.WorkspaceName, id.SqlPoolName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Sql Pool ID +func (id SqlPoolId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftSynapse", "Microsoft.Synapse", "Microsoft.Synapse"), + resourceids.StaticSegment("staticWorkspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceName", "workspaceValue"), + resourceids.StaticSegment("staticSqlPools", "sqlPools", "sqlPools"), + resourceids.UserSpecifiedSegment("sqlPoolName", "sqlPoolValue"), + } +} + +// String returns a human-readable description of this Sql Pool ID +func (id SqlPoolId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Workspace Name: %q", id.WorkspaceName), + fmt.Sprintf("Sql Pool Name: %q", id.SqlPoolName), + } + return fmt.Sprintf("Sql Pool (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolsconnectionpolicies/id_sqlpool_test.go b/resource-manager/synapse/2021-06-01/sqlpoolsconnectionpolicies/id_sqlpool_test.go new file mode 100644 index 00000000000..a6327da533f --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolsconnectionpolicies/id_sqlpool_test.go @@ -0,0 +1,327 @@ +package sqlpoolsconnectionpolicies + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &SqlPoolId{} + +func TestNewSqlPoolID(t *testing.T) { + id := NewSqlPoolID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "sqlPoolValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.WorkspaceName != "workspaceValue" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceName'", id.WorkspaceName, "workspaceValue") + } + + if id.SqlPoolName != "sqlPoolValue" { + t.Fatalf("Expected %q but got %q for Segment 'SqlPoolName'", id.SqlPoolName, "sqlPoolValue") + } +} + +func TestFormatSqlPoolID(t *testing.T) { + actual := NewSqlPoolID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "sqlPoolValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseSqlPoolID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *SqlPoolId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue", + Expected: &SqlPoolId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + SqlPoolName: "sqlPoolValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseSqlPoolID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + if actual.SqlPoolName != v.Expected.SqlPoolName { + t.Fatalf("Expected %q but got %q for SqlPoolName", v.Expected.SqlPoolName, actual.SqlPoolName) + } + + } +} + +func TestParseSqlPoolIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *SqlPoolId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/sQlPoOlS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue", + Expected: &SqlPoolId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + SqlPoolName: "sqlPoolValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/sQlPoOlS/sQlPoOlVaLuE", + Expected: &SqlPoolId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + WorkspaceName: "wOrKsPaCeVaLuE", + SqlPoolName: "sQlPoOlVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/sQlPoOlS/sQlPoOlVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseSqlPoolIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + if actual.SqlPoolName != v.Expected.SqlPoolName { + t.Fatalf("Expected %q but got %q for SqlPoolName", v.Expected.SqlPoolName, actual.SqlPoolName) + } + + } +} + +func TestSegmentsForSqlPoolId(t *testing.T) { + segments := SqlPoolId{}.Segments() + if len(segments) == 0 { + t.Fatalf("SqlPoolId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolsconnectionpolicies/method_sqlpoolconnectionpoliciesget.go b/resource-manager/synapse/2021-06-01/sqlpoolsconnectionpolicies/method_sqlpoolconnectionpoliciesget.go new file mode 100644 index 00000000000..2de354d28f5 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolsconnectionpolicies/method_sqlpoolconnectionpoliciesget.go @@ -0,0 +1,52 @@ +package sqlpoolsconnectionpolicies + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SqlPoolConnectionPoliciesGetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *SqlPoolConnectionPolicy +} + +// SqlPoolConnectionPoliciesGet ... +func (c SqlPoolsConnectionPoliciesClient) SqlPoolConnectionPoliciesGet(ctx context.Context, id SqlPoolId) (result SqlPoolConnectionPoliciesGetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/connectionPolicies/default", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolsconnectionpolicies/model_sqlpoolconnectionpolicy.go b/resource-manager/synapse/2021-06-01/sqlpoolsconnectionpolicies/model_sqlpoolconnectionpolicy.go new file mode 100644 index 00000000000..374f1a8fd3f --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolsconnectionpolicies/model_sqlpoolconnectionpolicy.go @@ -0,0 +1,13 @@ +package sqlpoolsconnectionpolicies + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SqlPoolConnectionPolicy struct { + Id *string `json:"id,omitempty"` + Kind *string `json:"kind,omitempty"` + Location *string `json:"location,omitempty"` + Name *string `json:"name,omitempty"` + Properties *SqlPoolConnectionPolicyProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolsconnectionpolicies/model_sqlpoolconnectionpolicyproperties.go b/resource-manager/synapse/2021-06-01/sqlpoolsconnectionpolicies/model_sqlpoolconnectionpolicyproperties.go new file mode 100644 index 00000000000..25db24820d8 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolsconnectionpolicies/model_sqlpoolconnectionpolicyproperties.go @@ -0,0 +1,14 @@ +package sqlpoolsconnectionpolicies + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SqlPoolConnectionPolicyProperties struct { + ProxyDnsName *string `json:"proxyDnsName,omitempty"` + ProxyPort *string `json:"proxyPort,omitempty"` + RedirectionState *string `json:"redirectionState,omitempty"` + SecurityEnabledAccess *string `json:"securityEnabledAccess,omitempty"` + State *string `json:"state,omitempty"` + UseServerDefault *string `json:"useServerDefault,omitempty"` + Visibility *string `json:"visibility,omitempty"` +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolsconnectionpolicies/version.go b/resource-manager/synapse/2021-06-01/sqlpoolsconnectionpolicies/version.go new file mode 100644 index 00000000000..ea63b388c87 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolsconnectionpolicies/version.go @@ -0,0 +1,12 @@ +package sqlpoolsconnectionpolicies + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2021-06-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/sqlpoolsconnectionpolicies/%s", defaultApiVersion) +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolsdatabasevulnerabilityassesmentrulebaselines/README.md b/resource-manager/synapse/2021-06-01/sqlpoolsdatabasevulnerabilityassesmentrulebaselines/README.md new file mode 100644 index 00000000000..4695e619821 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolsdatabasevulnerabilityassesmentrulebaselines/README.md @@ -0,0 +1,41 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/synapse/2021-06-01/sqlpoolsdatabasevulnerabilityassesmentrulebaselines` Documentation + +The `sqlpoolsdatabasevulnerabilityassesmentrulebaselines` SDK allows for interaction with the Azure Resource Manager Service `synapse` (API Version `2021-06-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/synapse/2021-06-01/sqlpoolsdatabasevulnerabilityassesmentrulebaselines" +``` + + +### Client Initialization + +```go +client := sqlpoolsdatabasevulnerabilityassesmentrulebaselines.NewSqlPoolsDatabaseVulnerabilityAssesmentRuleBaselinesClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `SqlPoolsDatabaseVulnerabilityAssesmentRuleBaselinesClient.SqlPoolVulnerabilityAssessmentRuleBaselinesCreateOrUpdate` + +```go +ctx := context.TODO() +id := sqlpoolsdatabasevulnerabilityassesmentrulebaselines.NewBaselineID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "sqlPoolValue", "ruleIdValue", "default") + +payload := sqlpoolsdatabasevulnerabilityassesmentrulebaselines.SqlPoolVulnerabilityAssessmentRuleBaseline{ + // ... +} + + +read, err := client.SqlPoolVulnerabilityAssessmentRuleBaselinesCreateOrUpdate(ctx, id, payload) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` diff --git a/resource-manager/synapse/2021-06-01/sqlpoolsdatabasevulnerabilityassesmentrulebaselines/client.go b/resource-manager/synapse/2021-06-01/sqlpoolsdatabasevulnerabilityassesmentrulebaselines/client.go new file mode 100644 index 00000000000..b39fc44fff2 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolsdatabasevulnerabilityassesmentrulebaselines/client.go @@ -0,0 +1,26 @@ +package sqlpoolsdatabasevulnerabilityassesmentrulebaselines + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SqlPoolsDatabaseVulnerabilityAssesmentRuleBaselinesClient struct { + Client *resourcemanager.Client +} + +func NewSqlPoolsDatabaseVulnerabilityAssesmentRuleBaselinesClientWithBaseURI(sdkApi sdkEnv.Api) (*SqlPoolsDatabaseVulnerabilityAssesmentRuleBaselinesClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "sqlpoolsdatabasevulnerabilityassesmentrulebaselines", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating SqlPoolsDatabaseVulnerabilityAssesmentRuleBaselinesClient: %+v", err) + } + + return &SqlPoolsDatabaseVulnerabilityAssesmentRuleBaselinesClient{ + Client: client, + }, nil +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolsdatabasevulnerabilityassesmentrulebaselines/constants.go b/resource-manager/synapse/2021-06-01/sqlpoolsdatabasevulnerabilityassesmentrulebaselines/constants.go new file mode 100644 index 00000000000..6706ef1712d --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolsdatabasevulnerabilityassesmentrulebaselines/constants.go @@ -0,0 +1,51 @@ +package sqlpoolsdatabasevulnerabilityassesmentrulebaselines + +import ( + "encoding/json" + "fmt" + "strings" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type VulnerabilityAssessmentPolicyBaselineName string + +const ( + VulnerabilityAssessmentPolicyBaselineNameDefault VulnerabilityAssessmentPolicyBaselineName = "default" + VulnerabilityAssessmentPolicyBaselineNameMaster VulnerabilityAssessmentPolicyBaselineName = "master" +) + +func PossibleValuesForVulnerabilityAssessmentPolicyBaselineName() []string { + return []string{ + string(VulnerabilityAssessmentPolicyBaselineNameDefault), + string(VulnerabilityAssessmentPolicyBaselineNameMaster), + } +} + +func (s *VulnerabilityAssessmentPolicyBaselineName) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseVulnerabilityAssessmentPolicyBaselineName(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseVulnerabilityAssessmentPolicyBaselineName(input string) (*VulnerabilityAssessmentPolicyBaselineName, error) { + vals := map[string]VulnerabilityAssessmentPolicyBaselineName{ + "default": VulnerabilityAssessmentPolicyBaselineNameDefault, + "master": VulnerabilityAssessmentPolicyBaselineNameMaster, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := VulnerabilityAssessmentPolicyBaselineName(input) + return &out, nil +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolsdatabasevulnerabilityassesmentrulebaselines/id_baseline.go b/resource-manager/synapse/2021-06-01/sqlpoolsdatabasevulnerabilityassesmentrulebaselines/id_baseline.go new file mode 100644 index 00000000000..a04bee9c818 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolsdatabasevulnerabilityassesmentrulebaselines/id_baseline.go @@ -0,0 +1,162 @@ +package sqlpoolsdatabasevulnerabilityassesmentrulebaselines + +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 = &BaselineId{} + +// BaselineId is a struct representing the Resource ID for a Baseline +type BaselineId struct { + SubscriptionId string + ResourceGroupName string + WorkspaceName string + SqlPoolName string + RuleId string + BaselineName VulnerabilityAssessmentPolicyBaselineName +} + +// NewBaselineID returns a new BaselineId struct +func NewBaselineID(subscriptionId string, resourceGroupName string, workspaceName string, sqlPoolName string, ruleId string, baselineName VulnerabilityAssessmentPolicyBaselineName) BaselineId { + return BaselineId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + WorkspaceName: workspaceName, + SqlPoolName: sqlPoolName, + RuleId: ruleId, + BaselineName: baselineName, + } +} + +// ParseBaselineID parses 'input' into a BaselineId +func ParseBaselineID(input string) (*BaselineId, error) { + parser := resourceids.NewParserFromResourceIdType(&BaselineId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := BaselineId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseBaselineIDInsensitively parses 'input' case-insensitively into a BaselineId +// note: this method should only be used for API response data and not user input +func ParseBaselineIDInsensitively(input string) (*BaselineId, error) { + parser := resourceids.NewParserFromResourceIdType(&BaselineId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := BaselineId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *BaselineId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.WorkspaceName, ok = input.Parsed["workspaceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "workspaceName", input) + } + + if id.SqlPoolName, ok = input.Parsed["sqlPoolName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "sqlPoolName", input) + } + + if id.RuleId, ok = input.Parsed["ruleId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "ruleId", input) + } + + if v, ok := input.Parsed["baselineName"]; true { + if !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "baselineName", input) + } + + baselineName, err := parseVulnerabilityAssessmentPolicyBaselineName(v) + if err != nil { + return fmt.Errorf("parsing %q: %+v", v, err) + } + id.BaselineName = *baselineName + } + + return nil +} + +// ValidateBaselineID checks that 'input' can be parsed as a Baseline ID +func ValidateBaselineID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseBaselineID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Baseline ID +func (id BaselineId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Synapse/workspaces/%s/sqlPools/%s/vulnerabilityAssessments/default/rules/%s/baselines/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.WorkspaceName, id.SqlPoolName, id.RuleId, string(id.BaselineName)) +} + +// Segments returns a slice of Resource ID Segments which comprise this Baseline ID +func (id BaselineId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftSynapse", "Microsoft.Synapse", "Microsoft.Synapse"), + resourceids.StaticSegment("staticWorkspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceName", "workspaceValue"), + resourceids.StaticSegment("staticSqlPools", "sqlPools", "sqlPools"), + resourceids.UserSpecifiedSegment("sqlPoolName", "sqlPoolValue"), + resourceids.StaticSegment("staticVulnerabilityAssessments", "vulnerabilityAssessments", "vulnerabilityAssessments"), + resourceids.StaticSegment("vulnerabilityAssessmentName", "default", "default"), + resourceids.StaticSegment("staticRules", "rules", "rules"), + resourceids.UserSpecifiedSegment("ruleId", "ruleIdValue"), + resourceids.StaticSegment("staticBaselines", "baselines", "baselines"), + resourceids.ConstantSegment("baselineName", PossibleValuesForVulnerabilityAssessmentPolicyBaselineName(), "default"), + } +} + +// String returns a human-readable description of this Baseline ID +func (id BaselineId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Workspace Name: %q", id.WorkspaceName), + fmt.Sprintf("Sql Pool Name: %q", id.SqlPoolName), + fmt.Sprintf("Rule: %q", id.RuleId), + fmt.Sprintf("Baseline Name: %q", string(id.BaselineName)), + } + return fmt.Sprintf("Baseline (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolsdatabasevulnerabilityassesmentrulebaselines/id_baseline_test.go b/resource-manager/synapse/2021-06-01/sqlpoolsdatabasevulnerabilityassesmentrulebaselines/id_baseline_test.go new file mode 100644 index 00000000000..e539761efd0 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolsdatabasevulnerabilityassesmentrulebaselines/id_baseline_test.go @@ -0,0 +1,447 @@ +package sqlpoolsdatabasevulnerabilityassesmentrulebaselines + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &BaselineId{} + +func TestNewBaselineID(t *testing.T) { + id := NewBaselineID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "sqlPoolValue", "ruleIdValue", "default") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.WorkspaceName != "workspaceValue" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceName'", id.WorkspaceName, "workspaceValue") + } + + if id.SqlPoolName != "sqlPoolValue" { + t.Fatalf("Expected %q but got %q for Segment 'SqlPoolName'", id.SqlPoolName, "sqlPoolValue") + } + + if id.RuleId != "ruleIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'RuleId'", id.RuleId, "ruleIdValue") + } + + if id.BaselineName != "default" { + t.Fatalf("Expected %q but got %q for Segment 'BaselineName'", id.BaselineName, "default") + } +} + +func TestFormatBaselineID(t *testing.T) { + actual := NewBaselineID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "sqlPoolValue", "ruleIdValue", "default").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/vulnerabilityAssessments/default/rules/ruleIdValue/baselines/default" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseBaselineID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *BaselineId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/vulnerabilityAssessments", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/vulnerabilityAssessments/default", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/vulnerabilityAssessments/default/rules", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/vulnerabilityAssessments/default/rules/ruleIdValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/vulnerabilityAssessments/default/rules/ruleIdValue/baselines", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/vulnerabilityAssessments/default/rules/ruleIdValue/baselines/default", + Expected: &BaselineId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + SqlPoolName: "sqlPoolValue", + RuleId: "ruleIdValue", + BaselineName: "default", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/vulnerabilityAssessments/default/rules/ruleIdValue/baselines/default/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseBaselineID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + if actual.SqlPoolName != v.Expected.SqlPoolName { + t.Fatalf("Expected %q but got %q for SqlPoolName", v.Expected.SqlPoolName, actual.SqlPoolName) + } + + if actual.RuleId != v.Expected.RuleId { + t.Fatalf("Expected %q but got %q for RuleId", v.Expected.RuleId, actual.RuleId) + } + + if actual.BaselineName != v.Expected.BaselineName { + t.Fatalf("Expected %q but got %q for BaselineName", v.Expected.BaselineName, actual.BaselineName) + } + + } +} + +func TestParseBaselineIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *BaselineId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/sQlPoOlS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/sQlPoOlS/sQlPoOlVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/vulnerabilityAssessments", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/sQlPoOlS/sQlPoOlVaLuE/vUlNeRaBiLiTyAsSeSsMeNtS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/vulnerabilityAssessments/default", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/sQlPoOlS/sQlPoOlVaLuE/vUlNeRaBiLiTyAsSeSsMeNtS/dEfAuLt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/vulnerabilityAssessments/default/rules", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/sQlPoOlS/sQlPoOlVaLuE/vUlNeRaBiLiTyAsSeSsMeNtS/dEfAuLt/rUlEs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/vulnerabilityAssessments/default/rules/ruleIdValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/sQlPoOlS/sQlPoOlVaLuE/vUlNeRaBiLiTyAsSeSsMeNtS/dEfAuLt/rUlEs/rUlEiDvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/vulnerabilityAssessments/default/rules/ruleIdValue/baselines", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/sQlPoOlS/sQlPoOlVaLuE/vUlNeRaBiLiTyAsSeSsMeNtS/dEfAuLt/rUlEs/rUlEiDvAlUe/bAsElInEs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/vulnerabilityAssessments/default/rules/ruleIdValue/baselines/default", + Expected: &BaselineId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + SqlPoolName: "sqlPoolValue", + RuleId: "ruleIdValue", + BaselineName: "default", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/vulnerabilityAssessments/default/rules/ruleIdValue/baselines/default/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/sQlPoOlS/sQlPoOlVaLuE/vUlNeRaBiLiTyAsSeSsMeNtS/dEfAuLt/rUlEs/rUlEiDvAlUe/bAsElInEs/dEfAuLt", + Expected: &BaselineId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + WorkspaceName: "wOrKsPaCeVaLuE", + SqlPoolName: "sQlPoOlVaLuE", + RuleId: "rUlEiDvAlUe", + BaselineName: "default", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/sQlPoOlS/sQlPoOlVaLuE/vUlNeRaBiLiTyAsSeSsMeNtS/dEfAuLt/rUlEs/rUlEiDvAlUe/bAsElInEs/dEfAuLt/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseBaselineIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + if actual.SqlPoolName != v.Expected.SqlPoolName { + t.Fatalf("Expected %q but got %q for SqlPoolName", v.Expected.SqlPoolName, actual.SqlPoolName) + } + + if actual.RuleId != v.Expected.RuleId { + t.Fatalf("Expected %q but got %q for RuleId", v.Expected.RuleId, actual.RuleId) + } + + if actual.BaselineName != v.Expected.BaselineName { + t.Fatalf("Expected %q but got %q for BaselineName", v.Expected.BaselineName, actual.BaselineName) + } + + } +} + +func TestSegmentsForBaselineId(t *testing.T) { + segments := BaselineId{}.Segments() + if len(segments) == 0 { + t.Fatalf("BaselineId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolsdatabasevulnerabilityassesmentrulebaselines/method_sqlpoolvulnerabilityassessmentrulebaselinescreateorupdate.go b/resource-manager/synapse/2021-06-01/sqlpoolsdatabasevulnerabilityassesmentrulebaselines/method_sqlpoolvulnerabilityassessmentrulebaselinescreateorupdate.go new file mode 100644 index 00000000000..e03dc06b1f5 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolsdatabasevulnerabilityassesmentrulebaselines/method_sqlpoolvulnerabilityassessmentrulebaselinescreateorupdate.go @@ -0,0 +1,55 @@ +package sqlpoolsdatabasevulnerabilityassesmentrulebaselines + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SqlPoolVulnerabilityAssessmentRuleBaselinesCreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *SqlPoolVulnerabilityAssessmentRuleBaseline +} + +// SqlPoolVulnerabilityAssessmentRuleBaselinesCreateOrUpdate ... +func (c SqlPoolsDatabaseVulnerabilityAssesmentRuleBaselinesClient) SqlPoolVulnerabilityAssessmentRuleBaselinesCreateOrUpdate(ctx context.Context, id BaselineId, input SqlPoolVulnerabilityAssessmentRuleBaseline) (result SqlPoolVulnerabilityAssessmentRuleBaselinesCreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolsdatabasevulnerabilityassesmentrulebaselines/model_sqlpoolvulnerabilityassessmentrulebaseline.go b/resource-manager/synapse/2021-06-01/sqlpoolsdatabasevulnerabilityassesmentrulebaselines/model_sqlpoolvulnerabilityassessmentrulebaseline.go new file mode 100644 index 00000000000..5a5be9ecef9 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolsdatabasevulnerabilityassesmentrulebaselines/model_sqlpoolvulnerabilityassessmentrulebaseline.go @@ -0,0 +1,11 @@ +package sqlpoolsdatabasevulnerabilityassesmentrulebaselines + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SqlPoolVulnerabilityAssessmentRuleBaseline struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *SqlPoolVulnerabilityAssessmentRuleBaselineProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolsdatabasevulnerabilityassesmentrulebaselines/model_sqlpoolvulnerabilityassessmentrulebaselineitem.go b/resource-manager/synapse/2021-06-01/sqlpoolsdatabasevulnerabilityassesmentrulebaselines/model_sqlpoolvulnerabilityassessmentrulebaselineitem.go new file mode 100644 index 00000000000..0d97be5bb5e --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolsdatabasevulnerabilityassesmentrulebaselines/model_sqlpoolvulnerabilityassessmentrulebaselineitem.go @@ -0,0 +1,8 @@ +package sqlpoolsdatabasevulnerabilityassesmentrulebaselines + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SqlPoolVulnerabilityAssessmentRuleBaselineItem struct { + Result []string `json:"result"` +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolsdatabasevulnerabilityassesmentrulebaselines/model_sqlpoolvulnerabilityassessmentrulebaselineproperties.go b/resource-manager/synapse/2021-06-01/sqlpoolsdatabasevulnerabilityassesmentrulebaselines/model_sqlpoolvulnerabilityassessmentrulebaselineproperties.go new file mode 100644 index 00000000000..6911befb4f6 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolsdatabasevulnerabilityassesmentrulebaselines/model_sqlpoolvulnerabilityassessmentrulebaselineproperties.go @@ -0,0 +1,8 @@ +package sqlpoolsdatabasevulnerabilityassesmentrulebaselines + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SqlPoolVulnerabilityAssessmentRuleBaselineProperties struct { + BaselineResults []SqlPoolVulnerabilityAssessmentRuleBaselineItem `json:"baselineResults"` +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolsdatabasevulnerabilityassesmentrulebaselines/version.go b/resource-manager/synapse/2021-06-01/sqlpoolsdatabasevulnerabilityassesmentrulebaselines/version.go new file mode 100644 index 00000000000..ce619a75b5d --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolsdatabasevulnerabilityassesmentrulebaselines/version.go @@ -0,0 +1,12 @@ +package sqlpoolsdatabasevulnerabilityassesmentrulebaselines + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2021-06-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/sqlpoolsdatabasevulnerabilityassesmentrulebaselines/%s", defaultApiVersion) +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolsdatamaskingpolicies/README.md b/resource-manager/synapse/2021-06-01/sqlpoolsdatamaskingpolicies/README.md new file mode 100644 index 00000000000..12a8d918927 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolsdatamaskingpolicies/README.md @@ -0,0 +1,57 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/synapse/2021-06-01/sqlpoolsdatamaskingpolicies` Documentation + +The `sqlpoolsdatamaskingpolicies` SDK allows for interaction with the Azure Resource Manager Service `synapse` (API Version `2021-06-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/synapse/2021-06-01/sqlpoolsdatamaskingpolicies" +``` + + +### Client Initialization + +```go +client := sqlpoolsdatamaskingpolicies.NewSqlPoolsDataMaskingPoliciesClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `SqlPoolsDataMaskingPoliciesClient.DataMaskingPoliciesCreateOrUpdate` + +```go +ctx := context.TODO() +id := sqlpoolsdatamaskingpolicies.NewSqlPoolID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "sqlPoolValue") + +payload := sqlpoolsdatamaskingpolicies.DataMaskingPolicy{ + // ... +} + + +read, err := client.DataMaskingPoliciesCreateOrUpdate(ctx, id, payload) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `SqlPoolsDataMaskingPoliciesClient.DataMaskingPoliciesGet` + +```go +ctx := context.TODO() +id := sqlpoolsdatamaskingpolicies.NewSqlPoolID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "sqlPoolValue") + +read, err := client.DataMaskingPoliciesGet(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` diff --git a/resource-manager/synapse/2021-06-01/sqlpoolsdatamaskingpolicies/client.go b/resource-manager/synapse/2021-06-01/sqlpoolsdatamaskingpolicies/client.go new file mode 100644 index 00000000000..401fccc9306 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolsdatamaskingpolicies/client.go @@ -0,0 +1,26 @@ +package sqlpoolsdatamaskingpolicies + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SqlPoolsDataMaskingPoliciesClient struct { + Client *resourcemanager.Client +} + +func NewSqlPoolsDataMaskingPoliciesClientWithBaseURI(sdkApi sdkEnv.Api) (*SqlPoolsDataMaskingPoliciesClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "sqlpoolsdatamaskingpolicies", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating SqlPoolsDataMaskingPoliciesClient: %+v", err) + } + + return &SqlPoolsDataMaskingPoliciesClient{ + Client: client, + }, nil +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolsdatamaskingpolicies/constants.go b/resource-manager/synapse/2021-06-01/sqlpoolsdatamaskingpolicies/constants.go new file mode 100644 index 00000000000..a84b87a277a --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolsdatamaskingpolicies/constants.go @@ -0,0 +1,51 @@ +package sqlpoolsdatamaskingpolicies + +import ( + "encoding/json" + "fmt" + "strings" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DataMaskingState string + +const ( + DataMaskingStateDisabled DataMaskingState = "Disabled" + DataMaskingStateEnabled DataMaskingState = "Enabled" +) + +func PossibleValuesForDataMaskingState() []string { + return []string{ + string(DataMaskingStateDisabled), + string(DataMaskingStateEnabled), + } +} + +func (s *DataMaskingState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseDataMaskingState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseDataMaskingState(input string) (*DataMaskingState, error) { + vals := map[string]DataMaskingState{ + "disabled": DataMaskingStateDisabled, + "enabled": DataMaskingStateEnabled, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := DataMaskingState(input) + return &out, nil +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolsdatamaskingpolicies/id_sqlpool.go b/resource-manager/synapse/2021-06-01/sqlpoolsdatamaskingpolicies/id_sqlpool.go new file mode 100644 index 00000000000..3aa41c6e269 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolsdatamaskingpolicies/id_sqlpool.go @@ -0,0 +1,134 @@ +package sqlpoolsdatamaskingpolicies + +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 = &SqlPoolId{} + +// SqlPoolId is a struct representing the Resource ID for a Sql Pool +type SqlPoolId struct { + SubscriptionId string + ResourceGroupName string + WorkspaceName string + SqlPoolName string +} + +// NewSqlPoolID returns a new SqlPoolId struct +func NewSqlPoolID(subscriptionId string, resourceGroupName string, workspaceName string, sqlPoolName string) SqlPoolId { + return SqlPoolId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + WorkspaceName: workspaceName, + SqlPoolName: sqlPoolName, + } +} + +// ParseSqlPoolID parses 'input' into a SqlPoolId +func ParseSqlPoolID(input string) (*SqlPoolId, error) { + parser := resourceids.NewParserFromResourceIdType(&SqlPoolId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := SqlPoolId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseSqlPoolIDInsensitively parses 'input' case-insensitively into a SqlPoolId +// note: this method should only be used for API response data and not user input +func ParseSqlPoolIDInsensitively(input string) (*SqlPoolId, error) { + parser := resourceids.NewParserFromResourceIdType(&SqlPoolId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := SqlPoolId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *SqlPoolId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.WorkspaceName, ok = input.Parsed["workspaceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "workspaceName", input) + } + + if id.SqlPoolName, ok = input.Parsed["sqlPoolName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "sqlPoolName", input) + } + + return nil +} + +// ValidateSqlPoolID checks that 'input' can be parsed as a Sql Pool ID +func ValidateSqlPoolID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseSqlPoolID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Sql Pool ID +func (id SqlPoolId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Synapse/workspaces/%s/sqlPools/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.WorkspaceName, id.SqlPoolName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Sql Pool ID +func (id SqlPoolId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftSynapse", "Microsoft.Synapse", "Microsoft.Synapse"), + resourceids.StaticSegment("staticWorkspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceName", "workspaceValue"), + resourceids.StaticSegment("staticSqlPools", "sqlPools", "sqlPools"), + resourceids.UserSpecifiedSegment("sqlPoolName", "sqlPoolValue"), + } +} + +// String returns a human-readable description of this Sql Pool ID +func (id SqlPoolId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Workspace Name: %q", id.WorkspaceName), + fmt.Sprintf("Sql Pool Name: %q", id.SqlPoolName), + } + return fmt.Sprintf("Sql Pool (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolsdatamaskingpolicies/id_sqlpool_test.go b/resource-manager/synapse/2021-06-01/sqlpoolsdatamaskingpolicies/id_sqlpool_test.go new file mode 100644 index 00000000000..6a13cbbd033 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolsdatamaskingpolicies/id_sqlpool_test.go @@ -0,0 +1,327 @@ +package sqlpoolsdatamaskingpolicies + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &SqlPoolId{} + +func TestNewSqlPoolID(t *testing.T) { + id := NewSqlPoolID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "sqlPoolValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.WorkspaceName != "workspaceValue" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceName'", id.WorkspaceName, "workspaceValue") + } + + if id.SqlPoolName != "sqlPoolValue" { + t.Fatalf("Expected %q but got %q for Segment 'SqlPoolName'", id.SqlPoolName, "sqlPoolValue") + } +} + +func TestFormatSqlPoolID(t *testing.T) { + actual := NewSqlPoolID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "sqlPoolValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseSqlPoolID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *SqlPoolId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue", + Expected: &SqlPoolId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + SqlPoolName: "sqlPoolValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseSqlPoolID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + if actual.SqlPoolName != v.Expected.SqlPoolName { + t.Fatalf("Expected %q but got %q for SqlPoolName", v.Expected.SqlPoolName, actual.SqlPoolName) + } + + } +} + +func TestParseSqlPoolIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *SqlPoolId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/sQlPoOlS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue", + Expected: &SqlPoolId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + SqlPoolName: "sqlPoolValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/sQlPoOlS/sQlPoOlVaLuE", + Expected: &SqlPoolId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + WorkspaceName: "wOrKsPaCeVaLuE", + SqlPoolName: "sQlPoOlVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/sQlPoOlS/sQlPoOlVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseSqlPoolIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + if actual.SqlPoolName != v.Expected.SqlPoolName { + t.Fatalf("Expected %q but got %q for SqlPoolName", v.Expected.SqlPoolName, actual.SqlPoolName) + } + + } +} + +func TestSegmentsForSqlPoolId(t *testing.T) { + segments := SqlPoolId{}.Segments() + if len(segments) == 0 { + t.Fatalf("SqlPoolId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolsdatamaskingpolicies/method_datamaskingpoliciescreateorupdate.go b/resource-manager/synapse/2021-06-01/sqlpoolsdatamaskingpolicies/method_datamaskingpoliciescreateorupdate.go new file mode 100644 index 00000000000..59f8194e3a6 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolsdatamaskingpolicies/method_datamaskingpoliciescreateorupdate.go @@ -0,0 +1,56 @@ +package sqlpoolsdatamaskingpolicies + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DataMaskingPoliciesCreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *DataMaskingPolicy +} + +// DataMaskingPoliciesCreateOrUpdate ... +func (c SqlPoolsDataMaskingPoliciesClient) DataMaskingPoliciesCreateOrUpdate(ctx context.Context, id SqlPoolId, input DataMaskingPolicy) (result DataMaskingPoliciesCreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: fmt.Sprintf("%s/dataMaskingPolicies/default", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolsdatamaskingpolicies/method_datamaskingpoliciesget.go b/resource-manager/synapse/2021-06-01/sqlpoolsdatamaskingpolicies/method_datamaskingpoliciesget.go new file mode 100644 index 00000000000..50ebd180db6 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolsdatamaskingpolicies/method_datamaskingpoliciesget.go @@ -0,0 +1,52 @@ +package sqlpoolsdatamaskingpolicies + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DataMaskingPoliciesGetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *DataMaskingPolicy +} + +// DataMaskingPoliciesGet ... +func (c SqlPoolsDataMaskingPoliciesClient) DataMaskingPoliciesGet(ctx context.Context, id SqlPoolId) (result DataMaskingPoliciesGetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/dataMaskingPolicies/default", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolsdatamaskingpolicies/model_datamaskingpolicy.go b/resource-manager/synapse/2021-06-01/sqlpoolsdatamaskingpolicies/model_datamaskingpolicy.go new file mode 100644 index 00000000000..e7b6c1e77ca --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolsdatamaskingpolicies/model_datamaskingpolicy.go @@ -0,0 +1,14 @@ +package sqlpoolsdatamaskingpolicies + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DataMaskingPolicy struct { + Id *string `json:"id,omitempty"` + Kind *string `json:"kind,omitempty"` + Location *string `json:"location,omitempty"` + ManagedBy *string `json:"managedBy,omitempty"` + Name *string `json:"name,omitempty"` + Properties *DataMaskingPolicyProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolsdatamaskingpolicies/model_datamaskingpolicyproperties.go b/resource-manager/synapse/2021-06-01/sqlpoolsdatamaskingpolicies/model_datamaskingpolicyproperties.go new file mode 100644 index 00000000000..bd6dc9dbfbc --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolsdatamaskingpolicies/model_datamaskingpolicyproperties.go @@ -0,0 +1,11 @@ +package sqlpoolsdatamaskingpolicies + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DataMaskingPolicyProperties struct { + ApplicationPrincipals *string `json:"applicationPrincipals,omitempty"` + DataMaskingState DataMaskingState `json:"dataMaskingState"` + ExemptPrincipals *string `json:"exemptPrincipals,omitempty"` + MaskingLevel *string `json:"maskingLevel,omitempty"` +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolsdatamaskingpolicies/version.go b/resource-manager/synapse/2021-06-01/sqlpoolsdatamaskingpolicies/version.go new file mode 100644 index 00000000000..5fd0f742d32 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolsdatamaskingpolicies/version.go @@ -0,0 +1,12 @@ +package sqlpoolsdatamaskingpolicies + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2021-06-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/sqlpoolsdatamaskingpolicies/%s", defaultApiVersion) +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolsdatamaskingrules/README.md b/resource-manager/synapse/2021-06-01/sqlpoolsdatamaskingrules/README.md new file mode 100644 index 00000000000..16327ec35e4 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolsdatamaskingrules/README.md @@ -0,0 +1,73 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/synapse/2021-06-01/sqlpoolsdatamaskingrules` Documentation + +The `sqlpoolsdatamaskingrules` SDK allows for interaction with the Azure Resource Manager Service `synapse` (API Version `2021-06-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/synapse/2021-06-01/sqlpoolsdatamaskingrules" +``` + + +### Client Initialization + +```go +client := sqlpoolsdatamaskingrules.NewSqlPoolsDataMaskingRulesClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `SqlPoolsDataMaskingRulesClient.DataMaskingRulesCreateOrUpdate` + +```go +ctx := context.TODO() +id := sqlpoolsdatamaskingrules.NewRuleID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "sqlPoolValue", "ruleValue") + +payload := sqlpoolsdatamaskingrules.DataMaskingRule{ + // ... +} + + +read, err := client.DataMaskingRulesCreateOrUpdate(ctx, id, payload) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `SqlPoolsDataMaskingRulesClient.DataMaskingRulesGet` + +```go +ctx := context.TODO() +id := sqlpoolsdatamaskingrules.NewRuleID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "sqlPoolValue", "ruleValue") + +read, err := client.DataMaskingRulesGet(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `SqlPoolsDataMaskingRulesClient.DataMaskingRulesListBySqlPool` + +```go +ctx := context.TODO() +id := sqlpoolsdatamaskingrules.NewSqlPoolID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "sqlPoolValue") + +read, err := client.DataMaskingRulesListBySqlPool(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` diff --git a/resource-manager/synapse/2021-06-01/sqlpoolsdatamaskingrules/client.go b/resource-manager/synapse/2021-06-01/sqlpoolsdatamaskingrules/client.go new file mode 100644 index 00000000000..d28cee23733 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolsdatamaskingrules/client.go @@ -0,0 +1,26 @@ +package sqlpoolsdatamaskingrules + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SqlPoolsDataMaskingRulesClient struct { + Client *resourcemanager.Client +} + +func NewSqlPoolsDataMaskingRulesClientWithBaseURI(sdkApi sdkEnv.Api) (*SqlPoolsDataMaskingRulesClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "sqlpoolsdatamaskingrules", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating SqlPoolsDataMaskingRulesClient: %+v", err) + } + + return &SqlPoolsDataMaskingRulesClient{ + Client: client, + }, nil +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolsdatamaskingrules/constants.go b/resource-manager/synapse/2021-06-01/sqlpoolsdatamaskingrules/constants.go new file mode 100644 index 00000000000..03572c6d6df --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolsdatamaskingrules/constants.go @@ -0,0 +1,104 @@ +package sqlpoolsdatamaskingrules + +import ( + "encoding/json" + "fmt" + "strings" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DataMaskingFunction string + +const ( + DataMaskingFunctionCCN DataMaskingFunction = "CCN" + DataMaskingFunctionDefault DataMaskingFunction = "Default" + DataMaskingFunctionEmail DataMaskingFunction = "Email" + DataMaskingFunctionNumber DataMaskingFunction = "Number" + DataMaskingFunctionSSN DataMaskingFunction = "SSN" + DataMaskingFunctionText DataMaskingFunction = "Text" +) + +func PossibleValuesForDataMaskingFunction() []string { + return []string{ + string(DataMaskingFunctionCCN), + string(DataMaskingFunctionDefault), + string(DataMaskingFunctionEmail), + string(DataMaskingFunctionNumber), + string(DataMaskingFunctionSSN), + string(DataMaskingFunctionText), + } +} + +func (s *DataMaskingFunction) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseDataMaskingFunction(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseDataMaskingFunction(input string) (*DataMaskingFunction, error) { + vals := map[string]DataMaskingFunction{ + "ccn": DataMaskingFunctionCCN, + "default": DataMaskingFunctionDefault, + "email": DataMaskingFunctionEmail, + "number": DataMaskingFunctionNumber, + "ssn": DataMaskingFunctionSSN, + "text": DataMaskingFunctionText, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := DataMaskingFunction(input) + return &out, nil +} + +type DataMaskingRuleState string + +const ( + DataMaskingRuleStateDisabled DataMaskingRuleState = "Disabled" + DataMaskingRuleStateEnabled DataMaskingRuleState = "Enabled" +) + +func PossibleValuesForDataMaskingRuleState() []string { + return []string{ + string(DataMaskingRuleStateDisabled), + string(DataMaskingRuleStateEnabled), + } +} + +func (s *DataMaskingRuleState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseDataMaskingRuleState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseDataMaskingRuleState(input string) (*DataMaskingRuleState, error) { + vals := map[string]DataMaskingRuleState{ + "disabled": DataMaskingRuleStateDisabled, + "enabled": DataMaskingRuleStateEnabled, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := DataMaskingRuleState(input) + return &out, nil +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolsdatamaskingrules/id_rule.go b/resource-manager/synapse/2021-06-01/sqlpoolsdatamaskingrules/id_rule.go new file mode 100644 index 00000000000..8b05b02cd81 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolsdatamaskingrules/id_rule.go @@ -0,0 +1,145 @@ +package sqlpoolsdatamaskingrules + +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 = &RuleId{} + +// RuleId is a struct representing the Resource ID for a Rule +type RuleId struct { + SubscriptionId string + ResourceGroupName string + WorkspaceName string + SqlPoolName string + RuleName string +} + +// NewRuleID returns a new RuleId struct +func NewRuleID(subscriptionId string, resourceGroupName string, workspaceName string, sqlPoolName string, ruleName string) RuleId { + return RuleId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + WorkspaceName: workspaceName, + SqlPoolName: sqlPoolName, + RuleName: ruleName, + } +} + +// ParseRuleID parses 'input' into a RuleId +func ParseRuleID(input string) (*RuleId, error) { + parser := resourceids.NewParserFromResourceIdType(&RuleId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := RuleId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseRuleIDInsensitively parses 'input' case-insensitively into a RuleId +// note: this method should only be used for API response data and not user input +func ParseRuleIDInsensitively(input string) (*RuleId, error) { + parser := resourceids.NewParserFromResourceIdType(&RuleId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := RuleId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *RuleId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.WorkspaceName, ok = input.Parsed["workspaceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "workspaceName", input) + } + + if id.SqlPoolName, ok = input.Parsed["sqlPoolName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "sqlPoolName", input) + } + + if id.RuleName, ok = input.Parsed["ruleName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "ruleName", input) + } + + return nil +} + +// ValidateRuleID checks that 'input' can be parsed as a Rule ID +func ValidateRuleID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseRuleID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Rule ID +func (id RuleId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Synapse/workspaces/%s/sqlPools/%s/dataMaskingPolicies/default/rules/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.WorkspaceName, id.SqlPoolName, id.RuleName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Rule ID +func (id RuleId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftSynapse", "Microsoft.Synapse", "Microsoft.Synapse"), + resourceids.StaticSegment("staticWorkspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceName", "workspaceValue"), + resourceids.StaticSegment("staticSqlPools", "sqlPools", "sqlPools"), + resourceids.UserSpecifiedSegment("sqlPoolName", "sqlPoolValue"), + resourceids.StaticSegment("staticDataMaskingPolicies", "dataMaskingPolicies", "dataMaskingPolicies"), + resourceids.StaticSegment("dataMaskingPolicyName", "default", "default"), + resourceids.StaticSegment("staticRules", "rules", "rules"), + resourceids.UserSpecifiedSegment("ruleName", "ruleValue"), + } +} + +// String returns a human-readable description of this Rule ID +func (id RuleId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Workspace Name: %q", id.WorkspaceName), + fmt.Sprintf("Sql Pool Name: %q", id.SqlPoolName), + fmt.Sprintf("Rule Name: %q", id.RuleName), + } + return fmt.Sprintf("Rule (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolsdatamaskingrules/id_rule_test.go b/resource-manager/synapse/2021-06-01/sqlpoolsdatamaskingrules/id_rule_test.go new file mode 100644 index 00000000000..c9f7f4cb3c4 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolsdatamaskingrules/id_rule_test.go @@ -0,0 +1,402 @@ +package sqlpoolsdatamaskingrules + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &RuleId{} + +func TestNewRuleID(t *testing.T) { + id := NewRuleID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "sqlPoolValue", "ruleValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.WorkspaceName != "workspaceValue" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceName'", id.WorkspaceName, "workspaceValue") + } + + if id.SqlPoolName != "sqlPoolValue" { + t.Fatalf("Expected %q but got %q for Segment 'SqlPoolName'", id.SqlPoolName, "sqlPoolValue") + } + + if id.RuleName != "ruleValue" { + t.Fatalf("Expected %q but got %q for Segment 'RuleName'", id.RuleName, "ruleValue") + } +} + +func TestFormatRuleID(t *testing.T) { + actual := NewRuleID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "sqlPoolValue", "ruleValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/dataMaskingPolicies/default/rules/ruleValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseRuleID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *RuleId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/dataMaskingPolicies", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/dataMaskingPolicies/default", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/dataMaskingPolicies/default/rules", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/dataMaskingPolicies/default/rules/ruleValue", + Expected: &RuleId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + SqlPoolName: "sqlPoolValue", + RuleName: "ruleValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/dataMaskingPolicies/default/rules/ruleValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseRuleID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + if actual.SqlPoolName != v.Expected.SqlPoolName { + t.Fatalf("Expected %q but got %q for SqlPoolName", v.Expected.SqlPoolName, actual.SqlPoolName) + } + + if actual.RuleName != v.Expected.RuleName { + t.Fatalf("Expected %q but got %q for RuleName", v.Expected.RuleName, actual.RuleName) + } + + } +} + +func TestParseRuleIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *RuleId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/sQlPoOlS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/sQlPoOlS/sQlPoOlVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/dataMaskingPolicies", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/sQlPoOlS/sQlPoOlVaLuE/dAtAmAsKiNgPoLiCiEs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/dataMaskingPolicies/default", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/sQlPoOlS/sQlPoOlVaLuE/dAtAmAsKiNgPoLiCiEs/dEfAuLt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/dataMaskingPolicies/default/rules", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/sQlPoOlS/sQlPoOlVaLuE/dAtAmAsKiNgPoLiCiEs/dEfAuLt/rUlEs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/dataMaskingPolicies/default/rules/ruleValue", + Expected: &RuleId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + SqlPoolName: "sqlPoolValue", + RuleName: "ruleValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/dataMaskingPolicies/default/rules/ruleValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/sQlPoOlS/sQlPoOlVaLuE/dAtAmAsKiNgPoLiCiEs/dEfAuLt/rUlEs/rUlEvAlUe", + Expected: &RuleId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + WorkspaceName: "wOrKsPaCeVaLuE", + SqlPoolName: "sQlPoOlVaLuE", + RuleName: "rUlEvAlUe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/sQlPoOlS/sQlPoOlVaLuE/dAtAmAsKiNgPoLiCiEs/dEfAuLt/rUlEs/rUlEvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseRuleIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + if actual.SqlPoolName != v.Expected.SqlPoolName { + t.Fatalf("Expected %q but got %q for SqlPoolName", v.Expected.SqlPoolName, actual.SqlPoolName) + } + + if actual.RuleName != v.Expected.RuleName { + t.Fatalf("Expected %q but got %q for RuleName", v.Expected.RuleName, actual.RuleName) + } + + } +} + +func TestSegmentsForRuleId(t *testing.T) { + segments := RuleId{}.Segments() + if len(segments) == 0 { + t.Fatalf("RuleId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolsdatamaskingrules/id_sqlpool.go b/resource-manager/synapse/2021-06-01/sqlpoolsdatamaskingrules/id_sqlpool.go new file mode 100644 index 00000000000..d3feceac0ec --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolsdatamaskingrules/id_sqlpool.go @@ -0,0 +1,134 @@ +package sqlpoolsdatamaskingrules + +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 = &SqlPoolId{} + +// SqlPoolId is a struct representing the Resource ID for a Sql Pool +type SqlPoolId struct { + SubscriptionId string + ResourceGroupName string + WorkspaceName string + SqlPoolName string +} + +// NewSqlPoolID returns a new SqlPoolId struct +func NewSqlPoolID(subscriptionId string, resourceGroupName string, workspaceName string, sqlPoolName string) SqlPoolId { + return SqlPoolId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + WorkspaceName: workspaceName, + SqlPoolName: sqlPoolName, + } +} + +// ParseSqlPoolID parses 'input' into a SqlPoolId +func ParseSqlPoolID(input string) (*SqlPoolId, error) { + parser := resourceids.NewParserFromResourceIdType(&SqlPoolId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := SqlPoolId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseSqlPoolIDInsensitively parses 'input' case-insensitively into a SqlPoolId +// note: this method should only be used for API response data and not user input +func ParseSqlPoolIDInsensitively(input string) (*SqlPoolId, error) { + parser := resourceids.NewParserFromResourceIdType(&SqlPoolId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := SqlPoolId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *SqlPoolId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.WorkspaceName, ok = input.Parsed["workspaceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "workspaceName", input) + } + + if id.SqlPoolName, ok = input.Parsed["sqlPoolName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "sqlPoolName", input) + } + + return nil +} + +// ValidateSqlPoolID checks that 'input' can be parsed as a Sql Pool ID +func ValidateSqlPoolID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseSqlPoolID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Sql Pool ID +func (id SqlPoolId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Synapse/workspaces/%s/sqlPools/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.WorkspaceName, id.SqlPoolName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Sql Pool ID +func (id SqlPoolId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftSynapse", "Microsoft.Synapse", "Microsoft.Synapse"), + resourceids.StaticSegment("staticWorkspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceName", "workspaceValue"), + resourceids.StaticSegment("staticSqlPools", "sqlPools", "sqlPools"), + resourceids.UserSpecifiedSegment("sqlPoolName", "sqlPoolValue"), + } +} + +// String returns a human-readable description of this Sql Pool ID +func (id SqlPoolId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Workspace Name: %q", id.WorkspaceName), + fmt.Sprintf("Sql Pool Name: %q", id.SqlPoolName), + } + return fmt.Sprintf("Sql Pool (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolsdatamaskingrules/id_sqlpool_test.go b/resource-manager/synapse/2021-06-01/sqlpoolsdatamaskingrules/id_sqlpool_test.go new file mode 100644 index 00000000000..0dca4b10342 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolsdatamaskingrules/id_sqlpool_test.go @@ -0,0 +1,327 @@ +package sqlpoolsdatamaskingrules + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &SqlPoolId{} + +func TestNewSqlPoolID(t *testing.T) { + id := NewSqlPoolID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "sqlPoolValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.WorkspaceName != "workspaceValue" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceName'", id.WorkspaceName, "workspaceValue") + } + + if id.SqlPoolName != "sqlPoolValue" { + t.Fatalf("Expected %q but got %q for Segment 'SqlPoolName'", id.SqlPoolName, "sqlPoolValue") + } +} + +func TestFormatSqlPoolID(t *testing.T) { + actual := NewSqlPoolID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "sqlPoolValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseSqlPoolID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *SqlPoolId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue", + Expected: &SqlPoolId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + SqlPoolName: "sqlPoolValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseSqlPoolID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + if actual.SqlPoolName != v.Expected.SqlPoolName { + t.Fatalf("Expected %q but got %q for SqlPoolName", v.Expected.SqlPoolName, actual.SqlPoolName) + } + + } +} + +func TestParseSqlPoolIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *SqlPoolId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/sQlPoOlS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue", + Expected: &SqlPoolId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + SqlPoolName: "sqlPoolValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/sQlPoOlS/sQlPoOlVaLuE", + Expected: &SqlPoolId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + WorkspaceName: "wOrKsPaCeVaLuE", + SqlPoolName: "sQlPoOlVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/sQlPoOlS/sQlPoOlVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseSqlPoolIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + if actual.SqlPoolName != v.Expected.SqlPoolName { + t.Fatalf("Expected %q but got %q for SqlPoolName", v.Expected.SqlPoolName, actual.SqlPoolName) + } + + } +} + +func TestSegmentsForSqlPoolId(t *testing.T) { + segments := SqlPoolId{}.Segments() + if len(segments) == 0 { + t.Fatalf("SqlPoolId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolsdatamaskingrules/method_datamaskingrulescreateorupdate.go b/resource-manager/synapse/2021-06-01/sqlpoolsdatamaskingrules/method_datamaskingrulescreateorupdate.go new file mode 100644 index 00000000000..ffa26105e64 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolsdatamaskingrules/method_datamaskingrulescreateorupdate.go @@ -0,0 +1,56 @@ +package sqlpoolsdatamaskingrules + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DataMaskingRulesCreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *DataMaskingRule +} + +// DataMaskingRulesCreateOrUpdate ... +func (c SqlPoolsDataMaskingRulesClient) DataMaskingRulesCreateOrUpdate(ctx context.Context, id RuleId, input DataMaskingRule) (result DataMaskingRulesCreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolsdatamaskingrules/method_datamaskingrulesget.go b/resource-manager/synapse/2021-06-01/sqlpoolsdatamaskingrules/method_datamaskingrulesget.go new file mode 100644 index 00000000000..cdda5270da3 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolsdatamaskingrules/method_datamaskingrulesget.go @@ -0,0 +1,51 @@ +package sqlpoolsdatamaskingrules + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DataMaskingRulesGetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *DataMaskingRule +} + +// DataMaskingRulesGet ... +func (c SqlPoolsDataMaskingRulesClient) DataMaskingRulesGet(ctx context.Context, id RuleId) (result DataMaskingRulesGetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolsdatamaskingrules/method_datamaskingruleslistbysqlpool.go b/resource-manager/synapse/2021-06-01/sqlpoolsdatamaskingrules/method_datamaskingruleslistbysqlpool.go new file mode 100644 index 00000000000..d86cb6c8c4a --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolsdatamaskingrules/method_datamaskingruleslistbysqlpool.go @@ -0,0 +1,52 @@ +package sqlpoolsdatamaskingrules + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DataMaskingRulesListBySqlPoolOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *DataMaskingRuleListResult +} + +// DataMaskingRulesListBySqlPool ... +func (c SqlPoolsDataMaskingRulesClient) DataMaskingRulesListBySqlPool(ctx context.Context, id SqlPoolId) (result DataMaskingRulesListBySqlPoolOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/dataMaskingPolicies/default/rules", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolsdatamaskingrules/model_datamaskingrule.go b/resource-manager/synapse/2021-06-01/sqlpoolsdatamaskingrules/model_datamaskingrule.go new file mode 100644 index 00000000000..f0423d3f0cb --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolsdatamaskingrules/model_datamaskingrule.go @@ -0,0 +1,13 @@ +package sqlpoolsdatamaskingrules + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DataMaskingRule struct { + Id *string `json:"id,omitempty"` + Kind *string `json:"kind,omitempty"` + Location *string `json:"location,omitempty"` + Name *string `json:"name,omitempty"` + Properties *DataMaskingRuleProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolsdatamaskingrules/model_datamaskingrulelistresult.go b/resource-manager/synapse/2021-06-01/sqlpoolsdatamaskingrules/model_datamaskingrulelistresult.go new file mode 100644 index 00000000000..7f55fd8a491 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolsdatamaskingrules/model_datamaskingrulelistresult.go @@ -0,0 +1,8 @@ +package sqlpoolsdatamaskingrules + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DataMaskingRuleListResult struct { + Value *[]DataMaskingRule `json:"value,omitempty"` +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolsdatamaskingrules/model_datamaskingruleproperties.go b/resource-manager/synapse/2021-06-01/sqlpoolsdatamaskingrules/model_datamaskingruleproperties.go new file mode 100644 index 00000000000..c82a444b915 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolsdatamaskingrules/model_datamaskingruleproperties.go @@ -0,0 +1,19 @@ +package sqlpoolsdatamaskingrules + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DataMaskingRuleProperties struct { + AliasName *string `json:"aliasName,omitempty"` + ColumnName string `json:"columnName"` + Id *string `json:"id,omitempty"` + MaskingFunction DataMaskingFunction `json:"maskingFunction"` + NumberFrom *string `json:"numberFrom,omitempty"` + NumberTo *string `json:"numberTo,omitempty"` + PrefixSize *string `json:"prefixSize,omitempty"` + ReplacementString *string `json:"replacementString,omitempty"` + RuleState *DataMaskingRuleState `json:"ruleState,omitempty"` + SchemaName string `json:"schemaName"` + SuffixSize *string `json:"suffixSize,omitempty"` + TableName string `json:"tableName"` +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolsdatamaskingrules/version.go b/resource-manager/synapse/2021-06-01/sqlpoolsdatamaskingrules/version.go new file mode 100644 index 00000000000..01b10aa93c9 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolsdatamaskingrules/version.go @@ -0,0 +1,12 @@ +package sqlpoolsdatamaskingrules + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2021-06-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/sqlpoolsdatamaskingrules/%s", defaultApiVersion) +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolsgeobackuppolicies/README.md b/resource-manager/synapse/2021-06-01/sqlpoolsgeobackuppolicies/README.md new file mode 100644 index 00000000000..18b597ad891 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolsgeobackuppolicies/README.md @@ -0,0 +1,73 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/synapse/2021-06-01/sqlpoolsgeobackuppolicies` Documentation + +The `sqlpoolsgeobackuppolicies` SDK allows for interaction with the Azure Resource Manager Service `synapse` (API Version `2021-06-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/synapse/2021-06-01/sqlpoolsgeobackuppolicies" +``` + + +### Client Initialization + +```go +client := sqlpoolsgeobackuppolicies.NewSqlPoolsGeoBackupPoliciesClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `SqlPoolsGeoBackupPoliciesClient.SqlPoolGeoBackupPoliciesCreateOrUpdate` + +```go +ctx := context.TODO() +id := sqlpoolsgeobackuppolicies.NewSqlPoolID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "sqlPoolValue") + +payload := sqlpoolsgeobackuppolicies.GeoBackupPolicy{ + // ... +} + + +read, err := client.SqlPoolGeoBackupPoliciesCreateOrUpdate(ctx, id, payload) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `SqlPoolsGeoBackupPoliciesClient.SqlPoolGeoBackupPoliciesGet` + +```go +ctx := context.TODO() +id := sqlpoolsgeobackuppolicies.NewSqlPoolID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "sqlPoolValue") + +read, err := client.SqlPoolGeoBackupPoliciesGet(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `SqlPoolsGeoBackupPoliciesClient.SqlPoolGeoBackupPoliciesList` + +```go +ctx := context.TODO() +id := sqlpoolsgeobackuppolicies.NewSqlPoolID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "sqlPoolValue") + +read, err := client.SqlPoolGeoBackupPoliciesList(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` diff --git a/resource-manager/synapse/2021-06-01/sqlpoolsgeobackuppolicies/client.go b/resource-manager/synapse/2021-06-01/sqlpoolsgeobackuppolicies/client.go new file mode 100644 index 00000000000..498ccf26bfe --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolsgeobackuppolicies/client.go @@ -0,0 +1,26 @@ +package sqlpoolsgeobackuppolicies + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SqlPoolsGeoBackupPoliciesClient struct { + Client *resourcemanager.Client +} + +func NewSqlPoolsGeoBackupPoliciesClientWithBaseURI(sdkApi sdkEnv.Api) (*SqlPoolsGeoBackupPoliciesClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "sqlpoolsgeobackuppolicies", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating SqlPoolsGeoBackupPoliciesClient: %+v", err) + } + + return &SqlPoolsGeoBackupPoliciesClient{ + Client: client, + }, nil +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolsgeobackuppolicies/constants.go b/resource-manager/synapse/2021-06-01/sqlpoolsgeobackuppolicies/constants.go new file mode 100644 index 00000000000..0198caa5cb3 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolsgeobackuppolicies/constants.go @@ -0,0 +1,51 @@ +package sqlpoolsgeobackuppolicies + +import ( + "encoding/json" + "fmt" + "strings" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GeoBackupPolicyState string + +const ( + GeoBackupPolicyStateDisabled GeoBackupPolicyState = "Disabled" + GeoBackupPolicyStateEnabled GeoBackupPolicyState = "Enabled" +) + +func PossibleValuesForGeoBackupPolicyState() []string { + return []string{ + string(GeoBackupPolicyStateDisabled), + string(GeoBackupPolicyStateEnabled), + } +} + +func (s *GeoBackupPolicyState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseGeoBackupPolicyState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseGeoBackupPolicyState(input string) (*GeoBackupPolicyState, error) { + vals := map[string]GeoBackupPolicyState{ + "disabled": GeoBackupPolicyStateDisabled, + "enabled": GeoBackupPolicyStateEnabled, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := GeoBackupPolicyState(input) + return &out, nil +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolsgeobackuppolicies/id_sqlpool.go b/resource-manager/synapse/2021-06-01/sqlpoolsgeobackuppolicies/id_sqlpool.go new file mode 100644 index 00000000000..436a4e0c545 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolsgeobackuppolicies/id_sqlpool.go @@ -0,0 +1,134 @@ +package sqlpoolsgeobackuppolicies + +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 = &SqlPoolId{} + +// SqlPoolId is a struct representing the Resource ID for a Sql Pool +type SqlPoolId struct { + SubscriptionId string + ResourceGroupName string + WorkspaceName string + SqlPoolName string +} + +// NewSqlPoolID returns a new SqlPoolId struct +func NewSqlPoolID(subscriptionId string, resourceGroupName string, workspaceName string, sqlPoolName string) SqlPoolId { + return SqlPoolId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + WorkspaceName: workspaceName, + SqlPoolName: sqlPoolName, + } +} + +// ParseSqlPoolID parses 'input' into a SqlPoolId +func ParseSqlPoolID(input string) (*SqlPoolId, error) { + parser := resourceids.NewParserFromResourceIdType(&SqlPoolId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := SqlPoolId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseSqlPoolIDInsensitively parses 'input' case-insensitively into a SqlPoolId +// note: this method should only be used for API response data and not user input +func ParseSqlPoolIDInsensitively(input string) (*SqlPoolId, error) { + parser := resourceids.NewParserFromResourceIdType(&SqlPoolId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := SqlPoolId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *SqlPoolId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.WorkspaceName, ok = input.Parsed["workspaceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "workspaceName", input) + } + + if id.SqlPoolName, ok = input.Parsed["sqlPoolName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "sqlPoolName", input) + } + + return nil +} + +// ValidateSqlPoolID checks that 'input' can be parsed as a Sql Pool ID +func ValidateSqlPoolID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseSqlPoolID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Sql Pool ID +func (id SqlPoolId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Synapse/workspaces/%s/sqlPools/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.WorkspaceName, id.SqlPoolName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Sql Pool ID +func (id SqlPoolId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftSynapse", "Microsoft.Synapse", "Microsoft.Synapse"), + resourceids.StaticSegment("staticWorkspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceName", "workspaceValue"), + resourceids.StaticSegment("staticSqlPools", "sqlPools", "sqlPools"), + resourceids.UserSpecifiedSegment("sqlPoolName", "sqlPoolValue"), + } +} + +// String returns a human-readable description of this Sql Pool ID +func (id SqlPoolId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Workspace Name: %q", id.WorkspaceName), + fmt.Sprintf("Sql Pool Name: %q", id.SqlPoolName), + } + return fmt.Sprintf("Sql Pool (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolsgeobackuppolicies/id_sqlpool_test.go b/resource-manager/synapse/2021-06-01/sqlpoolsgeobackuppolicies/id_sqlpool_test.go new file mode 100644 index 00000000000..980e3d9a8da --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolsgeobackuppolicies/id_sqlpool_test.go @@ -0,0 +1,327 @@ +package sqlpoolsgeobackuppolicies + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &SqlPoolId{} + +func TestNewSqlPoolID(t *testing.T) { + id := NewSqlPoolID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "sqlPoolValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.WorkspaceName != "workspaceValue" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceName'", id.WorkspaceName, "workspaceValue") + } + + if id.SqlPoolName != "sqlPoolValue" { + t.Fatalf("Expected %q but got %q for Segment 'SqlPoolName'", id.SqlPoolName, "sqlPoolValue") + } +} + +func TestFormatSqlPoolID(t *testing.T) { + actual := NewSqlPoolID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "sqlPoolValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseSqlPoolID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *SqlPoolId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue", + Expected: &SqlPoolId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + SqlPoolName: "sqlPoolValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseSqlPoolID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + if actual.SqlPoolName != v.Expected.SqlPoolName { + t.Fatalf("Expected %q but got %q for SqlPoolName", v.Expected.SqlPoolName, actual.SqlPoolName) + } + + } +} + +func TestParseSqlPoolIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *SqlPoolId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/sQlPoOlS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue", + Expected: &SqlPoolId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + SqlPoolName: "sqlPoolValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/sQlPoOlS/sQlPoOlVaLuE", + Expected: &SqlPoolId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + WorkspaceName: "wOrKsPaCeVaLuE", + SqlPoolName: "sQlPoOlVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/sQlPoOlS/sQlPoOlVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseSqlPoolIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + if actual.SqlPoolName != v.Expected.SqlPoolName { + t.Fatalf("Expected %q but got %q for SqlPoolName", v.Expected.SqlPoolName, actual.SqlPoolName) + } + + } +} + +func TestSegmentsForSqlPoolId(t *testing.T) { + segments := SqlPoolId{}.Segments() + if len(segments) == 0 { + t.Fatalf("SqlPoolId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolsgeobackuppolicies/method_sqlpoolgeobackuppoliciescreateorupdate.go b/resource-manager/synapse/2021-06-01/sqlpoolsgeobackuppolicies/method_sqlpoolgeobackuppoliciescreateorupdate.go new file mode 100644 index 00000000000..5088aa41565 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolsgeobackuppolicies/method_sqlpoolgeobackuppoliciescreateorupdate.go @@ -0,0 +1,57 @@ +package sqlpoolsgeobackuppolicies + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SqlPoolGeoBackupPoliciesCreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *GeoBackupPolicy +} + +// SqlPoolGeoBackupPoliciesCreateOrUpdate ... +func (c SqlPoolsGeoBackupPoliciesClient) SqlPoolGeoBackupPoliciesCreateOrUpdate(ctx context.Context, id SqlPoolId, input GeoBackupPolicy) (result SqlPoolGeoBackupPoliciesCreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: fmt.Sprintf("%s/geoBackupPolicies/default", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolsgeobackuppolicies/method_sqlpoolgeobackuppoliciesget.go b/resource-manager/synapse/2021-06-01/sqlpoolsgeobackuppolicies/method_sqlpoolgeobackuppoliciesget.go new file mode 100644 index 00000000000..760db85f5ab --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolsgeobackuppolicies/method_sqlpoolgeobackuppoliciesget.go @@ -0,0 +1,52 @@ +package sqlpoolsgeobackuppolicies + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SqlPoolGeoBackupPoliciesGetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *GeoBackupPolicy +} + +// SqlPoolGeoBackupPoliciesGet ... +func (c SqlPoolsGeoBackupPoliciesClient) SqlPoolGeoBackupPoliciesGet(ctx context.Context, id SqlPoolId) (result SqlPoolGeoBackupPoliciesGetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/geoBackupPolicies/default", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolsgeobackuppolicies/method_sqlpoolgeobackuppolicieslist.go b/resource-manager/synapse/2021-06-01/sqlpoolsgeobackuppolicies/method_sqlpoolgeobackuppolicieslist.go new file mode 100644 index 00000000000..0882af3fa68 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolsgeobackuppolicies/method_sqlpoolgeobackuppolicieslist.go @@ -0,0 +1,52 @@ +package sqlpoolsgeobackuppolicies + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SqlPoolGeoBackupPoliciesListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *GeoBackupPolicyListResult +} + +// SqlPoolGeoBackupPoliciesList ... +func (c SqlPoolsGeoBackupPoliciesClient) SqlPoolGeoBackupPoliciesList(ctx context.Context, id SqlPoolId) (result SqlPoolGeoBackupPoliciesListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/geoBackupPolicies", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolsgeobackuppolicies/model_geobackuppolicy.go b/resource-manager/synapse/2021-06-01/sqlpoolsgeobackuppolicies/model_geobackuppolicy.go new file mode 100644 index 00000000000..e7bac132802 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolsgeobackuppolicies/model_geobackuppolicy.go @@ -0,0 +1,13 @@ +package sqlpoolsgeobackuppolicies + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GeoBackupPolicy struct { + Id *string `json:"id,omitempty"` + Kind *string `json:"kind,omitempty"` + Location *string `json:"location,omitempty"` + Name *string `json:"name,omitempty"` + Properties GeoBackupPolicyProperties `json:"properties"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolsgeobackuppolicies/model_geobackuppolicylistresult.go b/resource-manager/synapse/2021-06-01/sqlpoolsgeobackuppolicies/model_geobackuppolicylistresult.go new file mode 100644 index 00000000000..ce6fb096b38 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolsgeobackuppolicies/model_geobackuppolicylistresult.go @@ -0,0 +1,8 @@ +package sqlpoolsgeobackuppolicies + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GeoBackupPolicyListResult struct { + Value *[]GeoBackupPolicy `json:"value,omitempty"` +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolsgeobackuppolicies/model_geobackuppolicyproperties.go b/resource-manager/synapse/2021-06-01/sqlpoolsgeobackuppolicies/model_geobackuppolicyproperties.go new file mode 100644 index 00000000000..f8aa45e1152 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolsgeobackuppolicies/model_geobackuppolicyproperties.go @@ -0,0 +1,9 @@ +package sqlpoolsgeobackuppolicies + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GeoBackupPolicyProperties struct { + State GeoBackupPolicyState `json:"state"` + StorageType *string `json:"storageType,omitempty"` +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolsgeobackuppolicies/version.go b/resource-manager/synapse/2021-06-01/sqlpoolsgeobackuppolicies/version.go new file mode 100644 index 00000000000..47e970ce16a --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolsgeobackuppolicies/version.go @@ -0,0 +1,12 @@ +package sqlpoolsgeobackuppolicies + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2021-06-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/sqlpoolsgeobackuppolicies/%s", defaultApiVersion) +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolsmaintenancewindowoptions/README.md b/resource-manager/synapse/2021-06-01/sqlpoolsmaintenancewindowoptions/README.md new file mode 100644 index 00000000000..00f69a7fb01 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolsmaintenancewindowoptions/README.md @@ -0,0 +1,36 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/synapse/2021-06-01/sqlpoolsmaintenancewindowoptions` Documentation + +The `sqlpoolsmaintenancewindowoptions` SDK allows for interaction with the Azure Resource Manager Service `synapse` (API Version `2021-06-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/synapse/2021-06-01/sqlpoolsmaintenancewindowoptions" +``` + + +### Client Initialization + +```go +client := sqlpoolsmaintenancewindowoptions.NewSqlPoolsMaintenanceWindowOptionsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `SqlPoolsMaintenanceWindowOptionsClient.SqlPoolMaintenanceWindowOptionsGet` + +```go +ctx := context.TODO() +id := sqlpoolsmaintenancewindowoptions.NewSqlPoolID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "sqlPoolValue") + +read, err := client.SqlPoolMaintenanceWindowOptionsGet(ctx, id, sqlpoolsmaintenancewindowoptions.DefaultSqlPoolMaintenanceWindowOptionsGetOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` diff --git a/resource-manager/synapse/2021-06-01/sqlpoolsmaintenancewindowoptions/client.go b/resource-manager/synapse/2021-06-01/sqlpoolsmaintenancewindowoptions/client.go new file mode 100644 index 00000000000..7fe7f7f7bf5 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolsmaintenancewindowoptions/client.go @@ -0,0 +1,26 @@ +package sqlpoolsmaintenancewindowoptions + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SqlPoolsMaintenanceWindowOptionsClient struct { + Client *resourcemanager.Client +} + +func NewSqlPoolsMaintenanceWindowOptionsClientWithBaseURI(sdkApi sdkEnv.Api) (*SqlPoolsMaintenanceWindowOptionsClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "sqlpoolsmaintenancewindowoptions", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating SqlPoolsMaintenanceWindowOptionsClient: %+v", err) + } + + return &SqlPoolsMaintenanceWindowOptionsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolsmaintenancewindowoptions/constants.go b/resource-manager/synapse/2021-06-01/sqlpoolsmaintenancewindowoptions/constants.go new file mode 100644 index 00000000000..0e2f866ece3 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolsmaintenancewindowoptions/constants.go @@ -0,0 +1,66 @@ +package sqlpoolsmaintenancewindowoptions + +import ( + "encoding/json" + "fmt" + "strings" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DayOfWeek string + +const ( + DayOfWeekFriday DayOfWeek = "Friday" + DayOfWeekMonday DayOfWeek = "Monday" + DayOfWeekSaturday DayOfWeek = "Saturday" + DayOfWeekSunday DayOfWeek = "Sunday" + DayOfWeekThursday DayOfWeek = "Thursday" + DayOfWeekTuesday DayOfWeek = "Tuesday" + DayOfWeekWednesday DayOfWeek = "Wednesday" +) + +func PossibleValuesForDayOfWeek() []string { + return []string{ + string(DayOfWeekFriday), + string(DayOfWeekMonday), + string(DayOfWeekSaturday), + string(DayOfWeekSunday), + string(DayOfWeekThursday), + string(DayOfWeekTuesday), + string(DayOfWeekWednesday), + } +} + +func (s *DayOfWeek) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseDayOfWeek(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseDayOfWeek(input string) (*DayOfWeek, error) { + vals := map[string]DayOfWeek{ + "friday": DayOfWeekFriday, + "monday": DayOfWeekMonday, + "saturday": DayOfWeekSaturday, + "sunday": DayOfWeekSunday, + "thursday": DayOfWeekThursday, + "tuesday": DayOfWeekTuesday, + "wednesday": DayOfWeekWednesday, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := DayOfWeek(input) + return &out, nil +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolsmaintenancewindowoptions/id_sqlpool.go b/resource-manager/synapse/2021-06-01/sqlpoolsmaintenancewindowoptions/id_sqlpool.go new file mode 100644 index 00000000000..b541b4c3306 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolsmaintenancewindowoptions/id_sqlpool.go @@ -0,0 +1,134 @@ +package sqlpoolsmaintenancewindowoptions + +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 = &SqlPoolId{} + +// SqlPoolId is a struct representing the Resource ID for a Sql Pool +type SqlPoolId struct { + SubscriptionId string + ResourceGroupName string + WorkspaceName string + SqlPoolName string +} + +// NewSqlPoolID returns a new SqlPoolId struct +func NewSqlPoolID(subscriptionId string, resourceGroupName string, workspaceName string, sqlPoolName string) SqlPoolId { + return SqlPoolId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + WorkspaceName: workspaceName, + SqlPoolName: sqlPoolName, + } +} + +// ParseSqlPoolID parses 'input' into a SqlPoolId +func ParseSqlPoolID(input string) (*SqlPoolId, error) { + parser := resourceids.NewParserFromResourceIdType(&SqlPoolId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := SqlPoolId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseSqlPoolIDInsensitively parses 'input' case-insensitively into a SqlPoolId +// note: this method should only be used for API response data and not user input +func ParseSqlPoolIDInsensitively(input string) (*SqlPoolId, error) { + parser := resourceids.NewParserFromResourceIdType(&SqlPoolId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := SqlPoolId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *SqlPoolId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.WorkspaceName, ok = input.Parsed["workspaceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "workspaceName", input) + } + + if id.SqlPoolName, ok = input.Parsed["sqlPoolName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "sqlPoolName", input) + } + + return nil +} + +// ValidateSqlPoolID checks that 'input' can be parsed as a Sql Pool ID +func ValidateSqlPoolID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseSqlPoolID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Sql Pool ID +func (id SqlPoolId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Synapse/workspaces/%s/sqlPools/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.WorkspaceName, id.SqlPoolName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Sql Pool ID +func (id SqlPoolId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftSynapse", "Microsoft.Synapse", "Microsoft.Synapse"), + resourceids.StaticSegment("staticWorkspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceName", "workspaceValue"), + resourceids.StaticSegment("staticSqlPools", "sqlPools", "sqlPools"), + resourceids.UserSpecifiedSegment("sqlPoolName", "sqlPoolValue"), + } +} + +// String returns a human-readable description of this Sql Pool ID +func (id SqlPoolId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Workspace Name: %q", id.WorkspaceName), + fmt.Sprintf("Sql Pool Name: %q", id.SqlPoolName), + } + return fmt.Sprintf("Sql Pool (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolsmaintenancewindowoptions/id_sqlpool_test.go b/resource-manager/synapse/2021-06-01/sqlpoolsmaintenancewindowoptions/id_sqlpool_test.go new file mode 100644 index 00000000000..7c01da55155 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolsmaintenancewindowoptions/id_sqlpool_test.go @@ -0,0 +1,327 @@ +package sqlpoolsmaintenancewindowoptions + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &SqlPoolId{} + +func TestNewSqlPoolID(t *testing.T) { + id := NewSqlPoolID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "sqlPoolValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.WorkspaceName != "workspaceValue" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceName'", id.WorkspaceName, "workspaceValue") + } + + if id.SqlPoolName != "sqlPoolValue" { + t.Fatalf("Expected %q but got %q for Segment 'SqlPoolName'", id.SqlPoolName, "sqlPoolValue") + } +} + +func TestFormatSqlPoolID(t *testing.T) { + actual := NewSqlPoolID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "sqlPoolValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseSqlPoolID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *SqlPoolId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue", + Expected: &SqlPoolId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + SqlPoolName: "sqlPoolValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseSqlPoolID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + if actual.SqlPoolName != v.Expected.SqlPoolName { + t.Fatalf("Expected %q but got %q for SqlPoolName", v.Expected.SqlPoolName, actual.SqlPoolName) + } + + } +} + +func TestParseSqlPoolIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *SqlPoolId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/sQlPoOlS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue", + Expected: &SqlPoolId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + SqlPoolName: "sqlPoolValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/sQlPoOlS/sQlPoOlVaLuE", + Expected: &SqlPoolId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + WorkspaceName: "wOrKsPaCeVaLuE", + SqlPoolName: "sQlPoOlVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/sQlPoOlS/sQlPoOlVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseSqlPoolIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + if actual.SqlPoolName != v.Expected.SqlPoolName { + t.Fatalf("Expected %q but got %q for SqlPoolName", v.Expected.SqlPoolName, actual.SqlPoolName) + } + + } +} + +func TestSegmentsForSqlPoolId(t *testing.T) { + segments := SqlPoolId{}.Segments() + if len(segments) == 0 { + t.Fatalf("SqlPoolId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolsmaintenancewindowoptions/method_sqlpoolmaintenancewindowoptionsget.go b/resource-manager/synapse/2021-06-01/sqlpoolsmaintenancewindowoptions/method_sqlpoolmaintenancewindowoptionsget.go new file mode 100644 index 00000000000..cc9f6b74586 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolsmaintenancewindowoptions/method_sqlpoolmaintenancewindowoptionsget.go @@ -0,0 +1,80 @@ +package sqlpoolsmaintenancewindowoptions + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SqlPoolMaintenanceWindowOptionsGetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *MaintenanceWindowOptions +} + +type SqlPoolMaintenanceWindowOptionsGetOperationOptions struct { + MaintenanceWindowOptionsName *string +} + +func DefaultSqlPoolMaintenanceWindowOptionsGetOperationOptions() SqlPoolMaintenanceWindowOptionsGetOperationOptions { + return SqlPoolMaintenanceWindowOptionsGetOperationOptions{} +} + +func (o SqlPoolMaintenanceWindowOptionsGetOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o SqlPoolMaintenanceWindowOptionsGetOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o SqlPoolMaintenanceWindowOptionsGetOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.MaintenanceWindowOptionsName != nil { + out.Append("maintenanceWindowOptionsName", fmt.Sprintf("%v", *o.MaintenanceWindowOptionsName)) + } + return &out +} + +// SqlPoolMaintenanceWindowOptionsGet ... +func (c SqlPoolsMaintenanceWindowOptionsClient) SqlPoolMaintenanceWindowOptionsGet(ctx context.Context, id SqlPoolId, options SqlPoolMaintenanceWindowOptionsGetOperationOptions) (result SqlPoolMaintenanceWindowOptionsGetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/maintenanceWindowOptions/current", id.ID()), + OptionsObject: options, + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolsmaintenancewindowoptions/model_maintenancewindowoptions.go b/resource-manager/synapse/2021-06-01/sqlpoolsmaintenancewindowoptions/model_maintenancewindowoptions.go new file mode 100644 index 00000000000..d4d0b635be4 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolsmaintenancewindowoptions/model_maintenancewindowoptions.go @@ -0,0 +1,11 @@ +package sqlpoolsmaintenancewindowoptions + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MaintenanceWindowOptions struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *MaintenanceWindowOptionsProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolsmaintenancewindowoptions/model_maintenancewindowoptionsproperties.go b/resource-manager/synapse/2021-06-01/sqlpoolsmaintenancewindowoptions/model_maintenancewindowoptionsproperties.go new file mode 100644 index 00000000000..cff63cc66ed --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolsmaintenancewindowoptions/model_maintenancewindowoptionsproperties.go @@ -0,0 +1,14 @@ +package sqlpoolsmaintenancewindowoptions + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MaintenanceWindowOptionsProperties struct { + AllowMultipleMaintenanceWindowsPerCycle *bool `json:"allowMultipleMaintenanceWindowsPerCycle,omitempty"` + DefaultDurationInMinutes *int64 `json:"defaultDurationInMinutes,omitempty"` + IsEnabled *bool `json:"isEnabled,omitempty"` + MaintenanceWindowCycles *[]MaintenanceWindowTimeRange `json:"maintenanceWindowCycles,omitempty"` + MinCycles *int64 `json:"minCycles,omitempty"` + MinDurationInMinutes *int64 `json:"minDurationInMinutes,omitempty"` + TimeGranularityInMinutes *int64 `json:"timeGranularityInMinutes,omitempty"` +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolsmaintenancewindowoptions/model_maintenancewindowtimerange.go b/resource-manager/synapse/2021-06-01/sqlpoolsmaintenancewindowoptions/model_maintenancewindowtimerange.go new file mode 100644 index 00000000000..02b8afdcd5d --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolsmaintenancewindowoptions/model_maintenancewindowtimerange.go @@ -0,0 +1,10 @@ +package sqlpoolsmaintenancewindowoptions + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MaintenanceWindowTimeRange struct { + DayOfWeek *DayOfWeek `json:"dayOfWeek,omitempty"` + Duration *string `json:"duration,omitempty"` + StartTime *string `json:"startTime,omitempty"` +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolsmaintenancewindowoptions/version.go b/resource-manager/synapse/2021-06-01/sqlpoolsmaintenancewindowoptions/version.go new file mode 100644 index 00000000000..d55ebbc4e76 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolsmaintenancewindowoptions/version.go @@ -0,0 +1,12 @@ +package sqlpoolsmaintenancewindowoptions + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2021-06-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/sqlpoolsmaintenancewindowoptions/%s", defaultApiVersion) +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolsmaintenancewindows/README.md b/resource-manager/synapse/2021-06-01/sqlpoolsmaintenancewindows/README.md new file mode 100644 index 00000000000..024bf8448ec --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolsmaintenancewindows/README.md @@ -0,0 +1,57 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/synapse/2021-06-01/sqlpoolsmaintenancewindows` Documentation + +The `sqlpoolsmaintenancewindows` SDK allows for interaction with the Azure Resource Manager Service `synapse` (API Version `2021-06-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/synapse/2021-06-01/sqlpoolsmaintenancewindows" +``` + + +### Client Initialization + +```go +client := sqlpoolsmaintenancewindows.NewSqlPoolsMaintenanceWindowsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `SqlPoolsMaintenanceWindowsClient.SqlPoolMaintenanceWindowsCreateOrUpdate` + +```go +ctx := context.TODO() +id := sqlpoolsmaintenancewindows.NewSqlPoolID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "sqlPoolValue") + +payload := sqlpoolsmaintenancewindows.MaintenanceWindows{ + // ... +} + + +read, err := client.SqlPoolMaintenanceWindowsCreateOrUpdate(ctx, id, payload, sqlpoolsmaintenancewindows.DefaultSqlPoolMaintenanceWindowsCreateOrUpdateOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `SqlPoolsMaintenanceWindowsClient.SqlPoolMaintenanceWindowsGet` + +```go +ctx := context.TODO() +id := sqlpoolsmaintenancewindows.NewSqlPoolID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "sqlPoolValue") + +read, err := client.SqlPoolMaintenanceWindowsGet(ctx, id, sqlpoolsmaintenancewindows.DefaultSqlPoolMaintenanceWindowsGetOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` diff --git a/resource-manager/synapse/2021-06-01/sqlpoolsmaintenancewindows/client.go b/resource-manager/synapse/2021-06-01/sqlpoolsmaintenancewindows/client.go new file mode 100644 index 00000000000..c4a76cbe3a3 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolsmaintenancewindows/client.go @@ -0,0 +1,26 @@ +package sqlpoolsmaintenancewindows + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SqlPoolsMaintenanceWindowsClient struct { + Client *resourcemanager.Client +} + +func NewSqlPoolsMaintenanceWindowsClientWithBaseURI(sdkApi sdkEnv.Api) (*SqlPoolsMaintenanceWindowsClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "sqlpoolsmaintenancewindows", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating SqlPoolsMaintenanceWindowsClient: %+v", err) + } + + return &SqlPoolsMaintenanceWindowsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolsmaintenancewindows/constants.go b/resource-manager/synapse/2021-06-01/sqlpoolsmaintenancewindows/constants.go new file mode 100644 index 00000000000..2fca9630692 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolsmaintenancewindows/constants.go @@ -0,0 +1,66 @@ +package sqlpoolsmaintenancewindows + +import ( + "encoding/json" + "fmt" + "strings" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DayOfWeek string + +const ( + DayOfWeekFriday DayOfWeek = "Friday" + DayOfWeekMonday DayOfWeek = "Monday" + DayOfWeekSaturday DayOfWeek = "Saturday" + DayOfWeekSunday DayOfWeek = "Sunday" + DayOfWeekThursday DayOfWeek = "Thursday" + DayOfWeekTuesday DayOfWeek = "Tuesday" + DayOfWeekWednesday DayOfWeek = "Wednesday" +) + +func PossibleValuesForDayOfWeek() []string { + return []string{ + string(DayOfWeekFriday), + string(DayOfWeekMonday), + string(DayOfWeekSaturday), + string(DayOfWeekSunday), + string(DayOfWeekThursday), + string(DayOfWeekTuesday), + string(DayOfWeekWednesday), + } +} + +func (s *DayOfWeek) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseDayOfWeek(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseDayOfWeek(input string) (*DayOfWeek, error) { + vals := map[string]DayOfWeek{ + "friday": DayOfWeekFriday, + "monday": DayOfWeekMonday, + "saturday": DayOfWeekSaturday, + "sunday": DayOfWeekSunday, + "thursday": DayOfWeekThursday, + "tuesday": DayOfWeekTuesday, + "wednesday": DayOfWeekWednesday, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := DayOfWeek(input) + return &out, nil +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolsmaintenancewindows/id_sqlpool.go b/resource-manager/synapse/2021-06-01/sqlpoolsmaintenancewindows/id_sqlpool.go new file mode 100644 index 00000000000..61b2ad0bf03 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolsmaintenancewindows/id_sqlpool.go @@ -0,0 +1,134 @@ +package sqlpoolsmaintenancewindows + +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 = &SqlPoolId{} + +// SqlPoolId is a struct representing the Resource ID for a Sql Pool +type SqlPoolId struct { + SubscriptionId string + ResourceGroupName string + WorkspaceName string + SqlPoolName string +} + +// NewSqlPoolID returns a new SqlPoolId struct +func NewSqlPoolID(subscriptionId string, resourceGroupName string, workspaceName string, sqlPoolName string) SqlPoolId { + return SqlPoolId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + WorkspaceName: workspaceName, + SqlPoolName: sqlPoolName, + } +} + +// ParseSqlPoolID parses 'input' into a SqlPoolId +func ParseSqlPoolID(input string) (*SqlPoolId, error) { + parser := resourceids.NewParserFromResourceIdType(&SqlPoolId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := SqlPoolId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseSqlPoolIDInsensitively parses 'input' case-insensitively into a SqlPoolId +// note: this method should only be used for API response data and not user input +func ParseSqlPoolIDInsensitively(input string) (*SqlPoolId, error) { + parser := resourceids.NewParserFromResourceIdType(&SqlPoolId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := SqlPoolId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *SqlPoolId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.WorkspaceName, ok = input.Parsed["workspaceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "workspaceName", input) + } + + if id.SqlPoolName, ok = input.Parsed["sqlPoolName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "sqlPoolName", input) + } + + return nil +} + +// ValidateSqlPoolID checks that 'input' can be parsed as a Sql Pool ID +func ValidateSqlPoolID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseSqlPoolID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Sql Pool ID +func (id SqlPoolId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Synapse/workspaces/%s/sqlPools/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.WorkspaceName, id.SqlPoolName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Sql Pool ID +func (id SqlPoolId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftSynapse", "Microsoft.Synapse", "Microsoft.Synapse"), + resourceids.StaticSegment("staticWorkspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceName", "workspaceValue"), + resourceids.StaticSegment("staticSqlPools", "sqlPools", "sqlPools"), + resourceids.UserSpecifiedSegment("sqlPoolName", "sqlPoolValue"), + } +} + +// String returns a human-readable description of this Sql Pool ID +func (id SqlPoolId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Workspace Name: %q", id.WorkspaceName), + fmt.Sprintf("Sql Pool Name: %q", id.SqlPoolName), + } + return fmt.Sprintf("Sql Pool (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolsmaintenancewindows/id_sqlpool_test.go b/resource-manager/synapse/2021-06-01/sqlpoolsmaintenancewindows/id_sqlpool_test.go new file mode 100644 index 00000000000..fee2922ce2d --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolsmaintenancewindows/id_sqlpool_test.go @@ -0,0 +1,327 @@ +package sqlpoolsmaintenancewindows + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &SqlPoolId{} + +func TestNewSqlPoolID(t *testing.T) { + id := NewSqlPoolID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "sqlPoolValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.WorkspaceName != "workspaceValue" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceName'", id.WorkspaceName, "workspaceValue") + } + + if id.SqlPoolName != "sqlPoolValue" { + t.Fatalf("Expected %q but got %q for Segment 'SqlPoolName'", id.SqlPoolName, "sqlPoolValue") + } +} + +func TestFormatSqlPoolID(t *testing.T) { + actual := NewSqlPoolID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "sqlPoolValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseSqlPoolID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *SqlPoolId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue", + Expected: &SqlPoolId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + SqlPoolName: "sqlPoolValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseSqlPoolID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + if actual.SqlPoolName != v.Expected.SqlPoolName { + t.Fatalf("Expected %q but got %q for SqlPoolName", v.Expected.SqlPoolName, actual.SqlPoolName) + } + + } +} + +func TestParseSqlPoolIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *SqlPoolId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/sQlPoOlS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue", + Expected: &SqlPoolId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + SqlPoolName: "sqlPoolValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/sQlPoOlS/sQlPoOlVaLuE", + Expected: &SqlPoolId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + WorkspaceName: "wOrKsPaCeVaLuE", + SqlPoolName: "sQlPoOlVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/sQlPoOlS/sQlPoOlVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseSqlPoolIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + if actual.SqlPoolName != v.Expected.SqlPoolName { + t.Fatalf("Expected %q but got %q for SqlPoolName", v.Expected.SqlPoolName, actual.SqlPoolName) + } + + } +} + +func TestSegmentsForSqlPoolId(t *testing.T) { + segments := SqlPoolId{}.Segments() + if len(segments) == 0 { + t.Fatalf("SqlPoolId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolsmaintenancewindows/method_sqlpoolmaintenancewindowscreateorupdate.go b/resource-manager/synapse/2021-06-01/sqlpoolsmaintenancewindows/method_sqlpoolmaintenancewindowscreateorupdate.go new file mode 100644 index 00000000000..6aad8c3b5f1 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolsmaintenancewindows/method_sqlpoolmaintenancewindowscreateorupdate.go @@ -0,0 +1,79 @@ +package sqlpoolsmaintenancewindows + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SqlPoolMaintenanceWindowsCreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +type SqlPoolMaintenanceWindowsCreateOrUpdateOperationOptions struct { + MaintenanceWindowName *string +} + +func DefaultSqlPoolMaintenanceWindowsCreateOrUpdateOperationOptions() SqlPoolMaintenanceWindowsCreateOrUpdateOperationOptions { + return SqlPoolMaintenanceWindowsCreateOrUpdateOperationOptions{} +} + +func (o SqlPoolMaintenanceWindowsCreateOrUpdateOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o SqlPoolMaintenanceWindowsCreateOrUpdateOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o SqlPoolMaintenanceWindowsCreateOrUpdateOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.MaintenanceWindowName != nil { + out.Append("maintenanceWindowName", fmt.Sprintf("%v", *o.MaintenanceWindowName)) + } + return &out +} + +// SqlPoolMaintenanceWindowsCreateOrUpdate ... +func (c SqlPoolsMaintenanceWindowsClient) SqlPoolMaintenanceWindowsCreateOrUpdate(ctx context.Context, id SqlPoolId, input MaintenanceWindows, options SqlPoolMaintenanceWindowsCreateOrUpdateOperationOptions) (result SqlPoolMaintenanceWindowsCreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: fmt.Sprintf("%s/maintenancewindows/current", id.ID()), + OptionsObject: options, + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolsmaintenancewindows/method_sqlpoolmaintenancewindowsget.go b/resource-manager/synapse/2021-06-01/sqlpoolsmaintenancewindows/method_sqlpoolmaintenancewindowsget.go new file mode 100644 index 00000000000..6e458c8f501 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolsmaintenancewindows/method_sqlpoolmaintenancewindowsget.go @@ -0,0 +1,80 @@ +package sqlpoolsmaintenancewindows + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SqlPoolMaintenanceWindowsGetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *MaintenanceWindows +} + +type SqlPoolMaintenanceWindowsGetOperationOptions struct { + MaintenanceWindowName *string +} + +func DefaultSqlPoolMaintenanceWindowsGetOperationOptions() SqlPoolMaintenanceWindowsGetOperationOptions { + return SqlPoolMaintenanceWindowsGetOperationOptions{} +} + +func (o SqlPoolMaintenanceWindowsGetOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o SqlPoolMaintenanceWindowsGetOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o SqlPoolMaintenanceWindowsGetOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.MaintenanceWindowName != nil { + out.Append("maintenanceWindowName", fmt.Sprintf("%v", *o.MaintenanceWindowName)) + } + return &out +} + +// SqlPoolMaintenanceWindowsGet ... +func (c SqlPoolsMaintenanceWindowsClient) SqlPoolMaintenanceWindowsGet(ctx context.Context, id SqlPoolId, options SqlPoolMaintenanceWindowsGetOperationOptions) (result SqlPoolMaintenanceWindowsGetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/maintenancewindows/current", id.ID()), + OptionsObject: options, + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolsmaintenancewindows/model_maintenancewindows.go b/resource-manager/synapse/2021-06-01/sqlpoolsmaintenancewindows/model_maintenancewindows.go new file mode 100644 index 00000000000..e735dac1d41 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolsmaintenancewindows/model_maintenancewindows.go @@ -0,0 +1,11 @@ +package sqlpoolsmaintenancewindows + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MaintenanceWindows struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *MaintenanceWindowsProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolsmaintenancewindows/model_maintenancewindowsproperties.go b/resource-manager/synapse/2021-06-01/sqlpoolsmaintenancewindows/model_maintenancewindowsproperties.go new file mode 100644 index 00000000000..e55627d82b6 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolsmaintenancewindows/model_maintenancewindowsproperties.go @@ -0,0 +1,8 @@ +package sqlpoolsmaintenancewindows + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MaintenanceWindowsProperties struct { + TimeRanges *[]MaintenanceWindowTimeRange `json:"timeRanges,omitempty"` +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolsmaintenancewindows/model_maintenancewindowtimerange.go b/resource-manager/synapse/2021-06-01/sqlpoolsmaintenancewindows/model_maintenancewindowtimerange.go new file mode 100644 index 00000000000..f860cb4f758 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolsmaintenancewindows/model_maintenancewindowtimerange.go @@ -0,0 +1,10 @@ +package sqlpoolsmaintenancewindows + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MaintenanceWindowTimeRange struct { + DayOfWeek *DayOfWeek `json:"dayOfWeek,omitempty"` + Duration *string `json:"duration,omitempty"` + StartTime *string `json:"startTime,omitempty"` +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolsmaintenancewindows/version.go b/resource-manager/synapse/2021-06-01/sqlpoolsmaintenancewindows/version.go new file mode 100644 index 00000000000..e9e76c62876 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolsmaintenancewindows/version.go @@ -0,0 +1,12 @@ +package sqlpoolsmaintenancewindows + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2021-06-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/sqlpoolsmaintenancewindows/%s", defaultApiVersion) +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolsoperations/README.md b/resource-manager/synapse/2021-06-01/sqlpoolsoperations/README.md new file mode 100644 index 00000000000..a519c44338e --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolsoperations/README.md @@ -0,0 +1,37 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/synapse/2021-06-01/sqlpoolsoperations` Documentation + +The `sqlpoolsoperations` SDK allows for interaction with the Azure Resource Manager Service `synapse` (API Version `2021-06-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/synapse/2021-06-01/sqlpoolsoperations" +``` + + +### Client Initialization + +```go +client := sqlpoolsoperations.NewSqlPoolsOperationsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `SqlPoolsOperationsClient.SqlPoolOperationsList` + +```go +ctx := context.TODO() +id := sqlpoolsoperations.NewSqlPoolID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "sqlPoolValue") + +// alternatively `client.SqlPoolOperationsList(ctx, id)` can be used to do batched pagination +items, err := client.SqlPoolOperationsListComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/synapse/2021-06-01/sqlpoolsoperations/client.go b/resource-manager/synapse/2021-06-01/sqlpoolsoperations/client.go new file mode 100644 index 00000000000..59d8d91e0f1 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolsoperations/client.go @@ -0,0 +1,26 @@ +package sqlpoolsoperations + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SqlPoolsOperationsClient struct { + Client *resourcemanager.Client +} + +func NewSqlPoolsOperationsClientWithBaseURI(sdkApi sdkEnv.Api) (*SqlPoolsOperationsClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "sqlpoolsoperations", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating SqlPoolsOperationsClient: %+v", err) + } + + return &SqlPoolsOperationsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolsoperations/constants.go b/resource-manager/synapse/2021-06-01/sqlpoolsoperations/constants.go new file mode 100644 index 00000000000..26b94ed559e --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolsoperations/constants.go @@ -0,0 +1,63 @@ +package sqlpoolsoperations + +import ( + "encoding/json" + "fmt" + "strings" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ManagementOperationState string + +const ( + ManagementOperationStateCancelInProgress ManagementOperationState = "CancelInProgress" + ManagementOperationStateCancelled ManagementOperationState = "Cancelled" + ManagementOperationStateFailed ManagementOperationState = "Failed" + ManagementOperationStateInProgress ManagementOperationState = "InProgress" + ManagementOperationStatePending ManagementOperationState = "Pending" + ManagementOperationStateSucceeded ManagementOperationState = "Succeeded" +) + +func PossibleValuesForManagementOperationState() []string { + return []string{ + string(ManagementOperationStateCancelInProgress), + string(ManagementOperationStateCancelled), + string(ManagementOperationStateFailed), + string(ManagementOperationStateInProgress), + string(ManagementOperationStatePending), + string(ManagementOperationStateSucceeded), + } +} + +func (s *ManagementOperationState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseManagementOperationState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseManagementOperationState(input string) (*ManagementOperationState, error) { + vals := map[string]ManagementOperationState{ + "cancelinprogress": ManagementOperationStateCancelInProgress, + "cancelled": ManagementOperationStateCancelled, + "failed": ManagementOperationStateFailed, + "inprogress": ManagementOperationStateInProgress, + "pending": ManagementOperationStatePending, + "succeeded": ManagementOperationStateSucceeded, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ManagementOperationState(input) + return &out, nil +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolsoperations/id_sqlpool.go b/resource-manager/synapse/2021-06-01/sqlpoolsoperations/id_sqlpool.go new file mode 100644 index 00000000000..3b6000e3dfd --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolsoperations/id_sqlpool.go @@ -0,0 +1,134 @@ +package sqlpoolsoperations + +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 = &SqlPoolId{} + +// SqlPoolId is a struct representing the Resource ID for a Sql Pool +type SqlPoolId struct { + SubscriptionId string + ResourceGroupName string + WorkspaceName string + SqlPoolName string +} + +// NewSqlPoolID returns a new SqlPoolId struct +func NewSqlPoolID(subscriptionId string, resourceGroupName string, workspaceName string, sqlPoolName string) SqlPoolId { + return SqlPoolId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + WorkspaceName: workspaceName, + SqlPoolName: sqlPoolName, + } +} + +// ParseSqlPoolID parses 'input' into a SqlPoolId +func ParseSqlPoolID(input string) (*SqlPoolId, error) { + parser := resourceids.NewParserFromResourceIdType(&SqlPoolId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := SqlPoolId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseSqlPoolIDInsensitively parses 'input' case-insensitively into a SqlPoolId +// note: this method should only be used for API response data and not user input +func ParseSqlPoolIDInsensitively(input string) (*SqlPoolId, error) { + parser := resourceids.NewParserFromResourceIdType(&SqlPoolId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := SqlPoolId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *SqlPoolId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.WorkspaceName, ok = input.Parsed["workspaceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "workspaceName", input) + } + + if id.SqlPoolName, ok = input.Parsed["sqlPoolName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "sqlPoolName", input) + } + + return nil +} + +// ValidateSqlPoolID checks that 'input' can be parsed as a Sql Pool ID +func ValidateSqlPoolID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseSqlPoolID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Sql Pool ID +func (id SqlPoolId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Synapse/workspaces/%s/sqlPools/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.WorkspaceName, id.SqlPoolName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Sql Pool ID +func (id SqlPoolId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftSynapse", "Microsoft.Synapse", "Microsoft.Synapse"), + resourceids.StaticSegment("staticWorkspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceName", "workspaceValue"), + resourceids.StaticSegment("staticSqlPools", "sqlPools", "sqlPools"), + resourceids.UserSpecifiedSegment("sqlPoolName", "sqlPoolValue"), + } +} + +// String returns a human-readable description of this Sql Pool ID +func (id SqlPoolId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Workspace Name: %q", id.WorkspaceName), + fmt.Sprintf("Sql Pool Name: %q", id.SqlPoolName), + } + return fmt.Sprintf("Sql Pool (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolsoperations/id_sqlpool_test.go b/resource-manager/synapse/2021-06-01/sqlpoolsoperations/id_sqlpool_test.go new file mode 100644 index 00000000000..37d95ddcb6e --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolsoperations/id_sqlpool_test.go @@ -0,0 +1,327 @@ +package sqlpoolsoperations + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &SqlPoolId{} + +func TestNewSqlPoolID(t *testing.T) { + id := NewSqlPoolID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "sqlPoolValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.WorkspaceName != "workspaceValue" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceName'", id.WorkspaceName, "workspaceValue") + } + + if id.SqlPoolName != "sqlPoolValue" { + t.Fatalf("Expected %q but got %q for Segment 'SqlPoolName'", id.SqlPoolName, "sqlPoolValue") + } +} + +func TestFormatSqlPoolID(t *testing.T) { + actual := NewSqlPoolID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "sqlPoolValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseSqlPoolID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *SqlPoolId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue", + Expected: &SqlPoolId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + SqlPoolName: "sqlPoolValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseSqlPoolID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + if actual.SqlPoolName != v.Expected.SqlPoolName { + t.Fatalf("Expected %q but got %q for SqlPoolName", v.Expected.SqlPoolName, actual.SqlPoolName) + } + + } +} + +func TestParseSqlPoolIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *SqlPoolId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/sQlPoOlS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue", + Expected: &SqlPoolId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + SqlPoolName: "sqlPoolValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/sQlPoOlS/sQlPoOlVaLuE", + Expected: &SqlPoolId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + WorkspaceName: "wOrKsPaCeVaLuE", + SqlPoolName: "sQlPoOlVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/sQlPoOlS/sQlPoOlVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseSqlPoolIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + if actual.SqlPoolName != v.Expected.SqlPoolName { + t.Fatalf("Expected %q but got %q for SqlPoolName", v.Expected.SqlPoolName, actual.SqlPoolName) + } + + } +} + +func TestSegmentsForSqlPoolId(t *testing.T) { + segments := SqlPoolId{}.Segments() + if len(segments) == 0 { + t.Fatalf("SqlPoolId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolsoperations/method_sqlpooloperationslist.go b/resource-manager/synapse/2021-06-01/sqlpoolsoperations/method_sqlpooloperationslist.go new file mode 100644 index 00000000000..db5d0f7938b --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolsoperations/method_sqlpooloperationslist.go @@ -0,0 +1,91 @@ +package sqlpoolsoperations + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SqlPoolOperationsListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]SqlPoolOperation +} + +type SqlPoolOperationsListCompleteResult struct { + LatestHttpResponse *http.Response + Items []SqlPoolOperation +} + +// SqlPoolOperationsList ... +func (c SqlPoolsOperationsClient) SqlPoolOperationsList(ctx context.Context, id SqlPoolId) (result SqlPoolOperationsListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/operations", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]SqlPoolOperation `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// SqlPoolOperationsListComplete retrieves all the results into a single object +func (c SqlPoolsOperationsClient) SqlPoolOperationsListComplete(ctx context.Context, id SqlPoolId) (SqlPoolOperationsListCompleteResult, error) { + return c.SqlPoolOperationsListCompleteMatchingPredicate(ctx, id, SqlPoolOperationOperationPredicate{}) +} + +// SqlPoolOperationsListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c SqlPoolsOperationsClient) SqlPoolOperationsListCompleteMatchingPredicate(ctx context.Context, id SqlPoolId, predicate SqlPoolOperationOperationPredicate) (result SqlPoolOperationsListCompleteResult, err error) { + items := make([]SqlPoolOperation, 0) + + resp, err := c.SqlPoolOperationsList(ctx, id) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = SqlPoolOperationsListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolsoperations/model_sqlpooloperation.go b/resource-manager/synapse/2021-06-01/sqlpoolsoperations/model_sqlpooloperation.go new file mode 100644 index 00000000000..8b35fbb553e --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolsoperations/model_sqlpooloperation.go @@ -0,0 +1,11 @@ +package sqlpoolsoperations + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SqlPoolOperation struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *SqlPoolOperationProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolsoperations/model_sqlpooloperationproperties.go b/resource-manager/synapse/2021-06-01/sqlpoolsoperations/model_sqlpooloperationproperties.go new file mode 100644 index 00000000000..8f4146aecfc --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolsoperations/model_sqlpooloperationproperties.go @@ -0,0 +1,51 @@ +package sqlpoolsoperations + +import ( + "time" + + "github.com/hashicorp/go-azure-helpers/lang/dates" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SqlPoolOperationProperties struct { + DatabaseName *string `json:"databaseName,omitempty"` + Description *string `json:"description,omitempty"` + ErrorCode *int64 `json:"errorCode,omitempty"` + ErrorDescription *string `json:"errorDescription,omitempty"` + ErrorSeverity *int64 `json:"errorSeverity,omitempty"` + EstimatedCompletionTime *string `json:"estimatedCompletionTime,omitempty"` + IsCancellable *bool `json:"isCancellable,omitempty"` + IsUserError *bool `json:"isUserError,omitempty"` + Operation *string `json:"operation,omitempty"` + OperationFriendlyName *string `json:"operationFriendlyName,omitempty"` + PercentComplete *int64 `json:"percentComplete,omitempty"` + ServerName *string `json:"serverName,omitempty"` + StartTime *string `json:"startTime,omitempty"` + State *ManagementOperationState `json:"state,omitempty"` +} + +func (o *SqlPoolOperationProperties) GetEstimatedCompletionTimeAsTime() (*time.Time, error) { + if o.EstimatedCompletionTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.EstimatedCompletionTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *SqlPoolOperationProperties) SetEstimatedCompletionTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.EstimatedCompletionTime = &formatted +} + +func (o *SqlPoolOperationProperties) GetStartTimeAsTime() (*time.Time, error) { + if o.StartTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.StartTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *SqlPoolOperationProperties) SetStartTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.StartTime = &formatted +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolsoperations/predicates.go b/resource-manager/synapse/2021-06-01/sqlpoolsoperations/predicates.go new file mode 100644 index 00000000000..a4df5c28759 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolsoperations/predicates.go @@ -0,0 +1,27 @@ +package sqlpoolsoperations + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SqlPoolOperationOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p SqlPoolOperationOperationPredicate) Matches(input SqlPoolOperation) bool { + + if p.Id != nil && (input.Id == nil || *p.Id != *input.Id) { + return false + } + + if p.Name != nil && (input.Name == nil || *p.Name != *input.Name) { + return false + } + + if p.Type != nil && (input.Type == nil || *p.Type != *input.Type) { + return false + } + + return true +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolsoperations/version.go b/resource-manager/synapse/2021-06-01/sqlpoolsoperations/version.go new file mode 100644 index 00000000000..ce8581f5cb5 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolsoperations/version.go @@ -0,0 +1,12 @@ +package sqlpoolsoperations + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2021-06-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/sqlpoolsoperations/%s", defaultApiVersion) +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolsreplicationlinks/README.md b/resource-manager/synapse/2021-06-01/sqlpoolsreplicationlinks/README.md new file mode 100644 index 00000000000..c6f3c5709d6 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolsreplicationlinks/README.md @@ -0,0 +1,53 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/synapse/2021-06-01/sqlpoolsreplicationlinks` Documentation + +The `sqlpoolsreplicationlinks` SDK allows for interaction with the Azure Resource Manager Service `synapse` (API Version `2021-06-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/synapse/2021-06-01/sqlpoolsreplicationlinks" +``` + + +### Client Initialization + +```go +client := sqlpoolsreplicationlinks.NewSqlPoolsReplicationLinksClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `SqlPoolsReplicationLinksClient.SqlPoolReplicationLinksGetByName` + +```go +ctx := context.TODO() +id := sqlpoolsreplicationlinks.NewReplicationLinkID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "sqlPoolValue", "linkIdValue") + +read, err := client.SqlPoolReplicationLinksGetByName(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `SqlPoolsReplicationLinksClient.SqlPoolReplicationLinksList` + +```go +ctx := context.TODO() +id := sqlpoolsreplicationlinks.NewSqlPoolID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "sqlPoolValue") + +// alternatively `client.SqlPoolReplicationLinksList(ctx, id)` can be used to do batched pagination +items, err := client.SqlPoolReplicationLinksListComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/synapse/2021-06-01/sqlpoolsreplicationlinks/client.go b/resource-manager/synapse/2021-06-01/sqlpoolsreplicationlinks/client.go new file mode 100644 index 00000000000..1036717b75b --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolsreplicationlinks/client.go @@ -0,0 +1,26 @@ +package sqlpoolsreplicationlinks + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SqlPoolsReplicationLinksClient struct { + Client *resourcemanager.Client +} + +func NewSqlPoolsReplicationLinksClientWithBaseURI(sdkApi sdkEnv.Api) (*SqlPoolsReplicationLinksClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "sqlpoolsreplicationlinks", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating SqlPoolsReplicationLinksClient: %+v", err) + } + + return &SqlPoolsReplicationLinksClient{ + Client: client, + }, nil +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolsreplicationlinks/constants.go b/resource-manager/synapse/2021-06-01/sqlpoolsreplicationlinks/constants.go new file mode 100644 index 00000000000..e9584200c6e --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolsreplicationlinks/constants.go @@ -0,0 +1,107 @@ +package sqlpoolsreplicationlinks + +import ( + "encoding/json" + "fmt" + "strings" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ReplicationRole string + +const ( + ReplicationRoleCopy ReplicationRole = "Copy" + ReplicationRoleNonReadableSecondary ReplicationRole = "NonReadableSecondary" + ReplicationRolePrimary ReplicationRole = "Primary" + ReplicationRoleSecondary ReplicationRole = "Secondary" + ReplicationRoleSource ReplicationRole = "Source" +) + +func PossibleValuesForReplicationRole() []string { + return []string{ + string(ReplicationRoleCopy), + string(ReplicationRoleNonReadableSecondary), + string(ReplicationRolePrimary), + string(ReplicationRoleSecondary), + string(ReplicationRoleSource), + } +} + +func (s *ReplicationRole) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseReplicationRole(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseReplicationRole(input string) (*ReplicationRole, error) { + vals := map[string]ReplicationRole{ + "copy": ReplicationRoleCopy, + "nonreadablesecondary": ReplicationRoleNonReadableSecondary, + "primary": ReplicationRolePrimary, + "secondary": ReplicationRoleSecondary, + "source": ReplicationRoleSource, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ReplicationRole(input) + return &out, nil +} + +type ReplicationState string + +const ( + ReplicationStateCATCHUP ReplicationState = "CATCH_UP" + ReplicationStatePENDING ReplicationState = "PENDING" + ReplicationStateSEEDING ReplicationState = "SEEDING" + ReplicationStateSUSPENDED ReplicationState = "SUSPENDED" +) + +func PossibleValuesForReplicationState() []string { + return []string{ + string(ReplicationStateCATCHUP), + string(ReplicationStatePENDING), + string(ReplicationStateSEEDING), + string(ReplicationStateSUSPENDED), + } +} + +func (s *ReplicationState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseReplicationState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseReplicationState(input string) (*ReplicationState, error) { + vals := map[string]ReplicationState{ + "catch_up": ReplicationStateCATCHUP, + "pending": ReplicationStatePENDING, + "seeding": ReplicationStateSEEDING, + "suspended": ReplicationStateSUSPENDED, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ReplicationState(input) + return &out, nil +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolsreplicationlinks/id_replicationlink.go b/resource-manager/synapse/2021-06-01/sqlpoolsreplicationlinks/id_replicationlink.go new file mode 100644 index 00000000000..cac914bac4f --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolsreplicationlinks/id_replicationlink.go @@ -0,0 +1,143 @@ +package sqlpoolsreplicationlinks + +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 = &ReplicationLinkId{} + +// ReplicationLinkId is a struct representing the Resource ID for a Replication Link +type ReplicationLinkId struct { + SubscriptionId string + ResourceGroupName string + WorkspaceName string + SqlPoolName string + LinkId string +} + +// NewReplicationLinkID returns a new ReplicationLinkId struct +func NewReplicationLinkID(subscriptionId string, resourceGroupName string, workspaceName string, sqlPoolName string, linkId string) ReplicationLinkId { + return ReplicationLinkId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + WorkspaceName: workspaceName, + SqlPoolName: sqlPoolName, + LinkId: linkId, + } +} + +// ParseReplicationLinkID parses 'input' into a ReplicationLinkId +func ParseReplicationLinkID(input string) (*ReplicationLinkId, error) { + parser := resourceids.NewParserFromResourceIdType(&ReplicationLinkId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ReplicationLinkId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseReplicationLinkIDInsensitively parses 'input' case-insensitively into a ReplicationLinkId +// note: this method should only be used for API response data and not user input +func ParseReplicationLinkIDInsensitively(input string) (*ReplicationLinkId, error) { + parser := resourceids.NewParserFromResourceIdType(&ReplicationLinkId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ReplicationLinkId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ReplicationLinkId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.WorkspaceName, ok = input.Parsed["workspaceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "workspaceName", input) + } + + if id.SqlPoolName, ok = input.Parsed["sqlPoolName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "sqlPoolName", input) + } + + if id.LinkId, ok = input.Parsed["linkId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "linkId", input) + } + + return nil +} + +// ValidateReplicationLinkID checks that 'input' can be parsed as a Replication Link ID +func ValidateReplicationLinkID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseReplicationLinkID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Replication Link ID +func (id ReplicationLinkId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Synapse/workspaces/%s/sqlPools/%s/replicationLinks/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.WorkspaceName, id.SqlPoolName, id.LinkId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Replication Link ID +func (id ReplicationLinkId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftSynapse", "Microsoft.Synapse", "Microsoft.Synapse"), + resourceids.StaticSegment("staticWorkspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceName", "workspaceValue"), + resourceids.StaticSegment("staticSqlPools", "sqlPools", "sqlPools"), + resourceids.UserSpecifiedSegment("sqlPoolName", "sqlPoolValue"), + resourceids.StaticSegment("staticReplicationLinks", "replicationLinks", "replicationLinks"), + resourceids.UserSpecifiedSegment("linkId", "linkIdValue"), + } +} + +// String returns a human-readable description of this Replication Link ID +func (id ReplicationLinkId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Workspace Name: %q", id.WorkspaceName), + fmt.Sprintf("Sql Pool Name: %q", id.SqlPoolName), + fmt.Sprintf("Link: %q", id.LinkId), + } + return fmt.Sprintf("Replication Link (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolsreplicationlinks/id_replicationlink_test.go b/resource-manager/synapse/2021-06-01/sqlpoolsreplicationlinks/id_replicationlink_test.go new file mode 100644 index 00000000000..95fd6a59b36 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolsreplicationlinks/id_replicationlink_test.go @@ -0,0 +1,372 @@ +package sqlpoolsreplicationlinks + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &ReplicationLinkId{} + +func TestNewReplicationLinkID(t *testing.T) { + id := NewReplicationLinkID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "sqlPoolValue", "linkIdValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.WorkspaceName != "workspaceValue" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceName'", id.WorkspaceName, "workspaceValue") + } + + if id.SqlPoolName != "sqlPoolValue" { + t.Fatalf("Expected %q but got %q for Segment 'SqlPoolName'", id.SqlPoolName, "sqlPoolValue") + } + + if id.LinkId != "linkIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'LinkId'", id.LinkId, "linkIdValue") + } +} + +func TestFormatReplicationLinkID(t *testing.T) { + actual := NewReplicationLinkID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "sqlPoolValue", "linkIdValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/replicationLinks/linkIdValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseReplicationLinkID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ReplicationLinkId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/replicationLinks", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/replicationLinks/linkIdValue", + Expected: &ReplicationLinkId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + SqlPoolName: "sqlPoolValue", + LinkId: "linkIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/replicationLinks/linkIdValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseReplicationLinkID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + if actual.SqlPoolName != v.Expected.SqlPoolName { + t.Fatalf("Expected %q but got %q for SqlPoolName", v.Expected.SqlPoolName, actual.SqlPoolName) + } + + if actual.LinkId != v.Expected.LinkId { + t.Fatalf("Expected %q but got %q for LinkId", v.Expected.LinkId, actual.LinkId) + } + + } +} + +func TestParseReplicationLinkIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ReplicationLinkId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/sQlPoOlS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/sQlPoOlS/sQlPoOlVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/replicationLinks", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/sQlPoOlS/sQlPoOlVaLuE/rEpLiCaTiOnLiNkS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/replicationLinks/linkIdValue", + Expected: &ReplicationLinkId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + SqlPoolName: "sqlPoolValue", + LinkId: "linkIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/replicationLinks/linkIdValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/sQlPoOlS/sQlPoOlVaLuE/rEpLiCaTiOnLiNkS/lInKiDvAlUe", + Expected: &ReplicationLinkId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + WorkspaceName: "wOrKsPaCeVaLuE", + SqlPoolName: "sQlPoOlVaLuE", + LinkId: "lInKiDvAlUe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/sQlPoOlS/sQlPoOlVaLuE/rEpLiCaTiOnLiNkS/lInKiDvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseReplicationLinkIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + if actual.SqlPoolName != v.Expected.SqlPoolName { + t.Fatalf("Expected %q but got %q for SqlPoolName", v.Expected.SqlPoolName, actual.SqlPoolName) + } + + if actual.LinkId != v.Expected.LinkId { + t.Fatalf("Expected %q but got %q for LinkId", v.Expected.LinkId, actual.LinkId) + } + + } +} + +func TestSegmentsForReplicationLinkId(t *testing.T) { + segments := ReplicationLinkId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ReplicationLinkId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolsreplicationlinks/id_sqlpool.go b/resource-manager/synapse/2021-06-01/sqlpoolsreplicationlinks/id_sqlpool.go new file mode 100644 index 00000000000..0801341eb4f --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolsreplicationlinks/id_sqlpool.go @@ -0,0 +1,134 @@ +package sqlpoolsreplicationlinks + +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 = &SqlPoolId{} + +// SqlPoolId is a struct representing the Resource ID for a Sql Pool +type SqlPoolId struct { + SubscriptionId string + ResourceGroupName string + WorkspaceName string + SqlPoolName string +} + +// NewSqlPoolID returns a new SqlPoolId struct +func NewSqlPoolID(subscriptionId string, resourceGroupName string, workspaceName string, sqlPoolName string) SqlPoolId { + return SqlPoolId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + WorkspaceName: workspaceName, + SqlPoolName: sqlPoolName, + } +} + +// ParseSqlPoolID parses 'input' into a SqlPoolId +func ParseSqlPoolID(input string) (*SqlPoolId, error) { + parser := resourceids.NewParserFromResourceIdType(&SqlPoolId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := SqlPoolId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseSqlPoolIDInsensitively parses 'input' case-insensitively into a SqlPoolId +// note: this method should only be used for API response data and not user input +func ParseSqlPoolIDInsensitively(input string) (*SqlPoolId, error) { + parser := resourceids.NewParserFromResourceIdType(&SqlPoolId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := SqlPoolId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *SqlPoolId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.WorkspaceName, ok = input.Parsed["workspaceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "workspaceName", input) + } + + if id.SqlPoolName, ok = input.Parsed["sqlPoolName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "sqlPoolName", input) + } + + return nil +} + +// ValidateSqlPoolID checks that 'input' can be parsed as a Sql Pool ID +func ValidateSqlPoolID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseSqlPoolID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Sql Pool ID +func (id SqlPoolId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Synapse/workspaces/%s/sqlPools/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.WorkspaceName, id.SqlPoolName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Sql Pool ID +func (id SqlPoolId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftSynapse", "Microsoft.Synapse", "Microsoft.Synapse"), + resourceids.StaticSegment("staticWorkspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceName", "workspaceValue"), + resourceids.StaticSegment("staticSqlPools", "sqlPools", "sqlPools"), + resourceids.UserSpecifiedSegment("sqlPoolName", "sqlPoolValue"), + } +} + +// String returns a human-readable description of this Sql Pool ID +func (id SqlPoolId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Workspace Name: %q", id.WorkspaceName), + fmt.Sprintf("Sql Pool Name: %q", id.SqlPoolName), + } + return fmt.Sprintf("Sql Pool (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolsreplicationlinks/id_sqlpool_test.go b/resource-manager/synapse/2021-06-01/sqlpoolsreplicationlinks/id_sqlpool_test.go new file mode 100644 index 00000000000..be1f886811e --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolsreplicationlinks/id_sqlpool_test.go @@ -0,0 +1,327 @@ +package sqlpoolsreplicationlinks + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &SqlPoolId{} + +func TestNewSqlPoolID(t *testing.T) { + id := NewSqlPoolID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "sqlPoolValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.WorkspaceName != "workspaceValue" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceName'", id.WorkspaceName, "workspaceValue") + } + + if id.SqlPoolName != "sqlPoolValue" { + t.Fatalf("Expected %q but got %q for Segment 'SqlPoolName'", id.SqlPoolName, "sqlPoolValue") + } +} + +func TestFormatSqlPoolID(t *testing.T) { + actual := NewSqlPoolID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "sqlPoolValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseSqlPoolID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *SqlPoolId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue", + Expected: &SqlPoolId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + SqlPoolName: "sqlPoolValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseSqlPoolID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + if actual.SqlPoolName != v.Expected.SqlPoolName { + t.Fatalf("Expected %q but got %q for SqlPoolName", v.Expected.SqlPoolName, actual.SqlPoolName) + } + + } +} + +func TestParseSqlPoolIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *SqlPoolId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/sQlPoOlS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue", + Expected: &SqlPoolId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + SqlPoolName: "sqlPoolValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/sQlPoOlS/sQlPoOlVaLuE", + Expected: &SqlPoolId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + WorkspaceName: "wOrKsPaCeVaLuE", + SqlPoolName: "sQlPoOlVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/sQlPoOlS/sQlPoOlVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseSqlPoolIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + if actual.SqlPoolName != v.Expected.SqlPoolName { + t.Fatalf("Expected %q but got %q for SqlPoolName", v.Expected.SqlPoolName, actual.SqlPoolName) + } + + } +} + +func TestSegmentsForSqlPoolId(t *testing.T) { + segments := SqlPoolId{}.Segments() + if len(segments) == 0 { + t.Fatalf("SqlPoolId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolsreplicationlinks/method_sqlpoolreplicationlinksgetbyname.go b/resource-manager/synapse/2021-06-01/sqlpoolsreplicationlinks/method_sqlpoolreplicationlinksgetbyname.go new file mode 100644 index 00000000000..c75531d7373 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolsreplicationlinks/method_sqlpoolreplicationlinksgetbyname.go @@ -0,0 +1,51 @@ +package sqlpoolsreplicationlinks + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SqlPoolReplicationLinksGetByNameOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *ReplicationLink +} + +// SqlPoolReplicationLinksGetByName ... +func (c SqlPoolsReplicationLinksClient) SqlPoolReplicationLinksGetByName(ctx context.Context, id ReplicationLinkId) (result SqlPoolReplicationLinksGetByNameOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolsreplicationlinks/method_sqlpoolreplicationlinkslist.go b/resource-manager/synapse/2021-06-01/sqlpoolsreplicationlinks/method_sqlpoolreplicationlinkslist.go new file mode 100644 index 00000000000..9ebce84ea52 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolsreplicationlinks/method_sqlpoolreplicationlinkslist.go @@ -0,0 +1,91 @@ +package sqlpoolsreplicationlinks + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SqlPoolReplicationLinksListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]ReplicationLink +} + +type SqlPoolReplicationLinksListCompleteResult struct { + LatestHttpResponse *http.Response + Items []ReplicationLink +} + +// SqlPoolReplicationLinksList ... +func (c SqlPoolsReplicationLinksClient) SqlPoolReplicationLinksList(ctx context.Context, id SqlPoolId) (result SqlPoolReplicationLinksListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/replicationLinks", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]ReplicationLink `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// SqlPoolReplicationLinksListComplete retrieves all the results into a single object +func (c SqlPoolsReplicationLinksClient) SqlPoolReplicationLinksListComplete(ctx context.Context, id SqlPoolId) (SqlPoolReplicationLinksListCompleteResult, error) { + return c.SqlPoolReplicationLinksListCompleteMatchingPredicate(ctx, id, ReplicationLinkOperationPredicate{}) +} + +// SqlPoolReplicationLinksListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c SqlPoolsReplicationLinksClient) SqlPoolReplicationLinksListCompleteMatchingPredicate(ctx context.Context, id SqlPoolId, predicate ReplicationLinkOperationPredicate) (result SqlPoolReplicationLinksListCompleteResult, err error) { + items := make([]ReplicationLink, 0) + + resp, err := c.SqlPoolReplicationLinksList(ctx, id) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = SqlPoolReplicationLinksListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolsreplicationlinks/model_replicationlink.go b/resource-manager/synapse/2021-06-01/sqlpoolsreplicationlinks/model_replicationlink.go new file mode 100644 index 00000000000..14147729ad3 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolsreplicationlinks/model_replicationlink.go @@ -0,0 +1,12 @@ +package sqlpoolsreplicationlinks + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ReplicationLink struct { + Id *string `json:"id,omitempty"` + Location *string `json:"location,omitempty"` + Name *string `json:"name,omitempty"` + Properties *ReplicationLinkProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolsreplicationlinks/model_replicationlinkproperties.go b/resource-manager/synapse/2021-06-01/sqlpoolsreplicationlinks/model_replicationlinkproperties.go new file mode 100644 index 00000000000..7a2549432a3 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolsreplicationlinks/model_replicationlinkproperties.go @@ -0,0 +1,35 @@ +package sqlpoolsreplicationlinks + +import ( + "time" + + "github.com/hashicorp/go-azure-helpers/lang/dates" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ReplicationLinkProperties struct { + IsTerminationAllowed *bool `json:"isTerminationAllowed,omitempty"` + PartnerDatabase *string `json:"partnerDatabase,omitempty"` + PartnerLocation *string `json:"partnerLocation,omitempty"` + PartnerRole *ReplicationRole `json:"partnerRole,omitempty"` + PartnerServer *string `json:"partnerServer,omitempty"` + PercentComplete *int64 `json:"percentComplete,omitempty"` + ReplicationMode *string `json:"replicationMode,omitempty"` + ReplicationState *ReplicationState `json:"replicationState,omitempty"` + Role *ReplicationRole `json:"role,omitempty"` + StartTime *string `json:"startTime,omitempty"` +} + +func (o *ReplicationLinkProperties) GetStartTimeAsTime() (*time.Time, error) { + if o.StartTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.StartTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *ReplicationLinkProperties) SetStartTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.StartTime = &formatted +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolsreplicationlinks/predicates.go b/resource-manager/synapse/2021-06-01/sqlpoolsreplicationlinks/predicates.go new file mode 100644 index 00000000000..5130e7f588a --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolsreplicationlinks/predicates.go @@ -0,0 +1,32 @@ +package sqlpoolsreplicationlinks + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ReplicationLinkOperationPredicate struct { + Id *string + Location *string + Name *string + Type *string +} + +func (p ReplicationLinkOperationPredicate) Matches(input ReplicationLink) bool { + + if p.Id != nil && (input.Id == nil || *p.Id != *input.Id) { + return false + } + + if p.Location != nil && (input.Location == nil || *p.Location != *input.Location) { + return false + } + + if p.Name != nil && (input.Name == nil || *p.Name != *input.Name) { + return false + } + + if p.Type != nil && (input.Type == nil || *p.Type != *input.Type) { + return false + } + + return true +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolsreplicationlinks/version.go b/resource-manager/synapse/2021-06-01/sqlpoolsreplicationlinks/version.go new file mode 100644 index 00000000000..3228637639c --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolsreplicationlinks/version.go @@ -0,0 +1,12 @@ +package sqlpoolsreplicationlinks + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2021-06-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/sqlpoolsreplicationlinks/%s", defaultApiVersion) +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolsrestorepoints/README.md b/resource-manager/synapse/2021-06-01/sqlpoolsrestorepoints/README.md new file mode 100644 index 00000000000..4297f7d5469 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolsrestorepoints/README.md @@ -0,0 +1,69 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/synapse/2021-06-01/sqlpoolsrestorepoints` Documentation + +The `sqlpoolsrestorepoints` SDK allows for interaction with the Azure Resource Manager Service `synapse` (API Version `2021-06-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/synapse/2021-06-01/sqlpoolsrestorepoints" +``` + + +### Client Initialization + +```go +client := sqlpoolsrestorepoints.NewSqlPoolsRestorePointsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `SqlPoolsRestorePointsClient.SqlPoolRestorePointsCreate` + +```go +ctx := context.TODO() +id := sqlpoolsrestorepoints.NewSqlPoolID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "sqlPoolValue") + +payload := sqlpoolsrestorepoints.CreateSqlPoolRestorePointDefinition{ + // ... +} + + +if err := client.SqlPoolRestorePointsCreateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `SqlPoolsRestorePointsClient.SqlPoolRestorePointsDelete` + +```go +ctx := context.TODO() +id := sqlpoolsrestorepoints.NewRestorePointID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "sqlPoolValue", "restorePointValue") + +read, err := client.SqlPoolRestorePointsDelete(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `SqlPoolsRestorePointsClient.SqlPoolRestorePointsGet` + +```go +ctx := context.TODO() +id := sqlpoolsrestorepoints.NewRestorePointID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "sqlPoolValue", "restorePointValue") + +read, err := client.SqlPoolRestorePointsGet(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` diff --git a/resource-manager/synapse/2021-06-01/sqlpoolsrestorepoints/client.go b/resource-manager/synapse/2021-06-01/sqlpoolsrestorepoints/client.go new file mode 100644 index 00000000000..e13bb88959a --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolsrestorepoints/client.go @@ -0,0 +1,26 @@ +package sqlpoolsrestorepoints + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SqlPoolsRestorePointsClient struct { + Client *resourcemanager.Client +} + +func NewSqlPoolsRestorePointsClientWithBaseURI(sdkApi sdkEnv.Api) (*SqlPoolsRestorePointsClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "sqlpoolsrestorepoints", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating SqlPoolsRestorePointsClient: %+v", err) + } + + return &SqlPoolsRestorePointsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolsrestorepoints/constants.go b/resource-manager/synapse/2021-06-01/sqlpoolsrestorepoints/constants.go new file mode 100644 index 00000000000..d41d6434598 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolsrestorepoints/constants.go @@ -0,0 +1,51 @@ +package sqlpoolsrestorepoints + +import ( + "encoding/json" + "fmt" + "strings" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RestorePointType string + +const ( + RestorePointTypeCONTINUOUS RestorePointType = "CONTINUOUS" + RestorePointTypeDISCRETE RestorePointType = "DISCRETE" +) + +func PossibleValuesForRestorePointType() []string { + return []string{ + string(RestorePointTypeCONTINUOUS), + string(RestorePointTypeDISCRETE), + } +} + +func (s *RestorePointType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseRestorePointType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseRestorePointType(input string) (*RestorePointType, error) { + vals := map[string]RestorePointType{ + "continuous": RestorePointTypeCONTINUOUS, + "discrete": RestorePointTypeDISCRETE, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := RestorePointType(input) + return &out, nil +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolsrestorepoints/id_restorepoint.go b/resource-manager/synapse/2021-06-01/sqlpoolsrestorepoints/id_restorepoint.go new file mode 100644 index 00000000000..8a8fcad6cd4 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolsrestorepoints/id_restorepoint.go @@ -0,0 +1,143 @@ +package sqlpoolsrestorepoints + +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 = &RestorePointId{} + +// RestorePointId is a struct representing the Resource ID for a Restore Point +type RestorePointId struct { + SubscriptionId string + ResourceGroupName string + WorkspaceName string + SqlPoolName string + RestorePointName string +} + +// NewRestorePointID returns a new RestorePointId struct +func NewRestorePointID(subscriptionId string, resourceGroupName string, workspaceName string, sqlPoolName string, restorePointName string) RestorePointId { + return RestorePointId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + WorkspaceName: workspaceName, + SqlPoolName: sqlPoolName, + RestorePointName: restorePointName, + } +} + +// ParseRestorePointID parses 'input' into a RestorePointId +func ParseRestorePointID(input string) (*RestorePointId, error) { + parser := resourceids.NewParserFromResourceIdType(&RestorePointId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := RestorePointId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseRestorePointIDInsensitively parses 'input' case-insensitively into a RestorePointId +// note: this method should only be used for API response data and not user input +func ParseRestorePointIDInsensitively(input string) (*RestorePointId, error) { + parser := resourceids.NewParserFromResourceIdType(&RestorePointId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := RestorePointId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *RestorePointId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.WorkspaceName, ok = input.Parsed["workspaceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "workspaceName", input) + } + + if id.SqlPoolName, ok = input.Parsed["sqlPoolName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "sqlPoolName", input) + } + + if id.RestorePointName, ok = input.Parsed["restorePointName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "restorePointName", input) + } + + return nil +} + +// ValidateRestorePointID checks that 'input' can be parsed as a Restore Point ID +func ValidateRestorePointID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseRestorePointID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Restore Point ID +func (id RestorePointId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Synapse/workspaces/%s/sqlPools/%s/restorePoints/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.WorkspaceName, id.SqlPoolName, id.RestorePointName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Restore Point ID +func (id RestorePointId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftSynapse", "Microsoft.Synapse", "Microsoft.Synapse"), + resourceids.StaticSegment("staticWorkspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceName", "workspaceValue"), + resourceids.StaticSegment("staticSqlPools", "sqlPools", "sqlPools"), + resourceids.UserSpecifiedSegment("sqlPoolName", "sqlPoolValue"), + resourceids.StaticSegment("staticRestorePoints", "restorePoints", "restorePoints"), + resourceids.UserSpecifiedSegment("restorePointName", "restorePointValue"), + } +} + +// String returns a human-readable description of this Restore Point ID +func (id RestorePointId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Workspace Name: %q", id.WorkspaceName), + fmt.Sprintf("Sql Pool Name: %q", id.SqlPoolName), + fmt.Sprintf("Restore Point Name: %q", id.RestorePointName), + } + return fmt.Sprintf("Restore Point (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolsrestorepoints/id_restorepoint_test.go b/resource-manager/synapse/2021-06-01/sqlpoolsrestorepoints/id_restorepoint_test.go new file mode 100644 index 00000000000..de3511af37e --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolsrestorepoints/id_restorepoint_test.go @@ -0,0 +1,372 @@ +package sqlpoolsrestorepoints + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &RestorePointId{} + +func TestNewRestorePointID(t *testing.T) { + id := NewRestorePointID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "sqlPoolValue", "restorePointValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.WorkspaceName != "workspaceValue" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceName'", id.WorkspaceName, "workspaceValue") + } + + if id.SqlPoolName != "sqlPoolValue" { + t.Fatalf("Expected %q but got %q for Segment 'SqlPoolName'", id.SqlPoolName, "sqlPoolValue") + } + + if id.RestorePointName != "restorePointValue" { + t.Fatalf("Expected %q but got %q for Segment 'RestorePointName'", id.RestorePointName, "restorePointValue") + } +} + +func TestFormatRestorePointID(t *testing.T) { + actual := NewRestorePointID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "sqlPoolValue", "restorePointValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/restorePoints/restorePointValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseRestorePointID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *RestorePointId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/restorePoints", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/restorePoints/restorePointValue", + Expected: &RestorePointId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + SqlPoolName: "sqlPoolValue", + RestorePointName: "restorePointValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/restorePoints/restorePointValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseRestorePointID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + if actual.SqlPoolName != v.Expected.SqlPoolName { + t.Fatalf("Expected %q but got %q for SqlPoolName", v.Expected.SqlPoolName, actual.SqlPoolName) + } + + if actual.RestorePointName != v.Expected.RestorePointName { + t.Fatalf("Expected %q but got %q for RestorePointName", v.Expected.RestorePointName, actual.RestorePointName) + } + + } +} + +func TestParseRestorePointIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *RestorePointId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/sQlPoOlS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/sQlPoOlS/sQlPoOlVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/restorePoints", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/sQlPoOlS/sQlPoOlVaLuE/rEsToRePoInTs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/restorePoints/restorePointValue", + Expected: &RestorePointId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + SqlPoolName: "sqlPoolValue", + RestorePointName: "restorePointValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/restorePoints/restorePointValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/sQlPoOlS/sQlPoOlVaLuE/rEsToRePoInTs/rEsToRePoInTvAlUe", + Expected: &RestorePointId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + WorkspaceName: "wOrKsPaCeVaLuE", + SqlPoolName: "sQlPoOlVaLuE", + RestorePointName: "rEsToRePoInTvAlUe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/sQlPoOlS/sQlPoOlVaLuE/rEsToRePoInTs/rEsToRePoInTvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseRestorePointIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + if actual.SqlPoolName != v.Expected.SqlPoolName { + t.Fatalf("Expected %q but got %q for SqlPoolName", v.Expected.SqlPoolName, actual.SqlPoolName) + } + + if actual.RestorePointName != v.Expected.RestorePointName { + t.Fatalf("Expected %q but got %q for RestorePointName", v.Expected.RestorePointName, actual.RestorePointName) + } + + } +} + +func TestSegmentsForRestorePointId(t *testing.T) { + segments := RestorePointId{}.Segments() + if len(segments) == 0 { + t.Fatalf("RestorePointId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolsrestorepoints/id_sqlpool.go b/resource-manager/synapse/2021-06-01/sqlpoolsrestorepoints/id_sqlpool.go new file mode 100644 index 00000000000..589af30456a --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolsrestorepoints/id_sqlpool.go @@ -0,0 +1,134 @@ +package sqlpoolsrestorepoints + +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 = &SqlPoolId{} + +// SqlPoolId is a struct representing the Resource ID for a Sql Pool +type SqlPoolId struct { + SubscriptionId string + ResourceGroupName string + WorkspaceName string + SqlPoolName string +} + +// NewSqlPoolID returns a new SqlPoolId struct +func NewSqlPoolID(subscriptionId string, resourceGroupName string, workspaceName string, sqlPoolName string) SqlPoolId { + return SqlPoolId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + WorkspaceName: workspaceName, + SqlPoolName: sqlPoolName, + } +} + +// ParseSqlPoolID parses 'input' into a SqlPoolId +func ParseSqlPoolID(input string) (*SqlPoolId, error) { + parser := resourceids.NewParserFromResourceIdType(&SqlPoolId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := SqlPoolId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseSqlPoolIDInsensitively parses 'input' case-insensitively into a SqlPoolId +// note: this method should only be used for API response data and not user input +func ParseSqlPoolIDInsensitively(input string) (*SqlPoolId, error) { + parser := resourceids.NewParserFromResourceIdType(&SqlPoolId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := SqlPoolId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *SqlPoolId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.WorkspaceName, ok = input.Parsed["workspaceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "workspaceName", input) + } + + if id.SqlPoolName, ok = input.Parsed["sqlPoolName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "sqlPoolName", input) + } + + return nil +} + +// ValidateSqlPoolID checks that 'input' can be parsed as a Sql Pool ID +func ValidateSqlPoolID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseSqlPoolID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Sql Pool ID +func (id SqlPoolId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Synapse/workspaces/%s/sqlPools/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.WorkspaceName, id.SqlPoolName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Sql Pool ID +func (id SqlPoolId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftSynapse", "Microsoft.Synapse", "Microsoft.Synapse"), + resourceids.StaticSegment("staticWorkspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceName", "workspaceValue"), + resourceids.StaticSegment("staticSqlPools", "sqlPools", "sqlPools"), + resourceids.UserSpecifiedSegment("sqlPoolName", "sqlPoolValue"), + } +} + +// String returns a human-readable description of this Sql Pool ID +func (id SqlPoolId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Workspace Name: %q", id.WorkspaceName), + fmt.Sprintf("Sql Pool Name: %q", id.SqlPoolName), + } + return fmt.Sprintf("Sql Pool (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolsrestorepoints/id_sqlpool_test.go b/resource-manager/synapse/2021-06-01/sqlpoolsrestorepoints/id_sqlpool_test.go new file mode 100644 index 00000000000..1ccdf71682d --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolsrestorepoints/id_sqlpool_test.go @@ -0,0 +1,327 @@ +package sqlpoolsrestorepoints + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &SqlPoolId{} + +func TestNewSqlPoolID(t *testing.T) { + id := NewSqlPoolID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "sqlPoolValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.WorkspaceName != "workspaceValue" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceName'", id.WorkspaceName, "workspaceValue") + } + + if id.SqlPoolName != "sqlPoolValue" { + t.Fatalf("Expected %q but got %q for Segment 'SqlPoolName'", id.SqlPoolName, "sqlPoolValue") + } +} + +func TestFormatSqlPoolID(t *testing.T) { + actual := NewSqlPoolID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "sqlPoolValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseSqlPoolID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *SqlPoolId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue", + Expected: &SqlPoolId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + SqlPoolName: "sqlPoolValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseSqlPoolID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + if actual.SqlPoolName != v.Expected.SqlPoolName { + t.Fatalf("Expected %q but got %q for SqlPoolName", v.Expected.SqlPoolName, actual.SqlPoolName) + } + + } +} + +func TestParseSqlPoolIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *SqlPoolId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/sQlPoOlS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue", + Expected: &SqlPoolId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + SqlPoolName: "sqlPoolValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/sQlPoOlS/sQlPoOlVaLuE", + Expected: &SqlPoolId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + WorkspaceName: "wOrKsPaCeVaLuE", + SqlPoolName: "sQlPoOlVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/sQlPoOlS/sQlPoOlVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseSqlPoolIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + if actual.SqlPoolName != v.Expected.SqlPoolName { + t.Fatalf("Expected %q but got %q for SqlPoolName", v.Expected.SqlPoolName, actual.SqlPoolName) + } + + } +} + +func TestSegmentsForSqlPoolId(t *testing.T) { + segments := SqlPoolId{}.Segments() + if len(segments) == 0 { + t.Fatalf("SqlPoolId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolsrestorepoints/method_sqlpoolrestorepointscreate.go b/resource-manager/synapse/2021-06-01/sqlpoolsrestorepoints/method_sqlpoolrestorepointscreate.go new file mode 100644 index 00000000000..48aa37fd79e --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolsrestorepoints/method_sqlpoolrestorepointscreate.go @@ -0,0 +1,76 @@ +package sqlpoolsrestorepoints + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SqlPoolRestorePointsCreateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *RestorePoint +} + +// SqlPoolRestorePointsCreate ... +func (c SqlPoolsRestorePointsClient) SqlPoolRestorePointsCreate(ctx context.Context, id SqlPoolId, input CreateSqlPoolRestorePointDefinition) (result SqlPoolRestorePointsCreateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/restorePoints", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// SqlPoolRestorePointsCreateThenPoll performs SqlPoolRestorePointsCreate then polls until it's completed +func (c SqlPoolsRestorePointsClient) SqlPoolRestorePointsCreateThenPoll(ctx context.Context, id SqlPoolId, input CreateSqlPoolRestorePointDefinition) error { + result, err := c.SqlPoolRestorePointsCreate(ctx, id, input) + if err != nil { + return fmt.Errorf("performing SqlPoolRestorePointsCreate: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after SqlPoolRestorePointsCreate: %+v", err) + } + + return nil +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolsrestorepoints/method_sqlpoolrestorepointsdelete.go b/resource-manager/synapse/2021-06-01/sqlpoolsrestorepoints/method_sqlpoolrestorepointsdelete.go new file mode 100644 index 00000000000..4163570a180 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolsrestorepoints/method_sqlpoolrestorepointsdelete.go @@ -0,0 +1,47 @@ +package sqlpoolsrestorepoints + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SqlPoolRestorePointsDeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// SqlPoolRestorePointsDelete ... +func (c SqlPoolsRestorePointsClient) SqlPoolRestorePointsDelete(ctx context.Context, id RestorePointId) (result SqlPoolRestorePointsDeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolsrestorepoints/method_sqlpoolrestorepointsget.go b/resource-manager/synapse/2021-06-01/sqlpoolsrestorepoints/method_sqlpoolrestorepointsget.go new file mode 100644 index 00000000000..061a7f2b246 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolsrestorepoints/method_sqlpoolrestorepointsget.go @@ -0,0 +1,51 @@ +package sqlpoolsrestorepoints + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SqlPoolRestorePointsGetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *RestorePoint +} + +// SqlPoolRestorePointsGet ... +func (c SqlPoolsRestorePointsClient) SqlPoolRestorePointsGet(ctx context.Context, id RestorePointId) (result SqlPoolRestorePointsGetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolsrestorepoints/model_createsqlpoolrestorepointdefinition.go b/resource-manager/synapse/2021-06-01/sqlpoolsrestorepoints/model_createsqlpoolrestorepointdefinition.go new file mode 100644 index 00000000000..c9fea09a427 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolsrestorepoints/model_createsqlpoolrestorepointdefinition.go @@ -0,0 +1,8 @@ +package sqlpoolsrestorepoints + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateSqlPoolRestorePointDefinition struct { + RestorePointLabel string `json:"restorePointLabel"` +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolsrestorepoints/model_restorepoint.go b/resource-manager/synapse/2021-06-01/sqlpoolsrestorepoints/model_restorepoint.go new file mode 100644 index 00000000000..b680feb431c --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolsrestorepoints/model_restorepoint.go @@ -0,0 +1,12 @@ +package sqlpoolsrestorepoints + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RestorePoint struct { + Id *string `json:"id,omitempty"` + Location *string `json:"location,omitempty"` + Name *string `json:"name,omitempty"` + Properties *RestorePointProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolsrestorepoints/model_restorepointproperties.go b/resource-manager/synapse/2021-06-01/sqlpoolsrestorepoints/model_restorepointproperties.go new file mode 100644 index 00000000000..323a3ac9f58 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolsrestorepoints/model_restorepointproperties.go @@ -0,0 +1,41 @@ +package sqlpoolsrestorepoints + +import ( + "time" + + "github.com/hashicorp/go-azure-helpers/lang/dates" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RestorePointProperties struct { + EarliestRestoreDate *string `json:"earliestRestoreDate,omitempty"` + RestorePointCreationDate *string `json:"restorePointCreationDate,omitempty"` + RestorePointLabel *string `json:"restorePointLabel,omitempty"` + RestorePointType *RestorePointType `json:"restorePointType,omitempty"` +} + +func (o *RestorePointProperties) GetEarliestRestoreDateAsTime() (*time.Time, error) { + if o.EarliestRestoreDate == nil { + return nil, nil + } + return dates.ParseAsFormat(o.EarliestRestoreDate, "2006-01-02T15:04:05Z07:00") +} + +func (o *RestorePointProperties) SetEarliestRestoreDateAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.EarliestRestoreDate = &formatted +} + +func (o *RestorePointProperties) GetRestorePointCreationDateAsTime() (*time.Time, error) { + if o.RestorePointCreationDate == nil { + return nil, nil + } + return dates.ParseAsFormat(o.RestorePointCreationDate, "2006-01-02T15:04:05Z07:00") +} + +func (o *RestorePointProperties) SetRestorePointCreationDateAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.RestorePointCreationDate = &formatted +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolsrestorepoints/version.go b/resource-manager/synapse/2021-06-01/sqlpoolsrestorepoints/version.go new file mode 100644 index 00000000000..2f7c9b49e2f --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolsrestorepoints/version.go @@ -0,0 +1,12 @@ +package sqlpoolsrestorepoints + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2021-06-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/sqlpoolsrestorepoints/%s", defaultApiVersion) +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolsschemas/README.md b/resource-manager/synapse/2021-06-01/sqlpoolsschemas/README.md new file mode 100644 index 00000000000..289a9eb192a --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolsschemas/README.md @@ -0,0 +1,71 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/synapse/2021-06-01/sqlpoolsschemas` Documentation + +The `sqlpoolsschemas` SDK allows for interaction with the Azure Resource Manager Service `synapse` (API Version `2021-06-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/synapse/2021-06-01/sqlpoolsschemas" +``` + + +### Client Initialization + +```go +client := sqlpoolsschemas.NewSqlPoolsSchemasClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `SqlPoolsSchemasClient.SqlPoolSchemasList` + +```go +ctx := context.TODO() +id := sqlpoolsschemas.NewSqlPoolID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "sqlPoolValue") + +// alternatively `client.SqlPoolSchemasList(ctx, id, sqlpoolsschemas.DefaultSqlPoolSchemasListOperationOptions())` can be used to do batched pagination +items, err := client.SqlPoolSchemasListComplete(ctx, id, sqlpoolsschemas.DefaultSqlPoolSchemasListOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `SqlPoolsSchemasClient.SqlPoolVulnerabilityAssessmentScansList` + +```go +ctx := context.TODO() +id := sqlpoolsschemas.NewSqlPoolID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "sqlPoolValue") + +// alternatively `client.SqlPoolVulnerabilityAssessmentScansList(ctx, id)` can be used to do batched pagination +items, err := client.SqlPoolVulnerabilityAssessmentScansListComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `SqlPoolsSchemasClient.SqlPoolVulnerabilityAssessmentsList` + +```go +ctx := context.TODO() +id := sqlpoolsschemas.NewSqlPoolID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "sqlPoolValue") + +// alternatively `client.SqlPoolVulnerabilityAssessmentsList(ctx, id)` can be used to do batched pagination +items, err := client.SqlPoolVulnerabilityAssessmentsListComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/synapse/2021-06-01/sqlpoolsschemas/client.go b/resource-manager/synapse/2021-06-01/sqlpoolsschemas/client.go new file mode 100644 index 00000000000..f87d75231a6 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolsschemas/client.go @@ -0,0 +1,26 @@ +package sqlpoolsschemas + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SqlPoolsSchemasClient struct { + Client *resourcemanager.Client +} + +func NewSqlPoolsSchemasClientWithBaseURI(sdkApi sdkEnv.Api) (*SqlPoolsSchemasClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "sqlpoolsschemas", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating SqlPoolsSchemasClient: %+v", err) + } + + return &SqlPoolsSchemasClient{ + Client: client, + }, nil +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolsschemas/constants.go b/resource-manager/synapse/2021-06-01/sqlpoolsschemas/constants.go new file mode 100644 index 00000000000..10f2a4ea496 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolsschemas/constants.go @@ -0,0 +1,98 @@ +package sqlpoolsschemas + +import ( + "encoding/json" + "fmt" + "strings" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type VulnerabilityAssessmentScanState string + +const ( + VulnerabilityAssessmentScanStateFailed VulnerabilityAssessmentScanState = "Failed" + VulnerabilityAssessmentScanStateFailedToRun VulnerabilityAssessmentScanState = "FailedToRun" + VulnerabilityAssessmentScanStateInProgress VulnerabilityAssessmentScanState = "InProgress" + VulnerabilityAssessmentScanStatePassed VulnerabilityAssessmentScanState = "Passed" +) + +func PossibleValuesForVulnerabilityAssessmentScanState() []string { + return []string{ + string(VulnerabilityAssessmentScanStateFailed), + string(VulnerabilityAssessmentScanStateFailedToRun), + string(VulnerabilityAssessmentScanStateInProgress), + string(VulnerabilityAssessmentScanStatePassed), + } +} + +func (s *VulnerabilityAssessmentScanState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseVulnerabilityAssessmentScanState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseVulnerabilityAssessmentScanState(input string) (*VulnerabilityAssessmentScanState, error) { + vals := map[string]VulnerabilityAssessmentScanState{ + "failed": VulnerabilityAssessmentScanStateFailed, + "failedtorun": VulnerabilityAssessmentScanStateFailedToRun, + "inprogress": VulnerabilityAssessmentScanStateInProgress, + "passed": VulnerabilityAssessmentScanStatePassed, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := VulnerabilityAssessmentScanState(input) + return &out, nil +} + +type VulnerabilityAssessmentScanTriggerType string + +const ( + VulnerabilityAssessmentScanTriggerTypeOnDemand VulnerabilityAssessmentScanTriggerType = "OnDemand" + VulnerabilityAssessmentScanTriggerTypeRecurring VulnerabilityAssessmentScanTriggerType = "Recurring" +) + +func PossibleValuesForVulnerabilityAssessmentScanTriggerType() []string { + return []string{ + string(VulnerabilityAssessmentScanTriggerTypeOnDemand), + string(VulnerabilityAssessmentScanTriggerTypeRecurring), + } +} + +func (s *VulnerabilityAssessmentScanTriggerType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseVulnerabilityAssessmentScanTriggerType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseVulnerabilityAssessmentScanTriggerType(input string) (*VulnerabilityAssessmentScanTriggerType, error) { + vals := map[string]VulnerabilityAssessmentScanTriggerType{ + "ondemand": VulnerabilityAssessmentScanTriggerTypeOnDemand, + "recurring": VulnerabilityAssessmentScanTriggerTypeRecurring, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := VulnerabilityAssessmentScanTriggerType(input) + return &out, nil +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolsschemas/id_sqlpool.go b/resource-manager/synapse/2021-06-01/sqlpoolsschemas/id_sqlpool.go new file mode 100644 index 00000000000..40c84cb6927 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolsschemas/id_sqlpool.go @@ -0,0 +1,134 @@ +package sqlpoolsschemas + +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 = &SqlPoolId{} + +// SqlPoolId is a struct representing the Resource ID for a Sql Pool +type SqlPoolId struct { + SubscriptionId string + ResourceGroupName string + WorkspaceName string + SqlPoolName string +} + +// NewSqlPoolID returns a new SqlPoolId struct +func NewSqlPoolID(subscriptionId string, resourceGroupName string, workspaceName string, sqlPoolName string) SqlPoolId { + return SqlPoolId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + WorkspaceName: workspaceName, + SqlPoolName: sqlPoolName, + } +} + +// ParseSqlPoolID parses 'input' into a SqlPoolId +func ParseSqlPoolID(input string) (*SqlPoolId, error) { + parser := resourceids.NewParserFromResourceIdType(&SqlPoolId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := SqlPoolId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseSqlPoolIDInsensitively parses 'input' case-insensitively into a SqlPoolId +// note: this method should only be used for API response data and not user input +func ParseSqlPoolIDInsensitively(input string) (*SqlPoolId, error) { + parser := resourceids.NewParserFromResourceIdType(&SqlPoolId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := SqlPoolId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *SqlPoolId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.WorkspaceName, ok = input.Parsed["workspaceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "workspaceName", input) + } + + if id.SqlPoolName, ok = input.Parsed["sqlPoolName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "sqlPoolName", input) + } + + return nil +} + +// ValidateSqlPoolID checks that 'input' can be parsed as a Sql Pool ID +func ValidateSqlPoolID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseSqlPoolID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Sql Pool ID +func (id SqlPoolId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Synapse/workspaces/%s/sqlPools/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.WorkspaceName, id.SqlPoolName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Sql Pool ID +func (id SqlPoolId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftSynapse", "Microsoft.Synapse", "Microsoft.Synapse"), + resourceids.StaticSegment("staticWorkspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceName", "workspaceValue"), + resourceids.StaticSegment("staticSqlPools", "sqlPools", "sqlPools"), + resourceids.UserSpecifiedSegment("sqlPoolName", "sqlPoolValue"), + } +} + +// String returns a human-readable description of this Sql Pool ID +func (id SqlPoolId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Workspace Name: %q", id.WorkspaceName), + fmt.Sprintf("Sql Pool Name: %q", id.SqlPoolName), + } + return fmt.Sprintf("Sql Pool (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolsschemas/id_sqlpool_test.go b/resource-manager/synapse/2021-06-01/sqlpoolsschemas/id_sqlpool_test.go new file mode 100644 index 00000000000..6579e38d73d --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolsschemas/id_sqlpool_test.go @@ -0,0 +1,327 @@ +package sqlpoolsschemas + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &SqlPoolId{} + +func TestNewSqlPoolID(t *testing.T) { + id := NewSqlPoolID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "sqlPoolValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.WorkspaceName != "workspaceValue" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceName'", id.WorkspaceName, "workspaceValue") + } + + if id.SqlPoolName != "sqlPoolValue" { + t.Fatalf("Expected %q but got %q for Segment 'SqlPoolName'", id.SqlPoolName, "sqlPoolValue") + } +} + +func TestFormatSqlPoolID(t *testing.T) { + actual := NewSqlPoolID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "sqlPoolValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseSqlPoolID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *SqlPoolId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue", + Expected: &SqlPoolId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + SqlPoolName: "sqlPoolValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseSqlPoolID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + if actual.SqlPoolName != v.Expected.SqlPoolName { + t.Fatalf("Expected %q but got %q for SqlPoolName", v.Expected.SqlPoolName, actual.SqlPoolName) + } + + } +} + +func TestParseSqlPoolIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *SqlPoolId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/sQlPoOlS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue", + Expected: &SqlPoolId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + SqlPoolName: "sqlPoolValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/sQlPoOlS/sQlPoOlVaLuE", + Expected: &SqlPoolId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + WorkspaceName: "wOrKsPaCeVaLuE", + SqlPoolName: "sQlPoOlVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/sQlPoOlS/sQlPoOlVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseSqlPoolIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + if actual.SqlPoolName != v.Expected.SqlPoolName { + t.Fatalf("Expected %q but got %q for SqlPoolName", v.Expected.SqlPoolName, actual.SqlPoolName) + } + + } +} + +func TestSegmentsForSqlPoolId(t *testing.T) { + segments := SqlPoolId{}.Segments() + if len(segments) == 0 { + t.Fatalf("SqlPoolId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolsschemas/method_sqlpoolschemaslist.go b/resource-manager/synapse/2021-06-01/sqlpoolsschemas/method_sqlpoolschemaslist.go new file mode 100644 index 00000000000..64c933d2662 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolsschemas/method_sqlpoolschemaslist.go @@ -0,0 +1,119 @@ +package sqlpoolsschemas + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SqlPoolSchemasListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]Resource +} + +type SqlPoolSchemasListCompleteResult struct { + LatestHttpResponse *http.Response + Items []Resource +} + +type SqlPoolSchemasListOperationOptions struct { + Filter *string +} + +func DefaultSqlPoolSchemasListOperationOptions() SqlPoolSchemasListOperationOptions { + return SqlPoolSchemasListOperationOptions{} +} + +func (o SqlPoolSchemasListOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o SqlPoolSchemasListOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o SqlPoolSchemasListOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + return &out +} + +// SqlPoolSchemasList ... +func (c SqlPoolsSchemasClient) SqlPoolSchemasList(ctx context.Context, id SqlPoolId, options SqlPoolSchemasListOperationOptions) (result SqlPoolSchemasListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/schemas", id.ID()), + OptionsObject: options, + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]Resource `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// SqlPoolSchemasListComplete retrieves all the results into a single object +func (c SqlPoolsSchemasClient) SqlPoolSchemasListComplete(ctx context.Context, id SqlPoolId, options SqlPoolSchemasListOperationOptions) (SqlPoolSchemasListCompleteResult, error) { + return c.SqlPoolSchemasListCompleteMatchingPredicate(ctx, id, options, ResourceOperationPredicate{}) +} + +// SqlPoolSchemasListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c SqlPoolsSchemasClient) SqlPoolSchemasListCompleteMatchingPredicate(ctx context.Context, id SqlPoolId, options SqlPoolSchemasListOperationOptions, predicate ResourceOperationPredicate) (result SqlPoolSchemasListCompleteResult, err error) { + items := make([]Resource, 0) + + resp, err := c.SqlPoolSchemasList(ctx, id, options) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = SqlPoolSchemasListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolsschemas/method_sqlpoolvulnerabilityassessmentscanslist.go b/resource-manager/synapse/2021-06-01/sqlpoolsschemas/method_sqlpoolvulnerabilityassessmentscanslist.go new file mode 100644 index 00000000000..91c6c2c0070 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolsschemas/method_sqlpoolvulnerabilityassessmentscanslist.go @@ -0,0 +1,91 @@ +package sqlpoolsschemas + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SqlPoolVulnerabilityAssessmentScansListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]VulnerabilityAssessmentScanRecord +} + +type SqlPoolVulnerabilityAssessmentScansListCompleteResult struct { + LatestHttpResponse *http.Response + Items []VulnerabilityAssessmentScanRecord +} + +// SqlPoolVulnerabilityAssessmentScansList ... +func (c SqlPoolsSchemasClient) SqlPoolVulnerabilityAssessmentScansList(ctx context.Context, id SqlPoolId) (result SqlPoolVulnerabilityAssessmentScansListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/vulnerabilityAssessments/default/scans", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]VulnerabilityAssessmentScanRecord `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// SqlPoolVulnerabilityAssessmentScansListComplete retrieves all the results into a single object +func (c SqlPoolsSchemasClient) SqlPoolVulnerabilityAssessmentScansListComplete(ctx context.Context, id SqlPoolId) (SqlPoolVulnerabilityAssessmentScansListCompleteResult, error) { + return c.SqlPoolVulnerabilityAssessmentScansListCompleteMatchingPredicate(ctx, id, VulnerabilityAssessmentScanRecordOperationPredicate{}) +} + +// SqlPoolVulnerabilityAssessmentScansListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c SqlPoolsSchemasClient) SqlPoolVulnerabilityAssessmentScansListCompleteMatchingPredicate(ctx context.Context, id SqlPoolId, predicate VulnerabilityAssessmentScanRecordOperationPredicate) (result SqlPoolVulnerabilityAssessmentScansListCompleteResult, err error) { + items := make([]VulnerabilityAssessmentScanRecord, 0) + + resp, err := c.SqlPoolVulnerabilityAssessmentScansList(ctx, id) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = SqlPoolVulnerabilityAssessmentScansListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolsschemas/method_sqlpoolvulnerabilityassessmentslist.go b/resource-manager/synapse/2021-06-01/sqlpoolsschemas/method_sqlpoolvulnerabilityassessmentslist.go new file mode 100644 index 00000000000..a68316ab10c --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolsschemas/method_sqlpoolvulnerabilityassessmentslist.go @@ -0,0 +1,91 @@ +package sqlpoolsschemas + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SqlPoolVulnerabilityAssessmentsListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]SqlPoolVulnerabilityAssessment +} + +type SqlPoolVulnerabilityAssessmentsListCompleteResult struct { + LatestHttpResponse *http.Response + Items []SqlPoolVulnerabilityAssessment +} + +// SqlPoolVulnerabilityAssessmentsList ... +func (c SqlPoolsSchemasClient) SqlPoolVulnerabilityAssessmentsList(ctx context.Context, id SqlPoolId) (result SqlPoolVulnerabilityAssessmentsListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/vulnerabilityAssessments", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]SqlPoolVulnerabilityAssessment `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// SqlPoolVulnerabilityAssessmentsListComplete retrieves all the results into a single object +func (c SqlPoolsSchemasClient) SqlPoolVulnerabilityAssessmentsListComplete(ctx context.Context, id SqlPoolId) (SqlPoolVulnerabilityAssessmentsListCompleteResult, error) { + return c.SqlPoolVulnerabilityAssessmentsListCompleteMatchingPredicate(ctx, id, SqlPoolVulnerabilityAssessmentOperationPredicate{}) +} + +// SqlPoolVulnerabilityAssessmentsListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c SqlPoolsSchemasClient) SqlPoolVulnerabilityAssessmentsListCompleteMatchingPredicate(ctx context.Context, id SqlPoolId, predicate SqlPoolVulnerabilityAssessmentOperationPredicate) (result SqlPoolVulnerabilityAssessmentsListCompleteResult, err error) { + items := make([]SqlPoolVulnerabilityAssessment, 0) + + resp, err := c.SqlPoolVulnerabilityAssessmentsList(ctx, id) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = SqlPoolVulnerabilityAssessmentsListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolsschemas/model_resource.go b/resource-manager/synapse/2021-06-01/sqlpoolsschemas/model_resource.go new file mode 100644 index 00000000000..54a75f054ff --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolsschemas/model_resource.go @@ -0,0 +1,10 @@ +package sqlpoolsschemas + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Resource struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolsschemas/model_sqlpoolvulnerabilityassessment.go b/resource-manager/synapse/2021-06-01/sqlpoolsschemas/model_sqlpoolvulnerabilityassessment.go new file mode 100644 index 00000000000..e63bfec691d --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolsschemas/model_sqlpoolvulnerabilityassessment.go @@ -0,0 +1,11 @@ +package sqlpoolsschemas + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SqlPoolVulnerabilityAssessment struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *SqlPoolVulnerabilityAssessmentProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolsschemas/model_sqlpoolvulnerabilityassessmentproperties.go b/resource-manager/synapse/2021-06-01/sqlpoolsschemas/model_sqlpoolvulnerabilityassessmentproperties.go new file mode 100644 index 00000000000..458ac3ca85a --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolsschemas/model_sqlpoolvulnerabilityassessmentproperties.go @@ -0,0 +1,11 @@ +package sqlpoolsschemas + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SqlPoolVulnerabilityAssessmentProperties struct { + RecurringScans *VulnerabilityAssessmentRecurringScansProperties `json:"recurringScans,omitempty"` + StorageAccountAccessKey *string `json:"storageAccountAccessKey,omitempty"` + StorageContainerPath *string `json:"storageContainerPath,omitempty"` + StorageContainerSasKey *string `json:"storageContainerSasKey,omitempty"` +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolsschemas/model_vulnerabilityassessmentrecurringscansproperties.go b/resource-manager/synapse/2021-06-01/sqlpoolsschemas/model_vulnerabilityassessmentrecurringscansproperties.go new file mode 100644 index 00000000000..e24a10b459d --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolsschemas/model_vulnerabilityassessmentrecurringscansproperties.go @@ -0,0 +1,10 @@ +package sqlpoolsschemas + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type VulnerabilityAssessmentRecurringScansProperties struct { + EmailSubscriptionAdmins *bool `json:"emailSubscriptionAdmins,omitempty"` + Emails *[]string `json:"emails,omitempty"` + IsEnabled *bool `json:"isEnabled,omitempty"` +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolsschemas/model_vulnerabilityassessmentscanerror.go b/resource-manager/synapse/2021-06-01/sqlpoolsschemas/model_vulnerabilityassessmentscanerror.go new file mode 100644 index 00000000000..b063c02596e --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolsschemas/model_vulnerabilityassessmentscanerror.go @@ -0,0 +1,9 @@ +package sqlpoolsschemas + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type VulnerabilityAssessmentScanError struct { + Code *string `json:"code,omitempty"` + Message *string `json:"message,omitempty"` +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolsschemas/model_vulnerabilityassessmentscanrecord.go b/resource-manager/synapse/2021-06-01/sqlpoolsschemas/model_vulnerabilityassessmentscanrecord.go new file mode 100644 index 00000000000..b44af1516ab --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolsschemas/model_vulnerabilityassessmentscanrecord.go @@ -0,0 +1,11 @@ +package sqlpoolsschemas + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type VulnerabilityAssessmentScanRecord struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *VulnerabilityAssessmentScanRecordProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolsschemas/model_vulnerabilityassessmentscanrecordproperties.go b/resource-manager/synapse/2021-06-01/sqlpoolsschemas/model_vulnerabilityassessmentscanrecordproperties.go new file mode 100644 index 00000000000..44321ae63eb --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolsschemas/model_vulnerabilityassessmentscanrecordproperties.go @@ -0,0 +1,45 @@ +package sqlpoolsschemas + +import ( + "time" + + "github.com/hashicorp/go-azure-helpers/lang/dates" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type VulnerabilityAssessmentScanRecordProperties struct { + EndTime *string `json:"endTime,omitempty"` + Errors *[]VulnerabilityAssessmentScanError `json:"errors,omitempty"` + NumberOfFailedSecurityChecks *int64 `json:"numberOfFailedSecurityChecks,omitempty"` + ScanId *string `json:"scanId,omitempty"` + StartTime *string `json:"startTime,omitempty"` + State *VulnerabilityAssessmentScanState `json:"state,omitempty"` + StorageContainerPath *string `json:"storageContainerPath,omitempty"` + TriggerType *VulnerabilityAssessmentScanTriggerType `json:"triggerType,omitempty"` +} + +func (o *VulnerabilityAssessmentScanRecordProperties) GetEndTimeAsTime() (*time.Time, error) { + if o.EndTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.EndTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *VulnerabilityAssessmentScanRecordProperties) SetEndTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.EndTime = &formatted +} + +func (o *VulnerabilityAssessmentScanRecordProperties) GetStartTimeAsTime() (*time.Time, error) { + if o.StartTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.StartTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *VulnerabilityAssessmentScanRecordProperties) SetStartTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.StartTime = &formatted +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolsschemas/predicates.go b/resource-manager/synapse/2021-06-01/sqlpoolsschemas/predicates.go new file mode 100644 index 00000000000..5457824dffa --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolsschemas/predicates.go @@ -0,0 +1,73 @@ +package sqlpoolsschemas + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ResourceOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p ResourceOperationPredicate) Matches(input Resource) bool { + + if p.Id != nil && (input.Id == nil || *p.Id != *input.Id) { + return false + } + + if p.Name != nil && (input.Name == nil || *p.Name != *input.Name) { + return false + } + + if p.Type != nil && (input.Type == nil || *p.Type != *input.Type) { + return false + } + + return true +} + +type SqlPoolVulnerabilityAssessmentOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p SqlPoolVulnerabilityAssessmentOperationPredicate) Matches(input SqlPoolVulnerabilityAssessment) bool { + + if p.Id != nil && (input.Id == nil || *p.Id != *input.Id) { + return false + } + + if p.Name != nil && (input.Name == nil || *p.Name != *input.Name) { + return false + } + + if p.Type != nil && (input.Type == nil || *p.Type != *input.Type) { + return false + } + + return true +} + +type VulnerabilityAssessmentScanRecordOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p VulnerabilityAssessmentScanRecordOperationPredicate) Matches(input VulnerabilityAssessmentScanRecord) bool { + + if p.Id != nil && (input.Id == nil || *p.Id != *input.Id) { + return false + } + + if p.Name != nil && (input.Name == nil || *p.Name != *input.Name) { + return false + } + + if p.Type != nil && (input.Type == nil || *p.Type != *input.Type) { + return false + } + + return true +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolsschemas/version.go b/resource-manager/synapse/2021-06-01/sqlpoolsschemas/version.go new file mode 100644 index 00000000000..1e65628cce0 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolsschemas/version.go @@ -0,0 +1,12 @@ +package sqlpoolsschemas + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2021-06-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/sqlpoolsschemas/%s", defaultApiVersion) +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolssecurityalertpolicies/README.md b/resource-manager/synapse/2021-06-01/sqlpoolssecurityalertpolicies/README.md new file mode 100644 index 00000000000..efd62e2eb7e --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolssecurityalertpolicies/README.md @@ -0,0 +1,74 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/synapse/2021-06-01/sqlpoolssecurityalertpolicies` Documentation + +The `sqlpoolssecurityalertpolicies` SDK allows for interaction with the Azure Resource Manager Service `synapse` (API Version `2021-06-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/synapse/2021-06-01/sqlpoolssecurityalertpolicies" +``` + + +### Client Initialization + +```go +client := sqlpoolssecurityalertpolicies.NewSqlPoolsSecurityAlertPoliciesClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `SqlPoolsSecurityAlertPoliciesClient.SqlPoolSecurityAlertPoliciesCreateOrUpdate` + +```go +ctx := context.TODO() +id := sqlpoolssecurityalertpolicies.NewSqlPoolID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "sqlPoolValue") + +payload := sqlpoolssecurityalertpolicies.SqlPoolSecurityAlertPolicy{ + // ... +} + + +read, err := client.SqlPoolSecurityAlertPoliciesCreateOrUpdate(ctx, id, payload) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `SqlPoolsSecurityAlertPoliciesClient.SqlPoolSecurityAlertPoliciesGet` + +```go +ctx := context.TODO() +id := sqlpoolssecurityalertpolicies.NewSqlPoolID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "sqlPoolValue") + +read, err := client.SqlPoolSecurityAlertPoliciesGet(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `SqlPoolsSecurityAlertPoliciesClient.SqlPoolSecurityAlertPoliciesList` + +```go +ctx := context.TODO() +id := sqlpoolssecurityalertpolicies.NewSqlPoolID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "sqlPoolValue") + +// alternatively `client.SqlPoolSecurityAlertPoliciesList(ctx, id)` can be used to do batched pagination +items, err := client.SqlPoolSecurityAlertPoliciesListComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/synapse/2021-06-01/sqlpoolssecurityalertpolicies/client.go b/resource-manager/synapse/2021-06-01/sqlpoolssecurityalertpolicies/client.go new file mode 100644 index 00000000000..5a40772b124 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolssecurityalertpolicies/client.go @@ -0,0 +1,26 @@ +package sqlpoolssecurityalertpolicies + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SqlPoolsSecurityAlertPoliciesClient struct { + Client *resourcemanager.Client +} + +func NewSqlPoolsSecurityAlertPoliciesClientWithBaseURI(sdkApi sdkEnv.Api) (*SqlPoolsSecurityAlertPoliciesClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "sqlpoolssecurityalertpolicies", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating SqlPoolsSecurityAlertPoliciesClient: %+v", err) + } + + return &SqlPoolsSecurityAlertPoliciesClient{ + Client: client, + }, nil +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolssecurityalertpolicies/constants.go b/resource-manager/synapse/2021-06-01/sqlpoolssecurityalertpolicies/constants.go new file mode 100644 index 00000000000..75e717d95fa --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolssecurityalertpolicies/constants.go @@ -0,0 +1,54 @@ +package sqlpoolssecurityalertpolicies + +import ( + "encoding/json" + "fmt" + "strings" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SecurityAlertPolicyState string + +const ( + SecurityAlertPolicyStateDisabled SecurityAlertPolicyState = "Disabled" + SecurityAlertPolicyStateEnabled SecurityAlertPolicyState = "Enabled" + SecurityAlertPolicyStateNew SecurityAlertPolicyState = "New" +) + +func PossibleValuesForSecurityAlertPolicyState() []string { + return []string{ + string(SecurityAlertPolicyStateDisabled), + string(SecurityAlertPolicyStateEnabled), + string(SecurityAlertPolicyStateNew), + } +} + +func (s *SecurityAlertPolicyState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseSecurityAlertPolicyState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseSecurityAlertPolicyState(input string) (*SecurityAlertPolicyState, error) { + vals := map[string]SecurityAlertPolicyState{ + "disabled": SecurityAlertPolicyStateDisabled, + "enabled": SecurityAlertPolicyStateEnabled, + "new": SecurityAlertPolicyStateNew, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := SecurityAlertPolicyState(input) + return &out, nil +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolssecurityalertpolicies/id_sqlpool.go b/resource-manager/synapse/2021-06-01/sqlpoolssecurityalertpolicies/id_sqlpool.go new file mode 100644 index 00000000000..688d8e235f8 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolssecurityalertpolicies/id_sqlpool.go @@ -0,0 +1,134 @@ +package sqlpoolssecurityalertpolicies + +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 = &SqlPoolId{} + +// SqlPoolId is a struct representing the Resource ID for a Sql Pool +type SqlPoolId struct { + SubscriptionId string + ResourceGroupName string + WorkspaceName string + SqlPoolName string +} + +// NewSqlPoolID returns a new SqlPoolId struct +func NewSqlPoolID(subscriptionId string, resourceGroupName string, workspaceName string, sqlPoolName string) SqlPoolId { + return SqlPoolId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + WorkspaceName: workspaceName, + SqlPoolName: sqlPoolName, + } +} + +// ParseSqlPoolID parses 'input' into a SqlPoolId +func ParseSqlPoolID(input string) (*SqlPoolId, error) { + parser := resourceids.NewParserFromResourceIdType(&SqlPoolId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := SqlPoolId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseSqlPoolIDInsensitively parses 'input' case-insensitively into a SqlPoolId +// note: this method should only be used for API response data and not user input +func ParseSqlPoolIDInsensitively(input string) (*SqlPoolId, error) { + parser := resourceids.NewParserFromResourceIdType(&SqlPoolId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := SqlPoolId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *SqlPoolId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.WorkspaceName, ok = input.Parsed["workspaceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "workspaceName", input) + } + + if id.SqlPoolName, ok = input.Parsed["sqlPoolName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "sqlPoolName", input) + } + + return nil +} + +// ValidateSqlPoolID checks that 'input' can be parsed as a Sql Pool ID +func ValidateSqlPoolID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseSqlPoolID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Sql Pool ID +func (id SqlPoolId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Synapse/workspaces/%s/sqlPools/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.WorkspaceName, id.SqlPoolName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Sql Pool ID +func (id SqlPoolId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftSynapse", "Microsoft.Synapse", "Microsoft.Synapse"), + resourceids.StaticSegment("staticWorkspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceName", "workspaceValue"), + resourceids.StaticSegment("staticSqlPools", "sqlPools", "sqlPools"), + resourceids.UserSpecifiedSegment("sqlPoolName", "sqlPoolValue"), + } +} + +// String returns a human-readable description of this Sql Pool ID +func (id SqlPoolId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Workspace Name: %q", id.WorkspaceName), + fmt.Sprintf("Sql Pool Name: %q", id.SqlPoolName), + } + return fmt.Sprintf("Sql Pool (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolssecurityalertpolicies/id_sqlpool_test.go b/resource-manager/synapse/2021-06-01/sqlpoolssecurityalertpolicies/id_sqlpool_test.go new file mode 100644 index 00000000000..e15e51a5468 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolssecurityalertpolicies/id_sqlpool_test.go @@ -0,0 +1,327 @@ +package sqlpoolssecurityalertpolicies + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &SqlPoolId{} + +func TestNewSqlPoolID(t *testing.T) { + id := NewSqlPoolID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "sqlPoolValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.WorkspaceName != "workspaceValue" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceName'", id.WorkspaceName, "workspaceValue") + } + + if id.SqlPoolName != "sqlPoolValue" { + t.Fatalf("Expected %q but got %q for Segment 'SqlPoolName'", id.SqlPoolName, "sqlPoolValue") + } +} + +func TestFormatSqlPoolID(t *testing.T) { + actual := NewSqlPoolID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "sqlPoolValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseSqlPoolID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *SqlPoolId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue", + Expected: &SqlPoolId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + SqlPoolName: "sqlPoolValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseSqlPoolID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + if actual.SqlPoolName != v.Expected.SqlPoolName { + t.Fatalf("Expected %q but got %q for SqlPoolName", v.Expected.SqlPoolName, actual.SqlPoolName) + } + + } +} + +func TestParseSqlPoolIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *SqlPoolId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/sQlPoOlS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue", + Expected: &SqlPoolId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + SqlPoolName: "sqlPoolValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/sQlPoOlS/sQlPoOlVaLuE", + Expected: &SqlPoolId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + WorkspaceName: "wOrKsPaCeVaLuE", + SqlPoolName: "sQlPoOlVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/sQlPoOlS/sQlPoOlVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseSqlPoolIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + if actual.SqlPoolName != v.Expected.SqlPoolName { + t.Fatalf("Expected %q but got %q for SqlPoolName", v.Expected.SqlPoolName, actual.SqlPoolName) + } + + } +} + +func TestSegmentsForSqlPoolId(t *testing.T) { + segments := SqlPoolId{}.Segments() + if len(segments) == 0 { + t.Fatalf("SqlPoolId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolssecurityalertpolicies/method_sqlpoolsecurityalertpoliciescreateorupdate.go b/resource-manager/synapse/2021-06-01/sqlpoolssecurityalertpolicies/method_sqlpoolsecurityalertpoliciescreateorupdate.go new file mode 100644 index 00000000000..6b38908f54b --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolssecurityalertpolicies/method_sqlpoolsecurityalertpoliciescreateorupdate.go @@ -0,0 +1,57 @@ +package sqlpoolssecurityalertpolicies + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SqlPoolSecurityAlertPoliciesCreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *SqlPoolSecurityAlertPolicy +} + +// SqlPoolSecurityAlertPoliciesCreateOrUpdate ... +func (c SqlPoolsSecurityAlertPoliciesClient) SqlPoolSecurityAlertPoliciesCreateOrUpdate(ctx context.Context, id SqlPoolId, input SqlPoolSecurityAlertPolicy) (result SqlPoolSecurityAlertPoliciesCreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: fmt.Sprintf("%s/securityAlertPolicies/default", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolssecurityalertpolicies/method_sqlpoolsecurityalertpoliciesget.go b/resource-manager/synapse/2021-06-01/sqlpoolssecurityalertpolicies/method_sqlpoolsecurityalertpoliciesget.go new file mode 100644 index 00000000000..488ccd2cc1a --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolssecurityalertpolicies/method_sqlpoolsecurityalertpoliciesget.go @@ -0,0 +1,52 @@ +package sqlpoolssecurityalertpolicies + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SqlPoolSecurityAlertPoliciesGetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *SqlPoolSecurityAlertPolicy +} + +// SqlPoolSecurityAlertPoliciesGet ... +func (c SqlPoolsSecurityAlertPoliciesClient) SqlPoolSecurityAlertPoliciesGet(ctx context.Context, id SqlPoolId) (result SqlPoolSecurityAlertPoliciesGetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/securityAlertPolicies/default", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolssecurityalertpolicies/method_sqlpoolsecurityalertpolicieslist.go b/resource-manager/synapse/2021-06-01/sqlpoolssecurityalertpolicies/method_sqlpoolsecurityalertpolicieslist.go new file mode 100644 index 00000000000..e2b4aefa60e --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolssecurityalertpolicies/method_sqlpoolsecurityalertpolicieslist.go @@ -0,0 +1,91 @@ +package sqlpoolssecurityalertpolicies + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SqlPoolSecurityAlertPoliciesListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]SqlPoolSecurityAlertPolicy +} + +type SqlPoolSecurityAlertPoliciesListCompleteResult struct { + LatestHttpResponse *http.Response + Items []SqlPoolSecurityAlertPolicy +} + +// SqlPoolSecurityAlertPoliciesList ... +func (c SqlPoolsSecurityAlertPoliciesClient) SqlPoolSecurityAlertPoliciesList(ctx context.Context, id SqlPoolId) (result SqlPoolSecurityAlertPoliciesListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/securityAlertPolicies", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]SqlPoolSecurityAlertPolicy `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// SqlPoolSecurityAlertPoliciesListComplete retrieves all the results into a single object +func (c SqlPoolsSecurityAlertPoliciesClient) SqlPoolSecurityAlertPoliciesListComplete(ctx context.Context, id SqlPoolId) (SqlPoolSecurityAlertPoliciesListCompleteResult, error) { + return c.SqlPoolSecurityAlertPoliciesListCompleteMatchingPredicate(ctx, id, SqlPoolSecurityAlertPolicyOperationPredicate{}) +} + +// SqlPoolSecurityAlertPoliciesListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c SqlPoolsSecurityAlertPoliciesClient) SqlPoolSecurityAlertPoliciesListCompleteMatchingPredicate(ctx context.Context, id SqlPoolId, predicate SqlPoolSecurityAlertPolicyOperationPredicate) (result SqlPoolSecurityAlertPoliciesListCompleteResult, err error) { + items := make([]SqlPoolSecurityAlertPolicy, 0) + + resp, err := c.SqlPoolSecurityAlertPoliciesList(ctx, id) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = SqlPoolSecurityAlertPoliciesListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolssecurityalertpolicies/model_securityalertpolicyproperties.go b/resource-manager/synapse/2021-06-01/sqlpoolssecurityalertpolicies/model_securityalertpolicyproperties.go new file mode 100644 index 00000000000..dfecb80e77a --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolssecurityalertpolicies/model_securityalertpolicyproperties.go @@ -0,0 +1,33 @@ +package sqlpoolssecurityalertpolicies + +import ( + "time" + + "github.com/hashicorp/go-azure-helpers/lang/dates" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SecurityAlertPolicyProperties struct { + CreationTime *string `json:"creationTime,omitempty"` + DisabledAlerts *[]string `json:"disabledAlerts,omitempty"` + EmailAccountAdmins *bool `json:"emailAccountAdmins,omitempty"` + EmailAddresses *[]string `json:"emailAddresses,omitempty"` + RetentionDays *int64 `json:"retentionDays,omitempty"` + State SecurityAlertPolicyState `json:"state"` + StorageAccountAccessKey *string `json:"storageAccountAccessKey,omitempty"` + StorageEndpoint *string `json:"storageEndpoint,omitempty"` +} + +func (o *SecurityAlertPolicyProperties) GetCreationTimeAsTime() (*time.Time, error) { + if o.CreationTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.CreationTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *SecurityAlertPolicyProperties) SetCreationTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.CreationTime = &formatted +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolssecurityalertpolicies/model_sqlpoolsecurityalertpolicy.go b/resource-manager/synapse/2021-06-01/sqlpoolssecurityalertpolicies/model_sqlpoolsecurityalertpolicy.go new file mode 100644 index 00000000000..f3cf960f121 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolssecurityalertpolicies/model_sqlpoolsecurityalertpolicy.go @@ -0,0 +1,11 @@ +package sqlpoolssecurityalertpolicies + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SqlPoolSecurityAlertPolicy struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *SecurityAlertPolicyProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolssecurityalertpolicies/predicates.go b/resource-manager/synapse/2021-06-01/sqlpoolssecurityalertpolicies/predicates.go new file mode 100644 index 00000000000..64180ab5ef9 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolssecurityalertpolicies/predicates.go @@ -0,0 +1,27 @@ +package sqlpoolssecurityalertpolicies + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SqlPoolSecurityAlertPolicyOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p SqlPoolSecurityAlertPolicyOperationPredicate) Matches(input SqlPoolSecurityAlertPolicy) bool { + + if p.Id != nil && (input.Id == nil || *p.Id != *input.Id) { + return false + } + + if p.Name != nil && (input.Name == nil || *p.Name != *input.Name) { + return false + } + + if p.Type != nil && (input.Type == nil || *p.Type != *input.Type) { + return false + } + + return true +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolssecurityalertpolicies/version.go b/resource-manager/synapse/2021-06-01/sqlpoolssecurityalertpolicies/version.go new file mode 100644 index 00000000000..3f92aceccd7 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolssecurityalertpolicies/version.go @@ -0,0 +1,12 @@ +package sqlpoolssecurityalertpolicies + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2021-06-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/sqlpoolssecurityalertpolicies/%s", defaultApiVersion) +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolssensitivitylabels/README.md b/resource-manager/synapse/2021-06-01/sqlpoolssensitivitylabels/README.md new file mode 100644 index 00000000000..8d7a79e9de8 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolssensitivitylabels/README.md @@ -0,0 +1,149 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/synapse/2021-06-01/sqlpoolssensitivitylabels` Documentation + +The `sqlpoolssensitivitylabels` SDK allows for interaction with the Azure Resource Manager Service `synapse` (API Version `2021-06-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/synapse/2021-06-01/sqlpoolssensitivitylabels" +``` + + +### Client Initialization + +```go +client := sqlpoolssensitivitylabels.NewSqlPoolsSensitivityLabelsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `SqlPoolsSensitivityLabelsClient.SqlPoolRecommendedSensitivityLabelsUpdate` + +```go +ctx := context.TODO() +id := sqlpoolssensitivitylabels.NewSqlPoolID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "sqlPoolValue") + +payload := sqlpoolssensitivitylabels.RecommendedSensitivityLabelUpdateList{ + // ... +} + + +read, err := client.SqlPoolRecommendedSensitivityLabelsUpdate(ctx, id, payload) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `SqlPoolsSensitivityLabelsClient.SqlPoolSensitivityLabelsCreateOrUpdate` + +```go +ctx := context.TODO() +id := sqlpoolssensitivitylabels.NewColumnID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "sqlPoolValue", "schemaValue", "tableValue", "columnValue") + +payload := sqlpoolssensitivitylabels.SensitivityLabel{ + // ... +} + + +read, err := client.SqlPoolSensitivityLabelsCreateOrUpdate(ctx, id, payload) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `SqlPoolsSensitivityLabelsClient.SqlPoolSensitivityLabelsDelete` + +```go +ctx := context.TODO() +id := sqlpoolssensitivitylabels.NewColumnID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "sqlPoolValue", "schemaValue", "tableValue", "columnValue") + +read, err := client.SqlPoolSensitivityLabelsDelete(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `SqlPoolsSensitivityLabelsClient.SqlPoolSensitivityLabelsGet` + +```go +ctx := context.TODO() +id := sqlpoolssensitivitylabels.NewSensitivityLabelSourceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "sqlPoolValue", "schemaValue", "tableValue", "columnValue", "current") + +read, err := client.SqlPoolSensitivityLabelsGet(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `SqlPoolsSensitivityLabelsClient.SqlPoolSensitivityLabelsListCurrent` + +```go +ctx := context.TODO() +id := sqlpoolssensitivitylabels.NewSqlPoolID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "sqlPoolValue") + +// alternatively `client.SqlPoolSensitivityLabelsListCurrent(ctx, id, sqlpoolssensitivitylabels.DefaultSqlPoolSensitivityLabelsListCurrentOperationOptions())` can be used to do batched pagination +items, err := client.SqlPoolSensitivityLabelsListCurrentComplete(ctx, id, sqlpoolssensitivitylabels.DefaultSqlPoolSensitivityLabelsListCurrentOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `SqlPoolsSensitivityLabelsClient.SqlPoolSensitivityLabelsListRecommended` + +```go +ctx := context.TODO() +id := sqlpoolssensitivitylabels.NewSqlPoolID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "sqlPoolValue") + +// alternatively `client.SqlPoolSensitivityLabelsListRecommended(ctx, id, sqlpoolssensitivitylabels.DefaultSqlPoolSensitivityLabelsListRecommendedOperationOptions())` can be used to do batched pagination +items, err := client.SqlPoolSensitivityLabelsListRecommendedComplete(ctx, id, sqlpoolssensitivitylabels.DefaultSqlPoolSensitivityLabelsListRecommendedOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `SqlPoolsSensitivityLabelsClient.SqlPoolSensitivityLabelsUpdate` + +```go +ctx := context.TODO() +id := sqlpoolssensitivitylabels.NewSqlPoolID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "sqlPoolValue") + +payload := sqlpoolssensitivitylabels.SensitivityLabelUpdateList{ + // ... +} + + +read, err := client.SqlPoolSensitivityLabelsUpdate(ctx, id, payload) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` diff --git a/resource-manager/synapse/2021-06-01/sqlpoolssensitivitylabels/client.go b/resource-manager/synapse/2021-06-01/sqlpoolssensitivitylabels/client.go new file mode 100644 index 00000000000..de6d3b3341b --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolssensitivitylabels/client.go @@ -0,0 +1,26 @@ +package sqlpoolssensitivitylabels + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SqlPoolsSensitivityLabelsClient struct { + Client *resourcemanager.Client +} + +func NewSqlPoolsSensitivityLabelsClientWithBaseURI(sdkApi sdkEnv.Api) (*SqlPoolsSensitivityLabelsClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "sqlpoolssensitivitylabels", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating SqlPoolsSensitivityLabelsClient: %+v", err) + } + + return &SqlPoolsSensitivityLabelsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolssensitivitylabels/constants.go b/resource-manager/synapse/2021-06-01/sqlpoolssensitivitylabels/constants.go new file mode 100644 index 00000000000..e40e77d8943 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolssensitivitylabels/constants.go @@ -0,0 +1,183 @@ +package sqlpoolssensitivitylabels + +import ( + "encoding/json" + "fmt" + "strings" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RecommendedSensitivityLabelUpdateKind string + +const ( + RecommendedSensitivityLabelUpdateKindDisable RecommendedSensitivityLabelUpdateKind = "disable" + RecommendedSensitivityLabelUpdateKindEnable RecommendedSensitivityLabelUpdateKind = "enable" +) + +func PossibleValuesForRecommendedSensitivityLabelUpdateKind() []string { + return []string{ + string(RecommendedSensitivityLabelUpdateKindDisable), + string(RecommendedSensitivityLabelUpdateKindEnable), + } +} + +func (s *RecommendedSensitivityLabelUpdateKind) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseRecommendedSensitivityLabelUpdateKind(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseRecommendedSensitivityLabelUpdateKind(input string) (*RecommendedSensitivityLabelUpdateKind, error) { + vals := map[string]RecommendedSensitivityLabelUpdateKind{ + "disable": RecommendedSensitivityLabelUpdateKindDisable, + "enable": RecommendedSensitivityLabelUpdateKindEnable, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := RecommendedSensitivityLabelUpdateKind(input) + return &out, nil +} + +type SensitivityLabelRank string + +const ( + SensitivityLabelRankCritical SensitivityLabelRank = "Critical" + SensitivityLabelRankHigh SensitivityLabelRank = "High" + SensitivityLabelRankLow SensitivityLabelRank = "Low" + SensitivityLabelRankMedium SensitivityLabelRank = "Medium" + SensitivityLabelRankNone SensitivityLabelRank = "None" +) + +func PossibleValuesForSensitivityLabelRank() []string { + return []string{ + string(SensitivityLabelRankCritical), + string(SensitivityLabelRankHigh), + string(SensitivityLabelRankLow), + string(SensitivityLabelRankMedium), + string(SensitivityLabelRankNone), + } +} + +func (s *SensitivityLabelRank) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseSensitivityLabelRank(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseSensitivityLabelRank(input string) (*SensitivityLabelRank, error) { + vals := map[string]SensitivityLabelRank{ + "critical": SensitivityLabelRankCritical, + "high": SensitivityLabelRankHigh, + "low": SensitivityLabelRankLow, + "medium": SensitivityLabelRankMedium, + "none": SensitivityLabelRankNone, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := SensitivityLabelRank(input) + return &out, nil +} + +type SensitivityLabelSource string + +const ( + SensitivityLabelSourceCurrent SensitivityLabelSource = "current" + SensitivityLabelSourceRecommended SensitivityLabelSource = "recommended" +) + +func PossibleValuesForSensitivityLabelSource() []string { + return []string{ + string(SensitivityLabelSourceCurrent), + string(SensitivityLabelSourceRecommended), + } +} + +func (s *SensitivityLabelSource) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseSensitivityLabelSource(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseSensitivityLabelSource(input string) (*SensitivityLabelSource, error) { + vals := map[string]SensitivityLabelSource{ + "current": SensitivityLabelSourceCurrent, + "recommended": SensitivityLabelSourceRecommended, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := SensitivityLabelSource(input) + return &out, nil +} + +type SensitivityLabelUpdateKind string + +const ( + SensitivityLabelUpdateKindRemove SensitivityLabelUpdateKind = "remove" + SensitivityLabelUpdateKindSet SensitivityLabelUpdateKind = "set" +) + +func PossibleValuesForSensitivityLabelUpdateKind() []string { + return []string{ + string(SensitivityLabelUpdateKindRemove), + string(SensitivityLabelUpdateKindSet), + } +} + +func (s *SensitivityLabelUpdateKind) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseSensitivityLabelUpdateKind(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseSensitivityLabelUpdateKind(input string) (*SensitivityLabelUpdateKind, error) { + vals := map[string]SensitivityLabelUpdateKind{ + "remove": SensitivityLabelUpdateKindRemove, + "set": SensitivityLabelUpdateKindSet, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := SensitivityLabelUpdateKind(input) + return &out, nil +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolssensitivitylabels/id_column.go b/resource-manager/synapse/2021-06-01/sqlpoolssensitivitylabels/id_column.go new file mode 100644 index 00000000000..b2a62f43a95 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolssensitivitylabels/id_column.go @@ -0,0 +1,161 @@ +package sqlpoolssensitivitylabels + +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 = &ColumnId{} + +// ColumnId is a struct representing the Resource ID for a Column +type ColumnId struct { + SubscriptionId string + ResourceGroupName string + WorkspaceName string + SqlPoolName string + SchemaName string + TableName string + ColumnName string +} + +// NewColumnID returns a new ColumnId struct +func NewColumnID(subscriptionId string, resourceGroupName string, workspaceName string, sqlPoolName string, schemaName string, tableName string, columnName string) ColumnId { + return ColumnId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + WorkspaceName: workspaceName, + SqlPoolName: sqlPoolName, + SchemaName: schemaName, + TableName: tableName, + ColumnName: columnName, + } +} + +// ParseColumnID parses 'input' into a ColumnId +func ParseColumnID(input string) (*ColumnId, error) { + parser := resourceids.NewParserFromResourceIdType(&ColumnId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ColumnId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseColumnIDInsensitively parses 'input' case-insensitively into a ColumnId +// note: this method should only be used for API response data and not user input +func ParseColumnIDInsensitively(input string) (*ColumnId, error) { + parser := resourceids.NewParserFromResourceIdType(&ColumnId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ColumnId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ColumnId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.WorkspaceName, ok = input.Parsed["workspaceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "workspaceName", input) + } + + if id.SqlPoolName, ok = input.Parsed["sqlPoolName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "sqlPoolName", input) + } + + if id.SchemaName, ok = input.Parsed["schemaName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "schemaName", input) + } + + if id.TableName, ok = input.Parsed["tableName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "tableName", input) + } + + if id.ColumnName, ok = input.Parsed["columnName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "columnName", input) + } + + return nil +} + +// ValidateColumnID checks that 'input' can be parsed as a Column ID +func ValidateColumnID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseColumnID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Column ID +func (id ColumnId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Synapse/workspaces/%s/sqlPools/%s/schemas/%s/tables/%s/columns/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.WorkspaceName, id.SqlPoolName, id.SchemaName, id.TableName, id.ColumnName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Column ID +func (id ColumnId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftSynapse", "Microsoft.Synapse", "Microsoft.Synapse"), + resourceids.StaticSegment("staticWorkspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceName", "workspaceValue"), + resourceids.StaticSegment("staticSqlPools", "sqlPools", "sqlPools"), + resourceids.UserSpecifiedSegment("sqlPoolName", "sqlPoolValue"), + resourceids.StaticSegment("staticSchemas", "schemas", "schemas"), + resourceids.UserSpecifiedSegment("schemaName", "schemaValue"), + resourceids.StaticSegment("staticTables", "tables", "tables"), + resourceids.UserSpecifiedSegment("tableName", "tableValue"), + resourceids.StaticSegment("staticColumns", "columns", "columns"), + resourceids.UserSpecifiedSegment("columnName", "columnValue"), + } +} + +// String returns a human-readable description of this Column ID +func (id ColumnId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Workspace Name: %q", id.WorkspaceName), + fmt.Sprintf("Sql Pool Name: %q", id.SqlPoolName), + fmt.Sprintf("Schema Name: %q", id.SchemaName), + fmt.Sprintf("Table Name: %q", id.TableName), + fmt.Sprintf("Column Name: %q", id.ColumnName), + } + return fmt.Sprintf("Column (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolssensitivitylabels/id_column_test.go b/resource-manager/synapse/2021-06-01/sqlpoolssensitivitylabels/id_column_test.go new file mode 100644 index 00000000000..0f3ff49fd1e --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolssensitivitylabels/id_column_test.go @@ -0,0 +1,462 @@ +package sqlpoolssensitivitylabels + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &ColumnId{} + +func TestNewColumnID(t *testing.T) { + id := NewColumnID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "sqlPoolValue", "schemaValue", "tableValue", "columnValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.WorkspaceName != "workspaceValue" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceName'", id.WorkspaceName, "workspaceValue") + } + + if id.SqlPoolName != "sqlPoolValue" { + t.Fatalf("Expected %q but got %q for Segment 'SqlPoolName'", id.SqlPoolName, "sqlPoolValue") + } + + if id.SchemaName != "schemaValue" { + t.Fatalf("Expected %q but got %q for Segment 'SchemaName'", id.SchemaName, "schemaValue") + } + + if id.TableName != "tableValue" { + t.Fatalf("Expected %q but got %q for Segment 'TableName'", id.TableName, "tableValue") + } + + if id.ColumnName != "columnValue" { + t.Fatalf("Expected %q but got %q for Segment 'ColumnName'", id.ColumnName, "columnValue") + } +} + +func TestFormatColumnID(t *testing.T) { + actual := NewColumnID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "sqlPoolValue", "schemaValue", "tableValue", "columnValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/schemas/schemaValue/tables/tableValue/columns/columnValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseColumnID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ColumnId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/schemas", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/schemas/schemaValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/schemas/schemaValue/tables", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/schemas/schemaValue/tables/tableValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/schemas/schemaValue/tables/tableValue/columns", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/schemas/schemaValue/tables/tableValue/columns/columnValue", + Expected: &ColumnId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + SqlPoolName: "sqlPoolValue", + SchemaName: "schemaValue", + TableName: "tableValue", + ColumnName: "columnValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/schemas/schemaValue/tables/tableValue/columns/columnValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseColumnID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + if actual.SqlPoolName != v.Expected.SqlPoolName { + t.Fatalf("Expected %q but got %q for SqlPoolName", v.Expected.SqlPoolName, actual.SqlPoolName) + } + + if actual.SchemaName != v.Expected.SchemaName { + t.Fatalf("Expected %q but got %q for SchemaName", v.Expected.SchemaName, actual.SchemaName) + } + + if actual.TableName != v.Expected.TableName { + t.Fatalf("Expected %q but got %q for TableName", v.Expected.TableName, actual.TableName) + } + + if actual.ColumnName != v.Expected.ColumnName { + t.Fatalf("Expected %q but got %q for ColumnName", v.Expected.ColumnName, actual.ColumnName) + } + + } +} + +func TestParseColumnIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ColumnId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/sQlPoOlS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/sQlPoOlS/sQlPoOlVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/schemas", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/sQlPoOlS/sQlPoOlVaLuE/sChEmAs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/schemas/schemaValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/sQlPoOlS/sQlPoOlVaLuE/sChEmAs/sChEmAvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/schemas/schemaValue/tables", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/sQlPoOlS/sQlPoOlVaLuE/sChEmAs/sChEmAvAlUe/tAbLeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/schemas/schemaValue/tables/tableValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/sQlPoOlS/sQlPoOlVaLuE/sChEmAs/sChEmAvAlUe/tAbLeS/tAbLeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/schemas/schemaValue/tables/tableValue/columns", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/sQlPoOlS/sQlPoOlVaLuE/sChEmAs/sChEmAvAlUe/tAbLeS/tAbLeVaLuE/cOlUmNs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/schemas/schemaValue/tables/tableValue/columns/columnValue", + Expected: &ColumnId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + SqlPoolName: "sqlPoolValue", + SchemaName: "schemaValue", + TableName: "tableValue", + ColumnName: "columnValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/schemas/schemaValue/tables/tableValue/columns/columnValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/sQlPoOlS/sQlPoOlVaLuE/sChEmAs/sChEmAvAlUe/tAbLeS/tAbLeVaLuE/cOlUmNs/cOlUmNvAlUe", + Expected: &ColumnId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + WorkspaceName: "wOrKsPaCeVaLuE", + SqlPoolName: "sQlPoOlVaLuE", + SchemaName: "sChEmAvAlUe", + TableName: "tAbLeVaLuE", + ColumnName: "cOlUmNvAlUe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/sQlPoOlS/sQlPoOlVaLuE/sChEmAs/sChEmAvAlUe/tAbLeS/tAbLeVaLuE/cOlUmNs/cOlUmNvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseColumnIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + if actual.SqlPoolName != v.Expected.SqlPoolName { + t.Fatalf("Expected %q but got %q for SqlPoolName", v.Expected.SqlPoolName, actual.SqlPoolName) + } + + if actual.SchemaName != v.Expected.SchemaName { + t.Fatalf("Expected %q but got %q for SchemaName", v.Expected.SchemaName, actual.SchemaName) + } + + if actual.TableName != v.Expected.TableName { + t.Fatalf("Expected %q but got %q for TableName", v.Expected.TableName, actual.TableName) + } + + if actual.ColumnName != v.Expected.ColumnName { + t.Fatalf("Expected %q but got %q for ColumnName", v.Expected.ColumnName, actual.ColumnName) + } + + } +} + +func TestSegmentsForColumnId(t *testing.T) { + segments := ColumnId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ColumnId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolssensitivitylabels/id_sensitivitylabelsource.go b/resource-manager/synapse/2021-06-01/sqlpoolssensitivitylabels/id_sensitivitylabelsource.go new file mode 100644 index 00000000000..be84e6c95c7 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolssensitivitylabels/id_sensitivitylabelsource.go @@ -0,0 +1,178 @@ +package sqlpoolssensitivitylabels + +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 = &SensitivityLabelSourceId{} + +// SensitivityLabelSourceId is a struct representing the Resource ID for a Sensitivity Label Source +type SensitivityLabelSourceId struct { + SubscriptionId string + ResourceGroupName string + WorkspaceName string + SqlPoolName string + SchemaName string + TableName string + ColumnName string + SensitivityLabelSource SensitivityLabelSource +} + +// NewSensitivityLabelSourceID returns a new SensitivityLabelSourceId struct +func NewSensitivityLabelSourceID(subscriptionId string, resourceGroupName string, workspaceName string, sqlPoolName string, schemaName string, tableName string, columnName string, sensitivityLabelSource SensitivityLabelSource) SensitivityLabelSourceId { + return SensitivityLabelSourceId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + WorkspaceName: workspaceName, + SqlPoolName: sqlPoolName, + SchemaName: schemaName, + TableName: tableName, + ColumnName: columnName, + SensitivityLabelSource: sensitivityLabelSource, + } +} + +// ParseSensitivityLabelSourceID parses 'input' into a SensitivityLabelSourceId +func ParseSensitivityLabelSourceID(input string) (*SensitivityLabelSourceId, error) { + parser := resourceids.NewParserFromResourceIdType(&SensitivityLabelSourceId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := SensitivityLabelSourceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseSensitivityLabelSourceIDInsensitively parses 'input' case-insensitively into a SensitivityLabelSourceId +// note: this method should only be used for API response data and not user input +func ParseSensitivityLabelSourceIDInsensitively(input string) (*SensitivityLabelSourceId, error) { + parser := resourceids.NewParserFromResourceIdType(&SensitivityLabelSourceId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := SensitivityLabelSourceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *SensitivityLabelSourceId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.WorkspaceName, ok = input.Parsed["workspaceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "workspaceName", input) + } + + if id.SqlPoolName, ok = input.Parsed["sqlPoolName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "sqlPoolName", input) + } + + if id.SchemaName, ok = input.Parsed["schemaName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "schemaName", input) + } + + if id.TableName, ok = input.Parsed["tableName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "tableName", input) + } + + if id.ColumnName, ok = input.Parsed["columnName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "columnName", input) + } + + if v, ok := input.Parsed["sensitivityLabelSource"]; true { + if !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "sensitivityLabelSource", input) + } + + sensitivityLabelSource, err := parseSensitivityLabelSource(v) + if err != nil { + return fmt.Errorf("parsing %q: %+v", v, err) + } + id.SensitivityLabelSource = *sensitivityLabelSource + } + + return nil +} + +// ValidateSensitivityLabelSourceID checks that 'input' can be parsed as a Sensitivity Label Source ID +func ValidateSensitivityLabelSourceID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseSensitivityLabelSourceID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Sensitivity Label Source ID +func (id SensitivityLabelSourceId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Synapse/workspaces/%s/sqlPools/%s/schemas/%s/tables/%s/columns/%s/sensitivityLabels/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.WorkspaceName, id.SqlPoolName, id.SchemaName, id.TableName, id.ColumnName, string(id.SensitivityLabelSource)) +} + +// Segments returns a slice of Resource ID Segments which comprise this Sensitivity Label Source ID +func (id SensitivityLabelSourceId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftSynapse", "Microsoft.Synapse", "Microsoft.Synapse"), + resourceids.StaticSegment("staticWorkspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceName", "workspaceValue"), + resourceids.StaticSegment("staticSqlPools", "sqlPools", "sqlPools"), + resourceids.UserSpecifiedSegment("sqlPoolName", "sqlPoolValue"), + resourceids.StaticSegment("staticSchemas", "schemas", "schemas"), + resourceids.UserSpecifiedSegment("schemaName", "schemaValue"), + resourceids.StaticSegment("staticTables", "tables", "tables"), + resourceids.UserSpecifiedSegment("tableName", "tableValue"), + resourceids.StaticSegment("staticColumns", "columns", "columns"), + resourceids.UserSpecifiedSegment("columnName", "columnValue"), + resourceids.StaticSegment("staticSensitivityLabels", "sensitivityLabels", "sensitivityLabels"), + resourceids.ConstantSegment("sensitivityLabelSource", PossibleValuesForSensitivityLabelSource(), "current"), + } +} + +// String returns a human-readable description of this Sensitivity Label Source ID +func (id SensitivityLabelSourceId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Workspace Name: %q", id.WorkspaceName), + fmt.Sprintf("Sql Pool Name: %q", id.SqlPoolName), + fmt.Sprintf("Schema Name: %q", id.SchemaName), + fmt.Sprintf("Table Name: %q", id.TableName), + fmt.Sprintf("Column Name: %q", id.ColumnName), + fmt.Sprintf("Sensitivity Label Source: %q", string(id.SensitivityLabelSource)), + } + return fmt.Sprintf("Sensitivity Label Source (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolssensitivitylabels/id_sensitivitylabelsource_test.go b/resource-manager/synapse/2021-06-01/sqlpoolssensitivitylabels/id_sensitivitylabelsource_test.go new file mode 100644 index 00000000000..7dd59ee871a --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolssensitivitylabels/id_sensitivitylabelsource_test.go @@ -0,0 +1,507 @@ +package sqlpoolssensitivitylabels + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &SensitivityLabelSourceId{} + +func TestNewSensitivityLabelSourceID(t *testing.T) { + id := NewSensitivityLabelSourceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "sqlPoolValue", "schemaValue", "tableValue", "columnValue", "current") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.WorkspaceName != "workspaceValue" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceName'", id.WorkspaceName, "workspaceValue") + } + + if id.SqlPoolName != "sqlPoolValue" { + t.Fatalf("Expected %q but got %q for Segment 'SqlPoolName'", id.SqlPoolName, "sqlPoolValue") + } + + if id.SchemaName != "schemaValue" { + t.Fatalf("Expected %q but got %q for Segment 'SchemaName'", id.SchemaName, "schemaValue") + } + + if id.TableName != "tableValue" { + t.Fatalf("Expected %q but got %q for Segment 'TableName'", id.TableName, "tableValue") + } + + if id.ColumnName != "columnValue" { + t.Fatalf("Expected %q but got %q for Segment 'ColumnName'", id.ColumnName, "columnValue") + } + + if id.SensitivityLabelSource != "current" { + t.Fatalf("Expected %q but got %q for Segment 'SensitivityLabelSource'", id.SensitivityLabelSource, "current") + } +} + +func TestFormatSensitivityLabelSourceID(t *testing.T) { + actual := NewSensitivityLabelSourceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "sqlPoolValue", "schemaValue", "tableValue", "columnValue", "current").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/schemas/schemaValue/tables/tableValue/columns/columnValue/sensitivityLabels/current" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseSensitivityLabelSourceID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *SensitivityLabelSourceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/schemas", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/schemas/schemaValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/schemas/schemaValue/tables", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/schemas/schemaValue/tables/tableValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/schemas/schemaValue/tables/tableValue/columns", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/schemas/schemaValue/tables/tableValue/columns/columnValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/schemas/schemaValue/tables/tableValue/columns/columnValue/sensitivityLabels", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/schemas/schemaValue/tables/tableValue/columns/columnValue/sensitivityLabels/current", + Expected: &SensitivityLabelSourceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + SqlPoolName: "sqlPoolValue", + SchemaName: "schemaValue", + TableName: "tableValue", + ColumnName: "columnValue", + SensitivityLabelSource: "current", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/schemas/schemaValue/tables/tableValue/columns/columnValue/sensitivityLabels/current/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseSensitivityLabelSourceID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + if actual.SqlPoolName != v.Expected.SqlPoolName { + t.Fatalf("Expected %q but got %q for SqlPoolName", v.Expected.SqlPoolName, actual.SqlPoolName) + } + + if actual.SchemaName != v.Expected.SchemaName { + t.Fatalf("Expected %q but got %q for SchemaName", v.Expected.SchemaName, actual.SchemaName) + } + + if actual.TableName != v.Expected.TableName { + t.Fatalf("Expected %q but got %q for TableName", v.Expected.TableName, actual.TableName) + } + + if actual.ColumnName != v.Expected.ColumnName { + t.Fatalf("Expected %q but got %q for ColumnName", v.Expected.ColumnName, actual.ColumnName) + } + + if actual.SensitivityLabelSource != v.Expected.SensitivityLabelSource { + t.Fatalf("Expected %q but got %q for SensitivityLabelSource", v.Expected.SensitivityLabelSource, actual.SensitivityLabelSource) + } + + } +} + +func TestParseSensitivityLabelSourceIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *SensitivityLabelSourceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/sQlPoOlS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/sQlPoOlS/sQlPoOlVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/schemas", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/sQlPoOlS/sQlPoOlVaLuE/sChEmAs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/schemas/schemaValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/sQlPoOlS/sQlPoOlVaLuE/sChEmAs/sChEmAvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/schemas/schemaValue/tables", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/sQlPoOlS/sQlPoOlVaLuE/sChEmAs/sChEmAvAlUe/tAbLeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/schemas/schemaValue/tables/tableValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/sQlPoOlS/sQlPoOlVaLuE/sChEmAs/sChEmAvAlUe/tAbLeS/tAbLeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/schemas/schemaValue/tables/tableValue/columns", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/sQlPoOlS/sQlPoOlVaLuE/sChEmAs/sChEmAvAlUe/tAbLeS/tAbLeVaLuE/cOlUmNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/schemas/schemaValue/tables/tableValue/columns/columnValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/sQlPoOlS/sQlPoOlVaLuE/sChEmAs/sChEmAvAlUe/tAbLeS/tAbLeVaLuE/cOlUmNs/cOlUmNvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/schemas/schemaValue/tables/tableValue/columns/columnValue/sensitivityLabels", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/sQlPoOlS/sQlPoOlVaLuE/sChEmAs/sChEmAvAlUe/tAbLeS/tAbLeVaLuE/cOlUmNs/cOlUmNvAlUe/sEnSiTiViTyLaBeLs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/schemas/schemaValue/tables/tableValue/columns/columnValue/sensitivityLabels/current", + Expected: &SensitivityLabelSourceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + SqlPoolName: "sqlPoolValue", + SchemaName: "schemaValue", + TableName: "tableValue", + ColumnName: "columnValue", + SensitivityLabelSource: "current", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/schemas/schemaValue/tables/tableValue/columns/columnValue/sensitivityLabels/current/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/sQlPoOlS/sQlPoOlVaLuE/sChEmAs/sChEmAvAlUe/tAbLeS/tAbLeVaLuE/cOlUmNs/cOlUmNvAlUe/sEnSiTiViTyLaBeLs/cUrReNt", + Expected: &SensitivityLabelSourceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + WorkspaceName: "wOrKsPaCeVaLuE", + SqlPoolName: "sQlPoOlVaLuE", + SchemaName: "sChEmAvAlUe", + TableName: "tAbLeVaLuE", + ColumnName: "cOlUmNvAlUe", + SensitivityLabelSource: "current", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/sQlPoOlS/sQlPoOlVaLuE/sChEmAs/sChEmAvAlUe/tAbLeS/tAbLeVaLuE/cOlUmNs/cOlUmNvAlUe/sEnSiTiViTyLaBeLs/cUrReNt/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseSensitivityLabelSourceIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + if actual.SqlPoolName != v.Expected.SqlPoolName { + t.Fatalf("Expected %q but got %q for SqlPoolName", v.Expected.SqlPoolName, actual.SqlPoolName) + } + + if actual.SchemaName != v.Expected.SchemaName { + t.Fatalf("Expected %q but got %q for SchemaName", v.Expected.SchemaName, actual.SchemaName) + } + + if actual.TableName != v.Expected.TableName { + t.Fatalf("Expected %q but got %q for TableName", v.Expected.TableName, actual.TableName) + } + + if actual.ColumnName != v.Expected.ColumnName { + t.Fatalf("Expected %q but got %q for ColumnName", v.Expected.ColumnName, actual.ColumnName) + } + + if actual.SensitivityLabelSource != v.Expected.SensitivityLabelSource { + t.Fatalf("Expected %q but got %q for SensitivityLabelSource", v.Expected.SensitivityLabelSource, actual.SensitivityLabelSource) + } + + } +} + +func TestSegmentsForSensitivityLabelSourceId(t *testing.T) { + segments := SensitivityLabelSourceId{}.Segments() + if len(segments) == 0 { + t.Fatalf("SensitivityLabelSourceId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolssensitivitylabels/id_sqlpool.go b/resource-manager/synapse/2021-06-01/sqlpoolssensitivitylabels/id_sqlpool.go new file mode 100644 index 00000000000..0898119e89d --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolssensitivitylabels/id_sqlpool.go @@ -0,0 +1,134 @@ +package sqlpoolssensitivitylabels + +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 = &SqlPoolId{} + +// SqlPoolId is a struct representing the Resource ID for a Sql Pool +type SqlPoolId struct { + SubscriptionId string + ResourceGroupName string + WorkspaceName string + SqlPoolName string +} + +// NewSqlPoolID returns a new SqlPoolId struct +func NewSqlPoolID(subscriptionId string, resourceGroupName string, workspaceName string, sqlPoolName string) SqlPoolId { + return SqlPoolId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + WorkspaceName: workspaceName, + SqlPoolName: sqlPoolName, + } +} + +// ParseSqlPoolID parses 'input' into a SqlPoolId +func ParseSqlPoolID(input string) (*SqlPoolId, error) { + parser := resourceids.NewParserFromResourceIdType(&SqlPoolId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := SqlPoolId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseSqlPoolIDInsensitively parses 'input' case-insensitively into a SqlPoolId +// note: this method should only be used for API response data and not user input +func ParseSqlPoolIDInsensitively(input string) (*SqlPoolId, error) { + parser := resourceids.NewParserFromResourceIdType(&SqlPoolId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := SqlPoolId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *SqlPoolId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.WorkspaceName, ok = input.Parsed["workspaceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "workspaceName", input) + } + + if id.SqlPoolName, ok = input.Parsed["sqlPoolName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "sqlPoolName", input) + } + + return nil +} + +// ValidateSqlPoolID checks that 'input' can be parsed as a Sql Pool ID +func ValidateSqlPoolID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseSqlPoolID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Sql Pool ID +func (id SqlPoolId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Synapse/workspaces/%s/sqlPools/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.WorkspaceName, id.SqlPoolName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Sql Pool ID +func (id SqlPoolId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftSynapse", "Microsoft.Synapse", "Microsoft.Synapse"), + resourceids.StaticSegment("staticWorkspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceName", "workspaceValue"), + resourceids.StaticSegment("staticSqlPools", "sqlPools", "sqlPools"), + resourceids.UserSpecifiedSegment("sqlPoolName", "sqlPoolValue"), + } +} + +// String returns a human-readable description of this Sql Pool ID +func (id SqlPoolId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Workspace Name: %q", id.WorkspaceName), + fmt.Sprintf("Sql Pool Name: %q", id.SqlPoolName), + } + return fmt.Sprintf("Sql Pool (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolssensitivitylabels/id_sqlpool_test.go b/resource-manager/synapse/2021-06-01/sqlpoolssensitivitylabels/id_sqlpool_test.go new file mode 100644 index 00000000000..42f1fc61397 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolssensitivitylabels/id_sqlpool_test.go @@ -0,0 +1,327 @@ +package sqlpoolssensitivitylabels + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &SqlPoolId{} + +func TestNewSqlPoolID(t *testing.T) { + id := NewSqlPoolID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "sqlPoolValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.WorkspaceName != "workspaceValue" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceName'", id.WorkspaceName, "workspaceValue") + } + + if id.SqlPoolName != "sqlPoolValue" { + t.Fatalf("Expected %q but got %q for Segment 'SqlPoolName'", id.SqlPoolName, "sqlPoolValue") + } +} + +func TestFormatSqlPoolID(t *testing.T) { + actual := NewSqlPoolID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "sqlPoolValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseSqlPoolID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *SqlPoolId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue", + Expected: &SqlPoolId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + SqlPoolName: "sqlPoolValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseSqlPoolID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + if actual.SqlPoolName != v.Expected.SqlPoolName { + t.Fatalf("Expected %q but got %q for SqlPoolName", v.Expected.SqlPoolName, actual.SqlPoolName) + } + + } +} + +func TestParseSqlPoolIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *SqlPoolId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/sQlPoOlS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue", + Expected: &SqlPoolId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + SqlPoolName: "sqlPoolValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/sQlPoOlS/sQlPoOlVaLuE", + Expected: &SqlPoolId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + WorkspaceName: "wOrKsPaCeVaLuE", + SqlPoolName: "sQlPoOlVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/sQlPoOlS/sQlPoOlVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseSqlPoolIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + if actual.SqlPoolName != v.Expected.SqlPoolName { + t.Fatalf("Expected %q but got %q for SqlPoolName", v.Expected.SqlPoolName, actual.SqlPoolName) + } + + } +} + +func TestSegmentsForSqlPoolId(t *testing.T) { + segments := SqlPoolId{}.Segments() + if len(segments) == 0 { + t.Fatalf("SqlPoolId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolssensitivitylabels/method_sqlpoolrecommendedsensitivitylabelsupdate.go b/resource-manager/synapse/2021-06-01/sqlpoolssensitivitylabels/method_sqlpoolrecommendedsensitivitylabelsupdate.go new file mode 100644 index 00000000000..bc7aa35029a --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolssensitivitylabels/method_sqlpoolrecommendedsensitivitylabelsupdate.go @@ -0,0 +1,51 @@ +package sqlpoolssensitivitylabels + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SqlPoolRecommendedSensitivityLabelsUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// SqlPoolRecommendedSensitivityLabelsUpdate ... +func (c SqlPoolsSensitivityLabelsClient) SqlPoolRecommendedSensitivityLabelsUpdate(ctx context.Context, id SqlPoolId, input RecommendedSensitivityLabelUpdateList) (result SqlPoolRecommendedSensitivityLabelsUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPatch, + Path: fmt.Sprintf("%s/recommendedSensitivityLabels", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolssensitivitylabels/method_sqlpoolsensitivitylabelscreateorupdate.go b/resource-manager/synapse/2021-06-01/sqlpoolssensitivitylabels/method_sqlpoolsensitivitylabelscreateorupdate.go new file mode 100644 index 00000000000..ebf665011eb --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolssensitivitylabels/method_sqlpoolsensitivitylabelscreateorupdate.go @@ -0,0 +1,57 @@ +package sqlpoolssensitivitylabels + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SqlPoolSensitivityLabelsCreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *SensitivityLabel +} + +// SqlPoolSensitivityLabelsCreateOrUpdate ... +func (c SqlPoolsSensitivityLabelsClient) SqlPoolSensitivityLabelsCreateOrUpdate(ctx context.Context, id ColumnId, input SensitivityLabel) (result SqlPoolSensitivityLabelsCreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: fmt.Sprintf("%s/sensitivityLabels/current", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolssensitivitylabels/method_sqlpoolsensitivitylabelsdelete.go b/resource-manager/synapse/2021-06-01/sqlpoolssensitivitylabels/method_sqlpoolsensitivitylabelsdelete.go new file mode 100644 index 00000000000..d7f39afec26 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolssensitivitylabels/method_sqlpoolsensitivitylabelsdelete.go @@ -0,0 +1,48 @@ +package sqlpoolssensitivitylabels + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SqlPoolSensitivityLabelsDeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// SqlPoolSensitivityLabelsDelete ... +func (c SqlPoolsSensitivityLabelsClient) SqlPoolSensitivityLabelsDelete(ctx context.Context, id ColumnId) (result SqlPoolSensitivityLabelsDeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: fmt.Sprintf("%s/sensitivityLabels/current", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolssensitivitylabels/method_sqlpoolsensitivitylabelsget.go b/resource-manager/synapse/2021-06-01/sqlpoolssensitivitylabels/method_sqlpoolsensitivitylabelsget.go new file mode 100644 index 00000000000..f6314aed80f --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolssensitivitylabels/method_sqlpoolsensitivitylabelsget.go @@ -0,0 +1,51 @@ +package sqlpoolssensitivitylabels + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SqlPoolSensitivityLabelsGetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *SensitivityLabel +} + +// SqlPoolSensitivityLabelsGet ... +func (c SqlPoolsSensitivityLabelsClient) SqlPoolSensitivityLabelsGet(ctx context.Context, id SensitivityLabelSourceId) (result SqlPoolSensitivityLabelsGetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolssensitivitylabels/method_sqlpoolsensitivitylabelslistcurrent.go b/resource-manager/synapse/2021-06-01/sqlpoolssensitivitylabels/method_sqlpoolsensitivitylabelslistcurrent.go new file mode 100644 index 00000000000..e8935303418 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolssensitivitylabels/method_sqlpoolsensitivitylabelslistcurrent.go @@ -0,0 +1,119 @@ +package sqlpoolssensitivitylabels + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SqlPoolSensitivityLabelsListCurrentOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]SensitivityLabel +} + +type SqlPoolSensitivityLabelsListCurrentCompleteResult struct { + LatestHttpResponse *http.Response + Items []SensitivityLabel +} + +type SqlPoolSensitivityLabelsListCurrentOperationOptions struct { + Filter *string +} + +func DefaultSqlPoolSensitivityLabelsListCurrentOperationOptions() SqlPoolSensitivityLabelsListCurrentOperationOptions { + return SqlPoolSensitivityLabelsListCurrentOperationOptions{} +} + +func (o SqlPoolSensitivityLabelsListCurrentOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o SqlPoolSensitivityLabelsListCurrentOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o SqlPoolSensitivityLabelsListCurrentOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + return &out +} + +// SqlPoolSensitivityLabelsListCurrent ... +func (c SqlPoolsSensitivityLabelsClient) SqlPoolSensitivityLabelsListCurrent(ctx context.Context, id SqlPoolId, options SqlPoolSensitivityLabelsListCurrentOperationOptions) (result SqlPoolSensitivityLabelsListCurrentOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/currentSensitivityLabels", id.ID()), + OptionsObject: options, + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]SensitivityLabel `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// SqlPoolSensitivityLabelsListCurrentComplete retrieves all the results into a single object +func (c SqlPoolsSensitivityLabelsClient) SqlPoolSensitivityLabelsListCurrentComplete(ctx context.Context, id SqlPoolId, options SqlPoolSensitivityLabelsListCurrentOperationOptions) (SqlPoolSensitivityLabelsListCurrentCompleteResult, error) { + return c.SqlPoolSensitivityLabelsListCurrentCompleteMatchingPredicate(ctx, id, options, SensitivityLabelOperationPredicate{}) +} + +// SqlPoolSensitivityLabelsListCurrentCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c SqlPoolsSensitivityLabelsClient) SqlPoolSensitivityLabelsListCurrentCompleteMatchingPredicate(ctx context.Context, id SqlPoolId, options SqlPoolSensitivityLabelsListCurrentOperationOptions, predicate SensitivityLabelOperationPredicate) (result SqlPoolSensitivityLabelsListCurrentCompleteResult, err error) { + items := make([]SensitivityLabel, 0) + + resp, err := c.SqlPoolSensitivityLabelsListCurrent(ctx, id, options) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = SqlPoolSensitivityLabelsListCurrentCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolssensitivitylabels/method_sqlpoolsensitivitylabelslistrecommended.go b/resource-manager/synapse/2021-06-01/sqlpoolssensitivitylabels/method_sqlpoolsensitivitylabelslistrecommended.go new file mode 100644 index 00000000000..8240951c050 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolssensitivitylabels/method_sqlpoolsensitivitylabelslistrecommended.go @@ -0,0 +1,123 @@ +package sqlpoolssensitivitylabels + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SqlPoolSensitivityLabelsListRecommendedOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]SensitivityLabel +} + +type SqlPoolSensitivityLabelsListRecommendedCompleteResult struct { + LatestHttpResponse *http.Response + Items []SensitivityLabel +} + +type SqlPoolSensitivityLabelsListRecommendedOperationOptions struct { + Filter *string + IncludeDisabledRecommendations *bool +} + +func DefaultSqlPoolSensitivityLabelsListRecommendedOperationOptions() SqlPoolSensitivityLabelsListRecommendedOperationOptions { + return SqlPoolSensitivityLabelsListRecommendedOperationOptions{} +} + +func (o SqlPoolSensitivityLabelsListRecommendedOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o SqlPoolSensitivityLabelsListRecommendedOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o SqlPoolSensitivityLabelsListRecommendedOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.IncludeDisabledRecommendations != nil { + out.Append("includeDisabledRecommendations", fmt.Sprintf("%v", *o.IncludeDisabledRecommendations)) + } + return &out +} + +// SqlPoolSensitivityLabelsListRecommended ... +func (c SqlPoolsSensitivityLabelsClient) SqlPoolSensitivityLabelsListRecommended(ctx context.Context, id SqlPoolId, options SqlPoolSensitivityLabelsListRecommendedOperationOptions) (result SqlPoolSensitivityLabelsListRecommendedOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/recommendedSensitivityLabels", id.ID()), + OptionsObject: options, + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]SensitivityLabel `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// SqlPoolSensitivityLabelsListRecommendedComplete retrieves all the results into a single object +func (c SqlPoolsSensitivityLabelsClient) SqlPoolSensitivityLabelsListRecommendedComplete(ctx context.Context, id SqlPoolId, options SqlPoolSensitivityLabelsListRecommendedOperationOptions) (SqlPoolSensitivityLabelsListRecommendedCompleteResult, error) { + return c.SqlPoolSensitivityLabelsListRecommendedCompleteMatchingPredicate(ctx, id, options, SensitivityLabelOperationPredicate{}) +} + +// SqlPoolSensitivityLabelsListRecommendedCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c SqlPoolsSensitivityLabelsClient) SqlPoolSensitivityLabelsListRecommendedCompleteMatchingPredicate(ctx context.Context, id SqlPoolId, options SqlPoolSensitivityLabelsListRecommendedOperationOptions, predicate SensitivityLabelOperationPredicate) (result SqlPoolSensitivityLabelsListRecommendedCompleteResult, err error) { + items := make([]SensitivityLabel, 0) + + resp, err := c.SqlPoolSensitivityLabelsListRecommended(ctx, id, options) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = SqlPoolSensitivityLabelsListRecommendedCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolssensitivitylabels/method_sqlpoolsensitivitylabelsupdate.go b/resource-manager/synapse/2021-06-01/sqlpoolssensitivitylabels/method_sqlpoolsensitivitylabelsupdate.go new file mode 100644 index 00000000000..04d24297972 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolssensitivitylabels/method_sqlpoolsensitivitylabelsupdate.go @@ -0,0 +1,51 @@ +package sqlpoolssensitivitylabels + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SqlPoolSensitivityLabelsUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// SqlPoolSensitivityLabelsUpdate ... +func (c SqlPoolsSensitivityLabelsClient) SqlPoolSensitivityLabelsUpdate(ctx context.Context, id SqlPoolId, input SensitivityLabelUpdateList) (result SqlPoolSensitivityLabelsUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPatch, + Path: fmt.Sprintf("%s/currentSensitivityLabels", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolssensitivitylabels/model_recommendedsensitivitylabelupdate.go b/resource-manager/synapse/2021-06-01/sqlpoolssensitivitylabels/model_recommendedsensitivitylabelupdate.go new file mode 100644 index 00000000000..c043e402280 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolssensitivitylabels/model_recommendedsensitivitylabelupdate.go @@ -0,0 +1,11 @@ +package sqlpoolssensitivitylabels + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RecommendedSensitivityLabelUpdate struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *RecommendedSensitivityLabelUpdateProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolssensitivitylabels/model_recommendedsensitivitylabelupdatelist.go b/resource-manager/synapse/2021-06-01/sqlpoolssensitivitylabels/model_recommendedsensitivitylabelupdatelist.go new file mode 100644 index 00000000000..64c41c6f39e --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolssensitivitylabels/model_recommendedsensitivitylabelupdatelist.go @@ -0,0 +1,8 @@ +package sqlpoolssensitivitylabels + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RecommendedSensitivityLabelUpdateList struct { + Operations *[]RecommendedSensitivityLabelUpdate `json:"operations,omitempty"` +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolssensitivitylabels/model_recommendedsensitivitylabelupdateproperties.go b/resource-manager/synapse/2021-06-01/sqlpoolssensitivitylabels/model_recommendedsensitivitylabelupdateproperties.go new file mode 100644 index 00000000000..f1ead1c90e2 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolssensitivitylabels/model_recommendedsensitivitylabelupdateproperties.go @@ -0,0 +1,11 @@ +package sqlpoolssensitivitylabels + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RecommendedSensitivityLabelUpdateProperties struct { + Column string `json:"column"` + Op RecommendedSensitivityLabelUpdateKind `json:"op"` + Schema string `json:"schema"` + Table string `json:"table"` +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolssensitivitylabels/model_sensitivitylabel.go b/resource-manager/synapse/2021-06-01/sqlpoolssensitivitylabels/model_sensitivitylabel.go new file mode 100644 index 00000000000..f359afe346c --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolssensitivitylabels/model_sensitivitylabel.go @@ -0,0 +1,12 @@ +package sqlpoolssensitivitylabels + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SensitivityLabel struct { + Id *string `json:"id,omitempty"` + ManagedBy *string `json:"managedBy,omitempty"` + Name *string `json:"name,omitempty"` + Properties *SensitivityLabelProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolssensitivitylabels/model_sensitivitylabelproperties.go b/resource-manager/synapse/2021-06-01/sqlpoolssensitivitylabels/model_sensitivitylabelproperties.go new file mode 100644 index 00000000000..a04454be544 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolssensitivitylabels/model_sensitivitylabelproperties.go @@ -0,0 +1,16 @@ +package sqlpoolssensitivitylabels + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SensitivityLabelProperties struct { + ColumnName *string `json:"columnName,omitempty"` + InformationType *string `json:"informationType,omitempty"` + InformationTypeId *string `json:"informationTypeId,omitempty"` + IsDisabled *bool `json:"isDisabled,omitempty"` + LabelId *string `json:"labelId,omitempty"` + LabelName *string `json:"labelName,omitempty"` + Rank *SensitivityLabelRank `json:"rank,omitempty"` + SchemaName *string `json:"schemaName,omitempty"` + TableName *string `json:"tableName,omitempty"` +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolssensitivitylabels/model_sensitivitylabelupdate.go b/resource-manager/synapse/2021-06-01/sqlpoolssensitivitylabels/model_sensitivitylabelupdate.go new file mode 100644 index 00000000000..cefa29d181b --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolssensitivitylabels/model_sensitivitylabelupdate.go @@ -0,0 +1,11 @@ +package sqlpoolssensitivitylabels + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SensitivityLabelUpdate struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *SensitivityLabelUpdateProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolssensitivitylabels/model_sensitivitylabelupdatelist.go b/resource-manager/synapse/2021-06-01/sqlpoolssensitivitylabels/model_sensitivitylabelupdatelist.go new file mode 100644 index 00000000000..eb3139af485 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolssensitivitylabels/model_sensitivitylabelupdatelist.go @@ -0,0 +1,8 @@ +package sqlpoolssensitivitylabels + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SensitivityLabelUpdateList struct { + Operations *[]SensitivityLabelUpdate `json:"operations,omitempty"` +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolssensitivitylabels/model_sensitivitylabelupdateproperties.go b/resource-manager/synapse/2021-06-01/sqlpoolssensitivitylabels/model_sensitivitylabelupdateproperties.go new file mode 100644 index 00000000000..8313ffc88e7 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolssensitivitylabels/model_sensitivitylabelupdateproperties.go @@ -0,0 +1,12 @@ +package sqlpoolssensitivitylabels + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SensitivityLabelUpdateProperties struct { + Column string `json:"column"` + Op SensitivityLabelUpdateKind `json:"op"` + Schema string `json:"schema"` + SensitivityLabel *SensitivityLabel `json:"sensitivityLabel,omitempty"` + Table string `json:"table"` +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolssensitivitylabels/predicates.go b/resource-manager/synapse/2021-06-01/sqlpoolssensitivitylabels/predicates.go new file mode 100644 index 00000000000..66aa0b99e1d --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolssensitivitylabels/predicates.go @@ -0,0 +1,32 @@ +package sqlpoolssensitivitylabels + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SensitivityLabelOperationPredicate struct { + Id *string + ManagedBy *string + Name *string + Type *string +} + +func (p SensitivityLabelOperationPredicate) Matches(input SensitivityLabel) bool { + + if p.Id != nil && (input.Id == nil || *p.Id != *input.Id) { + return false + } + + if p.ManagedBy != nil && (input.ManagedBy == nil || *p.ManagedBy != *input.ManagedBy) { + return false + } + + if p.Name != nil && (input.Name == nil || *p.Name != *input.Name) { + return false + } + + if p.Type != nil && (input.Type == nil || *p.Type != *input.Type) { + return false + } + + return true +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolssensitivitylabels/version.go b/resource-manager/synapse/2021-06-01/sqlpoolssensitivitylabels/version.go new file mode 100644 index 00000000000..319e7bca98c --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolssensitivitylabels/version.go @@ -0,0 +1,12 @@ +package sqlpoolssensitivitylabels + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2021-06-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/sqlpoolssensitivitylabels/%s", defaultApiVersion) +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolssqlpoolcolumns/README.md b/resource-manager/synapse/2021-06-01/sqlpoolssqlpoolcolumns/README.md new file mode 100644 index 00000000000..31894455ca1 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolssqlpoolcolumns/README.md @@ -0,0 +1,36 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/synapse/2021-06-01/sqlpoolssqlpoolcolumns` Documentation + +The `sqlpoolssqlpoolcolumns` SDK allows for interaction with the Azure Resource Manager Service `synapse` (API Version `2021-06-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/synapse/2021-06-01/sqlpoolssqlpoolcolumns" +``` + + +### Client Initialization + +```go +client := sqlpoolssqlpoolcolumns.NewSqlPoolsSqlPoolColumnsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `SqlPoolsSqlPoolColumnsClient.SqlPoolColumnsGet` + +```go +ctx := context.TODO() +id := sqlpoolssqlpoolcolumns.NewColumnID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "sqlPoolValue", "schemaValue", "tableValue", "columnValue") + +read, err := client.SqlPoolColumnsGet(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` diff --git a/resource-manager/synapse/2021-06-01/sqlpoolssqlpoolcolumns/client.go b/resource-manager/synapse/2021-06-01/sqlpoolssqlpoolcolumns/client.go new file mode 100644 index 00000000000..d7109a7495a --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolssqlpoolcolumns/client.go @@ -0,0 +1,26 @@ +package sqlpoolssqlpoolcolumns + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SqlPoolsSqlPoolColumnsClient struct { + Client *resourcemanager.Client +} + +func NewSqlPoolsSqlPoolColumnsClientWithBaseURI(sdkApi sdkEnv.Api) (*SqlPoolsSqlPoolColumnsClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "sqlpoolssqlpoolcolumns", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating SqlPoolsSqlPoolColumnsClient: %+v", err) + } + + return &SqlPoolsSqlPoolColumnsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolssqlpoolcolumns/constants.go b/resource-manager/synapse/2021-06-01/sqlpoolssqlpoolcolumns/constants.go new file mode 100644 index 00000000000..4321a7921f3 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolssqlpoolcolumns/constants.go @@ -0,0 +1,147 @@ +package sqlpoolssqlpoolcolumns + +import ( + "encoding/json" + "fmt" + "strings" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ColumnDataType string + +const ( + ColumnDataTypeBigint ColumnDataType = "bigint" + ColumnDataTypeBinary ColumnDataType = "binary" + ColumnDataTypeBit ColumnDataType = "bit" + ColumnDataTypeChar ColumnDataType = "char" + ColumnDataTypeDate ColumnDataType = "date" + ColumnDataTypeDatetime ColumnDataType = "datetime" + ColumnDataTypeDatetimeTwo ColumnDataType = "datetime2" + ColumnDataTypeDatetimeoffset ColumnDataType = "datetimeoffset" + ColumnDataTypeDecimal ColumnDataType = "decimal" + ColumnDataTypeFloat ColumnDataType = "float" + ColumnDataTypeGeography ColumnDataType = "geography" + ColumnDataTypeGeometry ColumnDataType = "geometry" + ColumnDataTypeHierarchyid ColumnDataType = "hierarchyid" + ColumnDataTypeImage ColumnDataType = "image" + ColumnDataTypeInt ColumnDataType = "int" + ColumnDataTypeMoney ColumnDataType = "money" + ColumnDataTypeNchar ColumnDataType = "nchar" + ColumnDataTypeNtext ColumnDataType = "ntext" + ColumnDataTypeNumeric ColumnDataType = "numeric" + ColumnDataTypeNvarchar ColumnDataType = "nvarchar" + ColumnDataTypeReal ColumnDataType = "real" + ColumnDataTypeSmalldatetime ColumnDataType = "smalldatetime" + ColumnDataTypeSmallint ColumnDataType = "smallint" + ColumnDataTypeSmallmoney ColumnDataType = "smallmoney" + ColumnDataTypeSqlVariant ColumnDataType = "sql_variant" + ColumnDataTypeSysname ColumnDataType = "sysname" + ColumnDataTypeText ColumnDataType = "text" + ColumnDataTypeTime ColumnDataType = "time" + ColumnDataTypeTimestamp ColumnDataType = "timestamp" + ColumnDataTypeTinyint ColumnDataType = "tinyint" + ColumnDataTypeUniqueidentifier ColumnDataType = "uniqueidentifier" + ColumnDataTypeVarbinary ColumnDataType = "varbinary" + ColumnDataTypeVarchar ColumnDataType = "varchar" + ColumnDataTypeXml ColumnDataType = "xml" +) + +func PossibleValuesForColumnDataType() []string { + return []string{ + string(ColumnDataTypeBigint), + string(ColumnDataTypeBinary), + string(ColumnDataTypeBit), + string(ColumnDataTypeChar), + string(ColumnDataTypeDate), + string(ColumnDataTypeDatetime), + string(ColumnDataTypeDatetimeTwo), + string(ColumnDataTypeDatetimeoffset), + string(ColumnDataTypeDecimal), + string(ColumnDataTypeFloat), + string(ColumnDataTypeGeography), + string(ColumnDataTypeGeometry), + string(ColumnDataTypeHierarchyid), + string(ColumnDataTypeImage), + string(ColumnDataTypeInt), + string(ColumnDataTypeMoney), + string(ColumnDataTypeNchar), + string(ColumnDataTypeNtext), + string(ColumnDataTypeNumeric), + string(ColumnDataTypeNvarchar), + string(ColumnDataTypeReal), + string(ColumnDataTypeSmalldatetime), + string(ColumnDataTypeSmallint), + string(ColumnDataTypeSmallmoney), + string(ColumnDataTypeSqlVariant), + string(ColumnDataTypeSysname), + string(ColumnDataTypeText), + string(ColumnDataTypeTime), + string(ColumnDataTypeTimestamp), + string(ColumnDataTypeTinyint), + string(ColumnDataTypeUniqueidentifier), + string(ColumnDataTypeVarbinary), + string(ColumnDataTypeVarchar), + string(ColumnDataTypeXml), + } +} + +func (s *ColumnDataType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseColumnDataType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseColumnDataType(input string) (*ColumnDataType, error) { + vals := map[string]ColumnDataType{ + "bigint": ColumnDataTypeBigint, + "binary": ColumnDataTypeBinary, + "bit": ColumnDataTypeBit, + "char": ColumnDataTypeChar, + "date": ColumnDataTypeDate, + "datetime": ColumnDataTypeDatetime, + "datetime2": ColumnDataTypeDatetimeTwo, + "datetimeoffset": ColumnDataTypeDatetimeoffset, + "decimal": ColumnDataTypeDecimal, + "float": ColumnDataTypeFloat, + "geography": ColumnDataTypeGeography, + "geometry": ColumnDataTypeGeometry, + "hierarchyid": ColumnDataTypeHierarchyid, + "image": ColumnDataTypeImage, + "int": ColumnDataTypeInt, + "money": ColumnDataTypeMoney, + "nchar": ColumnDataTypeNchar, + "ntext": ColumnDataTypeNtext, + "numeric": ColumnDataTypeNumeric, + "nvarchar": ColumnDataTypeNvarchar, + "real": ColumnDataTypeReal, + "smalldatetime": ColumnDataTypeSmalldatetime, + "smallint": ColumnDataTypeSmallint, + "smallmoney": ColumnDataTypeSmallmoney, + "sql_variant": ColumnDataTypeSqlVariant, + "sysname": ColumnDataTypeSysname, + "text": ColumnDataTypeText, + "time": ColumnDataTypeTime, + "timestamp": ColumnDataTypeTimestamp, + "tinyint": ColumnDataTypeTinyint, + "uniqueidentifier": ColumnDataTypeUniqueidentifier, + "varbinary": ColumnDataTypeVarbinary, + "varchar": ColumnDataTypeVarchar, + "xml": ColumnDataTypeXml, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ColumnDataType(input) + return &out, nil +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolssqlpoolcolumns/id_column.go b/resource-manager/synapse/2021-06-01/sqlpoolssqlpoolcolumns/id_column.go new file mode 100644 index 00000000000..1c06d9c6a9a --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolssqlpoolcolumns/id_column.go @@ -0,0 +1,161 @@ +package sqlpoolssqlpoolcolumns + +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 = &ColumnId{} + +// ColumnId is a struct representing the Resource ID for a Column +type ColumnId struct { + SubscriptionId string + ResourceGroupName string + WorkspaceName string + SqlPoolName string + SchemaName string + TableName string + ColumnName string +} + +// NewColumnID returns a new ColumnId struct +func NewColumnID(subscriptionId string, resourceGroupName string, workspaceName string, sqlPoolName string, schemaName string, tableName string, columnName string) ColumnId { + return ColumnId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + WorkspaceName: workspaceName, + SqlPoolName: sqlPoolName, + SchemaName: schemaName, + TableName: tableName, + ColumnName: columnName, + } +} + +// ParseColumnID parses 'input' into a ColumnId +func ParseColumnID(input string) (*ColumnId, error) { + parser := resourceids.NewParserFromResourceIdType(&ColumnId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ColumnId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseColumnIDInsensitively parses 'input' case-insensitively into a ColumnId +// note: this method should only be used for API response data and not user input +func ParseColumnIDInsensitively(input string) (*ColumnId, error) { + parser := resourceids.NewParserFromResourceIdType(&ColumnId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ColumnId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ColumnId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.WorkspaceName, ok = input.Parsed["workspaceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "workspaceName", input) + } + + if id.SqlPoolName, ok = input.Parsed["sqlPoolName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "sqlPoolName", input) + } + + if id.SchemaName, ok = input.Parsed["schemaName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "schemaName", input) + } + + if id.TableName, ok = input.Parsed["tableName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "tableName", input) + } + + if id.ColumnName, ok = input.Parsed["columnName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "columnName", input) + } + + return nil +} + +// ValidateColumnID checks that 'input' can be parsed as a Column ID +func ValidateColumnID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseColumnID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Column ID +func (id ColumnId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Synapse/workspaces/%s/sqlPools/%s/schemas/%s/tables/%s/columns/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.WorkspaceName, id.SqlPoolName, id.SchemaName, id.TableName, id.ColumnName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Column ID +func (id ColumnId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftSynapse", "Microsoft.Synapse", "Microsoft.Synapse"), + resourceids.StaticSegment("staticWorkspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceName", "workspaceValue"), + resourceids.StaticSegment("staticSqlPools", "sqlPools", "sqlPools"), + resourceids.UserSpecifiedSegment("sqlPoolName", "sqlPoolValue"), + resourceids.StaticSegment("staticSchemas", "schemas", "schemas"), + resourceids.UserSpecifiedSegment("schemaName", "schemaValue"), + resourceids.StaticSegment("staticTables", "tables", "tables"), + resourceids.UserSpecifiedSegment("tableName", "tableValue"), + resourceids.StaticSegment("staticColumns", "columns", "columns"), + resourceids.UserSpecifiedSegment("columnName", "columnValue"), + } +} + +// String returns a human-readable description of this Column ID +func (id ColumnId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Workspace Name: %q", id.WorkspaceName), + fmt.Sprintf("Sql Pool Name: %q", id.SqlPoolName), + fmt.Sprintf("Schema Name: %q", id.SchemaName), + fmt.Sprintf("Table Name: %q", id.TableName), + fmt.Sprintf("Column Name: %q", id.ColumnName), + } + return fmt.Sprintf("Column (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolssqlpoolcolumns/id_column_test.go b/resource-manager/synapse/2021-06-01/sqlpoolssqlpoolcolumns/id_column_test.go new file mode 100644 index 00000000000..a706ba7efea --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolssqlpoolcolumns/id_column_test.go @@ -0,0 +1,462 @@ +package sqlpoolssqlpoolcolumns + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &ColumnId{} + +func TestNewColumnID(t *testing.T) { + id := NewColumnID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "sqlPoolValue", "schemaValue", "tableValue", "columnValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.WorkspaceName != "workspaceValue" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceName'", id.WorkspaceName, "workspaceValue") + } + + if id.SqlPoolName != "sqlPoolValue" { + t.Fatalf("Expected %q but got %q for Segment 'SqlPoolName'", id.SqlPoolName, "sqlPoolValue") + } + + if id.SchemaName != "schemaValue" { + t.Fatalf("Expected %q but got %q for Segment 'SchemaName'", id.SchemaName, "schemaValue") + } + + if id.TableName != "tableValue" { + t.Fatalf("Expected %q but got %q for Segment 'TableName'", id.TableName, "tableValue") + } + + if id.ColumnName != "columnValue" { + t.Fatalf("Expected %q but got %q for Segment 'ColumnName'", id.ColumnName, "columnValue") + } +} + +func TestFormatColumnID(t *testing.T) { + actual := NewColumnID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "sqlPoolValue", "schemaValue", "tableValue", "columnValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/schemas/schemaValue/tables/tableValue/columns/columnValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseColumnID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ColumnId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/schemas", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/schemas/schemaValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/schemas/schemaValue/tables", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/schemas/schemaValue/tables/tableValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/schemas/schemaValue/tables/tableValue/columns", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/schemas/schemaValue/tables/tableValue/columns/columnValue", + Expected: &ColumnId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + SqlPoolName: "sqlPoolValue", + SchemaName: "schemaValue", + TableName: "tableValue", + ColumnName: "columnValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/schemas/schemaValue/tables/tableValue/columns/columnValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseColumnID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + if actual.SqlPoolName != v.Expected.SqlPoolName { + t.Fatalf("Expected %q but got %q for SqlPoolName", v.Expected.SqlPoolName, actual.SqlPoolName) + } + + if actual.SchemaName != v.Expected.SchemaName { + t.Fatalf("Expected %q but got %q for SchemaName", v.Expected.SchemaName, actual.SchemaName) + } + + if actual.TableName != v.Expected.TableName { + t.Fatalf("Expected %q but got %q for TableName", v.Expected.TableName, actual.TableName) + } + + if actual.ColumnName != v.Expected.ColumnName { + t.Fatalf("Expected %q but got %q for ColumnName", v.Expected.ColumnName, actual.ColumnName) + } + + } +} + +func TestParseColumnIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ColumnId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/sQlPoOlS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/sQlPoOlS/sQlPoOlVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/schemas", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/sQlPoOlS/sQlPoOlVaLuE/sChEmAs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/schemas/schemaValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/sQlPoOlS/sQlPoOlVaLuE/sChEmAs/sChEmAvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/schemas/schemaValue/tables", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/sQlPoOlS/sQlPoOlVaLuE/sChEmAs/sChEmAvAlUe/tAbLeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/schemas/schemaValue/tables/tableValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/sQlPoOlS/sQlPoOlVaLuE/sChEmAs/sChEmAvAlUe/tAbLeS/tAbLeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/schemas/schemaValue/tables/tableValue/columns", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/sQlPoOlS/sQlPoOlVaLuE/sChEmAs/sChEmAvAlUe/tAbLeS/tAbLeVaLuE/cOlUmNs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/schemas/schemaValue/tables/tableValue/columns/columnValue", + Expected: &ColumnId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + SqlPoolName: "sqlPoolValue", + SchemaName: "schemaValue", + TableName: "tableValue", + ColumnName: "columnValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/schemas/schemaValue/tables/tableValue/columns/columnValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/sQlPoOlS/sQlPoOlVaLuE/sChEmAs/sChEmAvAlUe/tAbLeS/tAbLeVaLuE/cOlUmNs/cOlUmNvAlUe", + Expected: &ColumnId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + WorkspaceName: "wOrKsPaCeVaLuE", + SqlPoolName: "sQlPoOlVaLuE", + SchemaName: "sChEmAvAlUe", + TableName: "tAbLeVaLuE", + ColumnName: "cOlUmNvAlUe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/sQlPoOlS/sQlPoOlVaLuE/sChEmAs/sChEmAvAlUe/tAbLeS/tAbLeVaLuE/cOlUmNs/cOlUmNvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseColumnIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + if actual.SqlPoolName != v.Expected.SqlPoolName { + t.Fatalf("Expected %q but got %q for SqlPoolName", v.Expected.SqlPoolName, actual.SqlPoolName) + } + + if actual.SchemaName != v.Expected.SchemaName { + t.Fatalf("Expected %q but got %q for SchemaName", v.Expected.SchemaName, actual.SchemaName) + } + + if actual.TableName != v.Expected.TableName { + t.Fatalf("Expected %q but got %q for TableName", v.Expected.TableName, actual.TableName) + } + + if actual.ColumnName != v.Expected.ColumnName { + t.Fatalf("Expected %q but got %q for ColumnName", v.Expected.ColumnName, actual.ColumnName) + } + + } +} + +func TestSegmentsForColumnId(t *testing.T) { + segments := ColumnId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ColumnId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolssqlpoolcolumns/method_sqlpoolcolumnsget.go b/resource-manager/synapse/2021-06-01/sqlpoolssqlpoolcolumns/method_sqlpoolcolumnsget.go new file mode 100644 index 00000000000..cc3ac725589 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolssqlpoolcolumns/method_sqlpoolcolumnsget.go @@ -0,0 +1,51 @@ +package sqlpoolssqlpoolcolumns + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SqlPoolColumnsGetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *SqlPoolColumn +} + +// SqlPoolColumnsGet ... +func (c SqlPoolsSqlPoolColumnsClient) SqlPoolColumnsGet(ctx context.Context, id ColumnId) (result SqlPoolColumnsGetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolssqlpoolcolumns/model_sqlpoolcolumn.go b/resource-manager/synapse/2021-06-01/sqlpoolssqlpoolcolumns/model_sqlpoolcolumn.go new file mode 100644 index 00000000000..94c36b5f6ee --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolssqlpoolcolumns/model_sqlpoolcolumn.go @@ -0,0 +1,11 @@ +package sqlpoolssqlpoolcolumns + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SqlPoolColumn struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *SqlPoolColumnProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolssqlpoolcolumns/model_sqlpoolcolumnproperties.go b/resource-manager/synapse/2021-06-01/sqlpoolssqlpoolcolumns/model_sqlpoolcolumnproperties.go new file mode 100644 index 00000000000..769d15fd42c --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolssqlpoolcolumns/model_sqlpoolcolumnproperties.go @@ -0,0 +1,9 @@ +package sqlpoolssqlpoolcolumns + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SqlPoolColumnProperties struct { + ColumnType *ColumnDataType `json:"columnType,omitempty"` + IsComputed *bool `json:"isComputed,omitempty"` +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolssqlpoolcolumns/version.go b/resource-manager/synapse/2021-06-01/sqlpoolssqlpoolcolumns/version.go new file mode 100644 index 00000000000..b99ad24df14 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolssqlpoolcolumns/version.go @@ -0,0 +1,12 @@ +package sqlpoolssqlpoolcolumns + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2021-06-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/sqlpoolssqlpoolcolumns/%s", defaultApiVersion) +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolssqlpoolschemas/README.md b/resource-manager/synapse/2021-06-01/sqlpoolssqlpoolschemas/README.md new file mode 100644 index 00000000000..f8eda2223a3 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolssqlpoolschemas/README.md @@ -0,0 +1,36 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/synapse/2021-06-01/sqlpoolssqlpoolschemas` Documentation + +The `sqlpoolssqlpoolschemas` SDK allows for interaction with the Azure Resource Manager Service `synapse` (API Version `2021-06-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/synapse/2021-06-01/sqlpoolssqlpoolschemas" +``` + + +### Client Initialization + +```go +client := sqlpoolssqlpoolschemas.NewSqlPoolsSqlPoolSchemasClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `SqlPoolsSqlPoolSchemasClient.SqlPoolSchemasGet` + +```go +ctx := context.TODO() +id := sqlpoolssqlpoolschemas.NewSchemaID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "sqlPoolValue", "schemaValue") + +read, err := client.SqlPoolSchemasGet(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` diff --git a/resource-manager/synapse/2021-06-01/sqlpoolssqlpoolschemas/client.go b/resource-manager/synapse/2021-06-01/sqlpoolssqlpoolschemas/client.go new file mode 100644 index 00000000000..564a1146a69 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolssqlpoolschemas/client.go @@ -0,0 +1,26 @@ +package sqlpoolssqlpoolschemas + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SqlPoolsSqlPoolSchemasClient struct { + Client *resourcemanager.Client +} + +func NewSqlPoolsSqlPoolSchemasClientWithBaseURI(sdkApi sdkEnv.Api) (*SqlPoolsSqlPoolSchemasClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "sqlpoolssqlpoolschemas", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating SqlPoolsSqlPoolSchemasClient: %+v", err) + } + + return &SqlPoolsSqlPoolSchemasClient{ + Client: client, + }, nil +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolssqlpoolschemas/id_schema.go b/resource-manager/synapse/2021-06-01/sqlpoolssqlpoolschemas/id_schema.go new file mode 100644 index 00000000000..0cbf7ab1df2 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolssqlpoolschemas/id_schema.go @@ -0,0 +1,143 @@ +package sqlpoolssqlpoolschemas + +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 = &SchemaId{} + +// SchemaId is a struct representing the Resource ID for a Schema +type SchemaId struct { + SubscriptionId string + ResourceGroupName string + WorkspaceName string + SqlPoolName string + SchemaName string +} + +// NewSchemaID returns a new SchemaId struct +func NewSchemaID(subscriptionId string, resourceGroupName string, workspaceName string, sqlPoolName string, schemaName string) SchemaId { + return SchemaId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + WorkspaceName: workspaceName, + SqlPoolName: sqlPoolName, + SchemaName: schemaName, + } +} + +// ParseSchemaID parses 'input' into a SchemaId +func ParseSchemaID(input string) (*SchemaId, error) { + parser := resourceids.NewParserFromResourceIdType(&SchemaId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := SchemaId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseSchemaIDInsensitively parses 'input' case-insensitively into a SchemaId +// note: this method should only be used for API response data and not user input +func ParseSchemaIDInsensitively(input string) (*SchemaId, error) { + parser := resourceids.NewParserFromResourceIdType(&SchemaId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := SchemaId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *SchemaId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.WorkspaceName, ok = input.Parsed["workspaceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "workspaceName", input) + } + + if id.SqlPoolName, ok = input.Parsed["sqlPoolName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "sqlPoolName", input) + } + + if id.SchemaName, ok = input.Parsed["schemaName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "schemaName", input) + } + + return nil +} + +// ValidateSchemaID checks that 'input' can be parsed as a Schema ID +func ValidateSchemaID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseSchemaID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Schema ID +func (id SchemaId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Synapse/workspaces/%s/sqlPools/%s/schemas/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.WorkspaceName, id.SqlPoolName, id.SchemaName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Schema ID +func (id SchemaId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftSynapse", "Microsoft.Synapse", "Microsoft.Synapse"), + resourceids.StaticSegment("staticWorkspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceName", "workspaceValue"), + resourceids.StaticSegment("staticSqlPools", "sqlPools", "sqlPools"), + resourceids.UserSpecifiedSegment("sqlPoolName", "sqlPoolValue"), + resourceids.StaticSegment("staticSchemas", "schemas", "schemas"), + resourceids.UserSpecifiedSegment("schemaName", "schemaValue"), + } +} + +// String returns a human-readable description of this Schema ID +func (id SchemaId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Workspace Name: %q", id.WorkspaceName), + fmt.Sprintf("Sql Pool Name: %q", id.SqlPoolName), + fmt.Sprintf("Schema Name: %q", id.SchemaName), + } + return fmt.Sprintf("Schema (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolssqlpoolschemas/id_schema_test.go b/resource-manager/synapse/2021-06-01/sqlpoolssqlpoolschemas/id_schema_test.go new file mode 100644 index 00000000000..13ee780a3b9 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolssqlpoolschemas/id_schema_test.go @@ -0,0 +1,372 @@ +package sqlpoolssqlpoolschemas + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &SchemaId{} + +func TestNewSchemaID(t *testing.T) { + id := NewSchemaID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "sqlPoolValue", "schemaValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.WorkspaceName != "workspaceValue" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceName'", id.WorkspaceName, "workspaceValue") + } + + if id.SqlPoolName != "sqlPoolValue" { + t.Fatalf("Expected %q but got %q for Segment 'SqlPoolName'", id.SqlPoolName, "sqlPoolValue") + } + + if id.SchemaName != "schemaValue" { + t.Fatalf("Expected %q but got %q for Segment 'SchemaName'", id.SchemaName, "schemaValue") + } +} + +func TestFormatSchemaID(t *testing.T) { + actual := NewSchemaID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "sqlPoolValue", "schemaValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/schemas/schemaValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseSchemaID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *SchemaId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/schemas", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/schemas/schemaValue", + Expected: &SchemaId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + SqlPoolName: "sqlPoolValue", + SchemaName: "schemaValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/schemas/schemaValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseSchemaID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + if actual.SqlPoolName != v.Expected.SqlPoolName { + t.Fatalf("Expected %q but got %q for SqlPoolName", v.Expected.SqlPoolName, actual.SqlPoolName) + } + + if actual.SchemaName != v.Expected.SchemaName { + t.Fatalf("Expected %q but got %q for SchemaName", v.Expected.SchemaName, actual.SchemaName) + } + + } +} + +func TestParseSchemaIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *SchemaId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/sQlPoOlS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/sQlPoOlS/sQlPoOlVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/schemas", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/sQlPoOlS/sQlPoOlVaLuE/sChEmAs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/schemas/schemaValue", + Expected: &SchemaId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + SqlPoolName: "sqlPoolValue", + SchemaName: "schemaValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/schemas/schemaValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/sQlPoOlS/sQlPoOlVaLuE/sChEmAs/sChEmAvAlUe", + Expected: &SchemaId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + WorkspaceName: "wOrKsPaCeVaLuE", + SqlPoolName: "sQlPoOlVaLuE", + SchemaName: "sChEmAvAlUe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/sQlPoOlS/sQlPoOlVaLuE/sChEmAs/sChEmAvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseSchemaIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + if actual.SqlPoolName != v.Expected.SqlPoolName { + t.Fatalf("Expected %q but got %q for SqlPoolName", v.Expected.SqlPoolName, actual.SqlPoolName) + } + + if actual.SchemaName != v.Expected.SchemaName { + t.Fatalf("Expected %q but got %q for SchemaName", v.Expected.SchemaName, actual.SchemaName) + } + + } +} + +func TestSegmentsForSchemaId(t *testing.T) { + segments := SchemaId{}.Segments() + if len(segments) == 0 { + t.Fatalf("SchemaId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolssqlpoolschemas/method_sqlpoolschemasget.go b/resource-manager/synapse/2021-06-01/sqlpoolssqlpoolschemas/method_sqlpoolschemasget.go new file mode 100644 index 00000000000..e8ef9f92b5e --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolssqlpoolschemas/method_sqlpoolschemasget.go @@ -0,0 +1,51 @@ +package sqlpoolssqlpoolschemas + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SqlPoolSchemasGetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *Resource +} + +// SqlPoolSchemasGet ... +func (c SqlPoolsSqlPoolSchemasClient) SqlPoolSchemasGet(ctx context.Context, id SchemaId) (result SqlPoolSchemasGetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolssqlpoolschemas/model_resource.go b/resource-manager/synapse/2021-06-01/sqlpoolssqlpoolschemas/model_resource.go new file mode 100644 index 00000000000..64a0fed0589 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolssqlpoolschemas/model_resource.go @@ -0,0 +1,10 @@ +package sqlpoolssqlpoolschemas + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Resource struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolssqlpoolschemas/version.go b/resource-manager/synapse/2021-06-01/sqlpoolssqlpoolschemas/version.go new file mode 100644 index 00000000000..2e2a54329a9 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolssqlpoolschemas/version.go @@ -0,0 +1,12 @@ +package sqlpoolssqlpoolschemas + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2021-06-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/sqlpoolssqlpoolschemas/%s", defaultApiVersion) +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolssqlpooltables/README.md b/resource-manager/synapse/2021-06-01/sqlpoolssqlpooltables/README.md new file mode 100644 index 00000000000..7ee26ac16c6 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolssqlpooltables/README.md @@ -0,0 +1,36 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/synapse/2021-06-01/sqlpoolssqlpooltables` Documentation + +The `sqlpoolssqlpooltables` SDK allows for interaction with the Azure Resource Manager Service `synapse` (API Version `2021-06-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/synapse/2021-06-01/sqlpoolssqlpooltables" +``` + + +### Client Initialization + +```go +client := sqlpoolssqlpooltables.NewSqlPoolsSqlPoolTablesClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `SqlPoolsSqlPoolTablesClient.SqlPoolTablesGet` + +```go +ctx := context.TODO() +id := sqlpoolssqlpooltables.NewTableID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "sqlPoolValue", "schemaValue", "tableValue") + +read, err := client.SqlPoolTablesGet(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` diff --git a/resource-manager/synapse/2021-06-01/sqlpoolssqlpooltables/client.go b/resource-manager/synapse/2021-06-01/sqlpoolssqlpooltables/client.go new file mode 100644 index 00000000000..8801c7801cc --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolssqlpooltables/client.go @@ -0,0 +1,26 @@ +package sqlpoolssqlpooltables + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SqlPoolsSqlPoolTablesClient struct { + Client *resourcemanager.Client +} + +func NewSqlPoolsSqlPoolTablesClientWithBaseURI(sdkApi sdkEnv.Api) (*SqlPoolsSqlPoolTablesClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "sqlpoolssqlpooltables", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating SqlPoolsSqlPoolTablesClient: %+v", err) + } + + return &SqlPoolsSqlPoolTablesClient{ + Client: client, + }, nil +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolssqlpooltables/id_table.go b/resource-manager/synapse/2021-06-01/sqlpoolssqlpooltables/id_table.go new file mode 100644 index 00000000000..0b422d0035c --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolssqlpooltables/id_table.go @@ -0,0 +1,152 @@ +package sqlpoolssqlpooltables + +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 = &TableId{} + +// TableId is a struct representing the Resource ID for a Table +type TableId struct { + SubscriptionId string + ResourceGroupName string + WorkspaceName string + SqlPoolName string + SchemaName string + TableName string +} + +// NewTableID returns a new TableId struct +func NewTableID(subscriptionId string, resourceGroupName string, workspaceName string, sqlPoolName string, schemaName string, tableName string) TableId { + return TableId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + WorkspaceName: workspaceName, + SqlPoolName: sqlPoolName, + SchemaName: schemaName, + TableName: tableName, + } +} + +// ParseTableID parses 'input' into a TableId +func ParseTableID(input string) (*TableId, error) { + parser := resourceids.NewParserFromResourceIdType(&TableId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := TableId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseTableIDInsensitively parses 'input' case-insensitively into a TableId +// note: this method should only be used for API response data and not user input +func ParseTableIDInsensitively(input string) (*TableId, error) { + parser := resourceids.NewParserFromResourceIdType(&TableId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := TableId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *TableId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.WorkspaceName, ok = input.Parsed["workspaceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "workspaceName", input) + } + + if id.SqlPoolName, ok = input.Parsed["sqlPoolName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "sqlPoolName", input) + } + + if id.SchemaName, ok = input.Parsed["schemaName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "schemaName", input) + } + + if id.TableName, ok = input.Parsed["tableName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "tableName", input) + } + + return nil +} + +// ValidateTableID checks that 'input' can be parsed as a Table ID +func ValidateTableID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseTableID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Table ID +func (id TableId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Synapse/workspaces/%s/sqlPools/%s/schemas/%s/tables/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.WorkspaceName, id.SqlPoolName, id.SchemaName, id.TableName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Table ID +func (id TableId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftSynapse", "Microsoft.Synapse", "Microsoft.Synapse"), + resourceids.StaticSegment("staticWorkspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceName", "workspaceValue"), + resourceids.StaticSegment("staticSqlPools", "sqlPools", "sqlPools"), + resourceids.UserSpecifiedSegment("sqlPoolName", "sqlPoolValue"), + resourceids.StaticSegment("staticSchemas", "schemas", "schemas"), + resourceids.UserSpecifiedSegment("schemaName", "schemaValue"), + resourceids.StaticSegment("staticTables", "tables", "tables"), + resourceids.UserSpecifiedSegment("tableName", "tableValue"), + } +} + +// String returns a human-readable description of this Table ID +func (id TableId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Workspace Name: %q", id.WorkspaceName), + fmt.Sprintf("Sql Pool Name: %q", id.SqlPoolName), + fmt.Sprintf("Schema Name: %q", id.SchemaName), + fmt.Sprintf("Table Name: %q", id.TableName), + } + return fmt.Sprintf("Table (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolssqlpooltables/id_table_test.go b/resource-manager/synapse/2021-06-01/sqlpoolssqlpooltables/id_table_test.go new file mode 100644 index 00000000000..ad0b95a9bb3 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolssqlpooltables/id_table_test.go @@ -0,0 +1,417 @@ +package sqlpoolssqlpooltables + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &TableId{} + +func TestNewTableID(t *testing.T) { + id := NewTableID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "sqlPoolValue", "schemaValue", "tableValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.WorkspaceName != "workspaceValue" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceName'", id.WorkspaceName, "workspaceValue") + } + + if id.SqlPoolName != "sqlPoolValue" { + t.Fatalf("Expected %q but got %q for Segment 'SqlPoolName'", id.SqlPoolName, "sqlPoolValue") + } + + if id.SchemaName != "schemaValue" { + t.Fatalf("Expected %q but got %q for Segment 'SchemaName'", id.SchemaName, "schemaValue") + } + + if id.TableName != "tableValue" { + t.Fatalf("Expected %q but got %q for Segment 'TableName'", id.TableName, "tableValue") + } +} + +func TestFormatTableID(t *testing.T) { + actual := NewTableID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "sqlPoolValue", "schemaValue", "tableValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/schemas/schemaValue/tables/tableValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseTableID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *TableId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/schemas", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/schemas/schemaValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/schemas/schemaValue/tables", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/schemas/schemaValue/tables/tableValue", + Expected: &TableId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + SqlPoolName: "sqlPoolValue", + SchemaName: "schemaValue", + TableName: "tableValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/schemas/schemaValue/tables/tableValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseTableID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + if actual.SqlPoolName != v.Expected.SqlPoolName { + t.Fatalf("Expected %q but got %q for SqlPoolName", v.Expected.SqlPoolName, actual.SqlPoolName) + } + + if actual.SchemaName != v.Expected.SchemaName { + t.Fatalf("Expected %q but got %q for SchemaName", v.Expected.SchemaName, actual.SchemaName) + } + + if actual.TableName != v.Expected.TableName { + t.Fatalf("Expected %q but got %q for TableName", v.Expected.TableName, actual.TableName) + } + + } +} + +func TestParseTableIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *TableId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/sQlPoOlS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/sQlPoOlS/sQlPoOlVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/schemas", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/sQlPoOlS/sQlPoOlVaLuE/sChEmAs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/schemas/schemaValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/sQlPoOlS/sQlPoOlVaLuE/sChEmAs/sChEmAvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/schemas/schemaValue/tables", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/sQlPoOlS/sQlPoOlVaLuE/sChEmAs/sChEmAvAlUe/tAbLeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/schemas/schemaValue/tables/tableValue", + Expected: &TableId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + SqlPoolName: "sqlPoolValue", + SchemaName: "schemaValue", + TableName: "tableValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/schemas/schemaValue/tables/tableValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/sQlPoOlS/sQlPoOlVaLuE/sChEmAs/sChEmAvAlUe/tAbLeS/tAbLeVaLuE", + Expected: &TableId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + WorkspaceName: "wOrKsPaCeVaLuE", + SqlPoolName: "sQlPoOlVaLuE", + SchemaName: "sChEmAvAlUe", + TableName: "tAbLeVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/sQlPoOlS/sQlPoOlVaLuE/sChEmAs/sChEmAvAlUe/tAbLeS/tAbLeVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseTableIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + if actual.SqlPoolName != v.Expected.SqlPoolName { + t.Fatalf("Expected %q but got %q for SqlPoolName", v.Expected.SqlPoolName, actual.SqlPoolName) + } + + if actual.SchemaName != v.Expected.SchemaName { + t.Fatalf("Expected %q but got %q for SchemaName", v.Expected.SchemaName, actual.SchemaName) + } + + if actual.TableName != v.Expected.TableName { + t.Fatalf("Expected %q but got %q for TableName", v.Expected.TableName, actual.TableName) + } + + } +} + +func TestSegmentsForTableId(t *testing.T) { + segments := TableId{}.Segments() + if len(segments) == 0 { + t.Fatalf("TableId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolssqlpooltables/method_sqlpooltablesget.go b/resource-manager/synapse/2021-06-01/sqlpoolssqlpooltables/method_sqlpooltablesget.go new file mode 100644 index 00000000000..48dea1607c4 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolssqlpooltables/method_sqlpooltablesget.go @@ -0,0 +1,51 @@ +package sqlpoolssqlpooltables + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SqlPoolTablesGetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *Resource +} + +// SqlPoolTablesGet ... +func (c SqlPoolsSqlPoolTablesClient) SqlPoolTablesGet(ctx context.Context, id TableId) (result SqlPoolTablesGetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolssqlpooltables/model_resource.go b/resource-manager/synapse/2021-06-01/sqlpoolssqlpooltables/model_resource.go new file mode 100644 index 00000000000..922758d2b30 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolssqlpooltables/model_resource.go @@ -0,0 +1,10 @@ +package sqlpoolssqlpooltables + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Resource struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolssqlpooltables/version.go b/resource-manager/synapse/2021-06-01/sqlpoolssqlpooltables/version.go new file mode 100644 index 00000000000..afd66a62595 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolssqlpooltables/version.go @@ -0,0 +1,12 @@ +package sqlpoolssqlpooltables + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2021-06-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/sqlpoolssqlpooltables/%s", defaultApiVersion) +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolssqlpooluseractivities/README.md b/resource-manager/synapse/2021-06-01/sqlpoolssqlpooluseractivities/README.md new file mode 100644 index 00000000000..c0ce598a5e7 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolssqlpooluseractivities/README.md @@ -0,0 +1,36 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/synapse/2021-06-01/sqlpoolssqlpooluseractivities` Documentation + +The `sqlpoolssqlpooluseractivities` SDK allows for interaction with the Azure Resource Manager Service `synapse` (API Version `2021-06-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/synapse/2021-06-01/sqlpoolssqlpooluseractivities" +``` + + +### Client Initialization + +```go +client := sqlpoolssqlpooluseractivities.NewSqlPoolsSqlPoolUserActivitiesClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `SqlPoolsSqlPoolUserActivitiesClient.SqlPoolDataWarehouseUserActivitiesGet` + +```go +ctx := context.TODO() +id := sqlpoolssqlpooluseractivities.NewSqlPoolID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "sqlPoolValue") + +read, err := client.SqlPoolDataWarehouseUserActivitiesGet(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` diff --git a/resource-manager/synapse/2021-06-01/sqlpoolssqlpooluseractivities/client.go b/resource-manager/synapse/2021-06-01/sqlpoolssqlpooluseractivities/client.go new file mode 100644 index 00000000000..bcef6bf0b93 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolssqlpooluseractivities/client.go @@ -0,0 +1,26 @@ +package sqlpoolssqlpooluseractivities + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SqlPoolsSqlPoolUserActivitiesClient struct { + Client *resourcemanager.Client +} + +func NewSqlPoolsSqlPoolUserActivitiesClientWithBaseURI(sdkApi sdkEnv.Api) (*SqlPoolsSqlPoolUserActivitiesClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "sqlpoolssqlpooluseractivities", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating SqlPoolsSqlPoolUserActivitiesClient: %+v", err) + } + + return &SqlPoolsSqlPoolUserActivitiesClient{ + Client: client, + }, nil +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolssqlpooluseractivities/id_sqlpool.go b/resource-manager/synapse/2021-06-01/sqlpoolssqlpooluseractivities/id_sqlpool.go new file mode 100644 index 00000000000..9d73253ad2b --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolssqlpooluseractivities/id_sqlpool.go @@ -0,0 +1,134 @@ +package sqlpoolssqlpooluseractivities + +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 = &SqlPoolId{} + +// SqlPoolId is a struct representing the Resource ID for a Sql Pool +type SqlPoolId struct { + SubscriptionId string + ResourceGroupName string + WorkspaceName string + SqlPoolName string +} + +// NewSqlPoolID returns a new SqlPoolId struct +func NewSqlPoolID(subscriptionId string, resourceGroupName string, workspaceName string, sqlPoolName string) SqlPoolId { + return SqlPoolId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + WorkspaceName: workspaceName, + SqlPoolName: sqlPoolName, + } +} + +// ParseSqlPoolID parses 'input' into a SqlPoolId +func ParseSqlPoolID(input string) (*SqlPoolId, error) { + parser := resourceids.NewParserFromResourceIdType(&SqlPoolId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := SqlPoolId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseSqlPoolIDInsensitively parses 'input' case-insensitively into a SqlPoolId +// note: this method should only be used for API response data and not user input +func ParseSqlPoolIDInsensitively(input string) (*SqlPoolId, error) { + parser := resourceids.NewParserFromResourceIdType(&SqlPoolId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := SqlPoolId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *SqlPoolId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.WorkspaceName, ok = input.Parsed["workspaceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "workspaceName", input) + } + + if id.SqlPoolName, ok = input.Parsed["sqlPoolName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "sqlPoolName", input) + } + + return nil +} + +// ValidateSqlPoolID checks that 'input' can be parsed as a Sql Pool ID +func ValidateSqlPoolID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseSqlPoolID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Sql Pool ID +func (id SqlPoolId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Synapse/workspaces/%s/sqlPools/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.WorkspaceName, id.SqlPoolName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Sql Pool ID +func (id SqlPoolId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftSynapse", "Microsoft.Synapse", "Microsoft.Synapse"), + resourceids.StaticSegment("staticWorkspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceName", "workspaceValue"), + resourceids.StaticSegment("staticSqlPools", "sqlPools", "sqlPools"), + resourceids.UserSpecifiedSegment("sqlPoolName", "sqlPoolValue"), + } +} + +// String returns a human-readable description of this Sql Pool ID +func (id SqlPoolId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Workspace Name: %q", id.WorkspaceName), + fmt.Sprintf("Sql Pool Name: %q", id.SqlPoolName), + } + return fmt.Sprintf("Sql Pool (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolssqlpooluseractivities/id_sqlpool_test.go b/resource-manager/synapse/2021-06-01/sqlpoolssqlpooluseractivities/id_sqlpool_test.go new file mode 100644 index 00000000000..287146f8900 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolssqlpooluseractivities/id_sqlpool_test.go @@ -0,0 +1,327 @@ +package sqlpoolssqlpooluseractivities + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &SqlPoolId{} + +func TestNewSqlPoolID(t *testing.T) { + id := NewSqlPoolID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "sqlPoolValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.WorkspaceName != "workspaceValue" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceName'", id.WorkspaceName, "workspaceValue") + } + + if id.SqlPoolName != "sqlPoolValue" { + t.Fatalf("Expected %q but got %q for Segment 'SqlPoolName'", id.SqlPoolName, "sqlPoolValue") + } +} + +func TestFormatSqlPoolID(t *testing.T) { + actual := NewSqlPoolID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "sqlPoolValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseSqlPoolID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *SqlPoolId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue", + Expected: &SqlPoolId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + SqlPoolName: "sqlPoolValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseSqlPoolID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + if actual.SqlPoolName != v.Expected.SqlPoolName { + t.Fatalf("Expected %q but got %q for SqlPoolName", v.Expected.SqlPoolName, actual.SqlPoolName) + } + + } +} + +func TestParseSqlPoolIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *SqlPoolId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/sQlPoOlS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue", + Expected: &SqlPoolId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + SqlPoolName: "sqlPoolValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/sQlPoOlS/sQlPoOlVaLuE", + Expected: &SqlPoolId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + WorkspaceName: "wOrKsPaCeVaLuE", + SqlPoolName: "sQlPoOlVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/sQlPoOlS/sQlPoOlVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseSqlPoolIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + if actual.SqlPoolName != v.Expected.SqlPoolName { + t.Fatalf("Expected %q but got %q for SqlPoolName", v.Expected.SqlPoolName, actual.SqlPoolName) + } + + } +} + +func TestSegmentsForSqlPoolId(t *testing.T) { + segments := SqlPoolId{}.Segments() + if len(segments) == 0 { + t.Fatalf("SqlPoolId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolssqlpooluseractivities/method_sqlpooldatawarehouseuseractivitiesget.go b/resource-manager/synapse/2021-06-01/sqlpoolssqlpooluseractivities/method_sqlpooldatawarehouseuseractivitiesget.go new file mode 100644 index 00000000000..448ebb13608 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolssqlpooluseractivities/method_sqlpooldatawarehouseuseractivitiesget.go @@ -0,0 +1,52 @@ +package sqlpoolssqlpooluseractivities + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SqlPoolDataWarehouseUserActivitiesGetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *DataWarehouseUserActivities +} + +// SqlPoolDataWarehouseUserActivitiesGet ... +func (c SqlPoolsSqlPoolUserActivitiesClient) SqlPoolDataWarehouseUserActivitiesGet(ctx context.Context, id SqlPoolId) (result SqlPoolDataWarehouseUserActivitiesGetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/dataWarehouseUserActivities/current", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolssqlpooluseractivities/model_datawarehouseuseractivities.go b/resource-manager/synapse/2021-06-01/sqlpoolssqlpooluseractivities/model_datawarehouseuseractivities.go new file mode 100644 index 00000000000..9388ff0efb7 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolssqlpooluseractivities/model_datawarehouseuseractivities.go @@ -0,0 +1,11 @@ +package sqlpoolssqlpooluseractivities + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DataWarehouseUserActivities struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *DataWarehouseUserActivitiesProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolssqlpooluseractivities/model_datawarehouseuseractivitiesproperties.go b/resource-manager/synapse/2021-06-01/sqlpoolssqlpooluseractivities/model_datawarehouseuseractivitiesproperties.go new file mode 100644 index 00000000000..2c415bdbc31 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolssqlpooluseractivities/model_datawarehouseuseractivitiesproperties.go @@ -0,0 +1,8 @@ +package sqlpoolssqlpooluseractivities + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DataWarehouseUserActivitiesProperties struct { + ActiveQueriesCount *int64 `json:"activeQueriesCount,omitempty"` +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolssqlpooluseractivities/version.go b/resource-manager/synapse/2021-06-01/sqlpoolssqlpooluseractivities/version.go new file mode 100644 index 00000000000..99687f5392c --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolssqlpooluseractivities/version.go @@ -0,0 +1,12 @@ +package sqlpoolssqlpooluseractivities + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2021-06-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/sqlpoolssqlpooluseractivities/%s", defaultApiVersion) +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolssqlpoolvulnerabilityassesmentrulebaselines/README.md b/resource-manager/synapse/2021-06-01/sqlpoolssqlpoolvulnerabilityassesmentrulebaselines/README.md new file mode 100644 index 00000000000..6939a2128a1 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolssqlpoolvulnerabilityassesmentrulebaselines/README.md @@ -0,0 +1,36 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/synapse/2021-06-01/sqlpoolssqlpoolvulnerabilityassesmentrulebaselines` Documentation + +The `sqlpoolssqlpoolvulnerabilityassesmentrulebaselines` SDK allows for interaction with the Azure Resource Manager Service `synapse` (API Version `2021-06-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/synapse/2021-06-01/sqlpoolssqlpoolvulnerabilityassesmentrulebaselines" +``` + + +### Client Initialization + +```go +client := sqlpoolssqlpoolvulnerabilityassesmentrulebaselines.NewSqlPoolsSqlPoolVulnerabilityAssesmentRuleBaselinesClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `SqlPoolsSqlPoolVulnerabilityAssesmentRuleBaselinesClient.SqlPoolVulnerabilityAssessmentRuleBaselinesGet` + +```go +ctx := context.TODO() +id := sqlpoolssqlpoolvulnerabilityassesmentrulebaselines.NewBaselineID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "sqlPoolValue", "ruleIdValue", "default") + +read, err := client.SqlPoolVulnerabilityAssessmentRuleBaselinesGet(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` diff --git a/resource-manager/synapse/2021-06-01/sqlpoolssqlpoolvulnerabilityassesmentrulebaselines/client.go b/resource-manager/synapse/2021-06-01/sqlpoolssqlpoolvulnerabilityassesmentrulebaselines/client.go new file mode 100644 index 00000000000..e64c44ab2b5 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolssqlpoolvulnerabilityassesmentrulebaselines/client.go @@ -0,0 +1,26 @@ +package sqlpoolssqlpoolvulnerabilityassesmentrulebaselines + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SqlPoolsSqlPoolVulnerabilityAssesmentRuleBaselinesClient struct { + Client *resourcemanager.Client +} + +func NewSqlPoolsSqlPoolVulnerabilityAssesmentRuleBaselinesClientWithBaseURI(sdkApi sdkEnv.Api) (*SqlPoolsSqlPoolVulnerabilityAssesmentRuleBaselinesClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "sqlpoolssqlpoolvulnerabilityassesmentrulebaselines", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating SqlPoolsSqlPoolVulnerabilityAssesmentRuleBaselinesClient: %+v", err) + } + + return &SqlPoolsSqlPoolVulnerabilityAssesmentRuleBaselinesClient{ + Client: client, + }, nil +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolssqlpoolvulnerabilityassesmentrulebaselines/constants.go b/resource-manager/synapse/2021-06-01/sqlpoolssqlpoolvulnerabilityassesmentrulebaselines/constants.go new file mode 100644 index 00000000000..e977d346ae5 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolssqlpoolvulnerabilityassesmentrulebaselines/constants.go @@ -0,0 +1,51 @@ +package sqlpoolssqlpoolvulnerabilityassesmentrulebaselines + +import ( + "encoding/json" + "fmt" + "strings" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type VulnerabilityAssessmentPolicyBaselineName string + +const ( + VulnerabilityAssessmentPolicyBaselineNameDefault VulnerabilityAssessmentPolicyBaselineName = "default" + VulnerabilityAssessmentPolicyBaselineNameMaster VulnerabilityAssessmentPolicyBaselineName = "master" +) + +func PossibleValuesForVulnerabilityAssessmentPolicyBaselineName() []string { + return []string{ + string(VulnerabilityAssessmentPolicyBaselineNameDefault), + string(VulnerabilityAssessmentPolicyBaselineNameMaster), + } +} + +func (s *VulnerabilityAssessmentPolicyBaselineName) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseVulnerabilityAssessmentPolicyBaselineName(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseVulnerabilityAssessmentPolicyBaselineName(input string) (*VulnerabilityAssessmentPolicyBaselineName, error) { + vals := map[string]VulnerabilityAssessmentPolicyBaselineName{ + "default": VulnerabilityAssessmentPolicyBaselineNameDefault, + "master": VulnerabilityAssessmentPolicyBaselineNameMaster, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := VulnerabilityAssessmentPolicyBaselineName(input) + return &out, nil +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolssqlpoolvulnerabilityassesmentrulebaselines/id_baseline.go b/resource-manager/synapse/2021-06-01/sqlpoolssqlpoolvulnerabilityassesmentrulebaselines/id_baseline.go new file mode 100644 index 00000000000..895e7e66dbe --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolssqlpoolvulnerabilityassesmentrulebaselines/id_baseline.go @@ -0,0 +1,162 @@ +package sqlpoolssqlpoolvulnerabilityassesmentrulebaselines + +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 = &BaselineId{} + +// BaselineId is a struct representing the Resource ID for a Baseline +type BaselineId struct { + SubscriptionId string + ResourceGroupName string + WorkspaceName string + SqlPoolName string + RuleId string + BaselineName VulnerabilityAssessmentPolicyBaselineName +} + +// NewBaselineID returns a new BaselineId struct +func NewBaselineID(subscriptionId string, resourceGroupName string, workspaceName string, sqlPoolName string, ruleId string, baselineName VulnerabilityAssessmentPolicyBaselineName) BaselineId { + return BaselineId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + WorkspaceName: workspaceName, + SqlPoolName: sqlPoolName, + RuleId: ruleId, + BaselineName: baselineName, + } +} + +// ParseBaselineID parses 'input' into a BaselineId +func ParseBaselineID(input string) (*BaselineId, error) { + parser := resourceids.NewParserFromResourceIdType(&BaselineId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := BaselineId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseBaselineIDInsensitively parses 'input' case-insensitively into a BaselineId +// note: this method should only be used for API response data and not user input +func ParseBaselineIDInsensitively(input string) (*BaselineId, error) { + parser := resourceids.NewParserFromResourceIdType(&BaselineId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := BaselineId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *BaselineId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.WorkspaceName, ok = input.Parsed["workspaceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "workspaceName", input) + } + + if id.SqlPoolName, ok = input.Parsed["sqlPoolName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "sqlPoolName", input) + } + + if id.RuleId, ok = input.Parsed["ruleId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "ruleId", input) + } + + if v, ok := input.Parsed["baselineName"]; true { + if !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "baselineName", input) + } + + baselineName, err := parseVulnerabilityAssessmentPolicyBaselineName(v) + if err != nil { + return fmt.Errorf("parsing %q: %+v", v, err) + } + id.BaselineName = *baselineName + } + + return nil +} + +// ValidateBaselineID checks that 'input' can be parsed as a Baseline ID +func ValidateBaselineID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseBaselineID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Baseline ID +func (id BaselineId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Synapse/workspaces/%s/sqlPools/%s/vulnerabilityAssessments/default/rules/%s/baselines/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.WorkspaceName, id.SqlPoolName, id.RuleId, string(id.BaselineName)) +} + +// Segments returns a slice of Resource ID Segments which comprise this Baseline ID +func (id BaselineId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftSynapse", "Microsoft.Synapse", "Microsoft.Synapse"), + resourceids.StaticSegment("staticWorkspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceName", "workspaceValue"), + resourceids.StaticSegment("staticSqlPools", "sqlPools", "sqlPools"), + resourceids.UserSpecifiedSegment("sqlPoolName", "sqlPoolValue"), + resourceids.StaticSegment("staticVulnerabilityAssessments", "vulnerabilityAssessments", "vulnerabilityAssessments"), + resourceids.StaticSegment("vulnerabilityAssessmentName", "default", "default"), + resourceids.StaticSegment("staticRules", "rules", "rules"), + resourceids.UserSpecifiedSegment("ruleId", "ruleIdValue"), + resourceids.StaticSegment("staticBaselines", "baselines", "baselines"), + resourceids.ConstantSegment("baselineName", PossibleValuesForVulnerabilityAssessmentPolicyBaselineName(), "default"), + } +} + +// String returns a human-readable description of this Baseline ID +func (id BaselineId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Workspace Name: %q", id.WorkspaceName), + fmt.Sprintf("Sql Pool Name: %q", id.SqlPoolName), + fmt.Sprintf("Rule: %q", id.RuleId), + fmt.Sprintf("Baseline Name: %q", string(id.BaselineName)), + } + return fmt.Sprintf("Baseline (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolssqlpoolvulnerabilityassesmentrulebaselines/id_baseline_test.go b/resource-manager/synapse/2021-06-01/sqlpoolssqlpoolvulnerabilityassesmentrulebaselines/id_baseline_test.go new file mode 100644 index 00000000000..5bbe1e80231 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolssqlpoolvulnerabilityassesmentrulebaselines/id_baseline_test.go @@ -0,0 +1,447 @@ +package sqlpoolssqlpoolvulnerabilityassesmentrulebaselines + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &BaselineId{} + +func TestNewBaselineID(t *testing.T) { + id := NewBaselineID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "sqlPoolValue", "ruleIdValue", "default") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.WorkspaceName != "workspaceValue" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceName'", id.WorkspaceName, "workspaceValue") + } + + if id.SqlPoolName != "sqlPoolValue" { + t.Fatalf("Expected %q but got %q for Segment 'SqlPoolName'", id.SqlPoolName, "sqlPoolValue") + } + + if id.RuleId != "ruleIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'RuleId'", id.RuleId, "ruleIdValue") + } + + if id.BaselineName != "default" { + t.Fatalf("Expected %q but got %q for Segment 'BaselineName'", id.BaselineName, "default") + } +} + +func TestFormatBaselineID(t *testing.T) { + actual := NewBaselineID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "sqlPoolValue", "ruleIdValue", "default").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/vulnerabilityAssessments/default/rules/ruleIdValue/baselines/default" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseBaselineID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *BaselineId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/vulnerabilityAssessments", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/vulnerabilityAssessments/default", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/vulnerabilityAssessments/default/rules", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/vulnerabilityAssessments/default/rules/ruleIdValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/vulnerabilityAssessments/default/rules/ruleIdValue/baselines", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/vulnerabilityAssessments/default/rules/ruleIdValue/baselines/default", + Expected: &BaselineId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + SqlPoolName: "sqlPoolValue", + RuleId: "ruleIdValue", + BaselineName: "default", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/vulnerabilityAssessments/default/rules/ruleIdValue/baselines/default/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseBaselineID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + if actual.SqlPoolName != v.Expected.SqlPoolName { + t.Fatalf("Expected %q but got %q for SqlPoolName", v.Expected.SqlPoolName, actual.SqlPoolName) + } + + if actual.RuleId != v.Expected.RuleId { + t.Fatalf("Expected %q but got %q for RuleId", v.Expected.RuleId, actual.RuleId) + } + + if actual.BaselineName != v.Expected.BaselineName { + t.Fatalf("Expected %q but got %q for BaselineName", v.Expected.BaselineName, actual.BaselineName) + } + + } +} + +func TestParseBaselineIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *BaselineId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/sQlPoOlS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/sQlPoOlS/sQlPoOlVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/vulnerabilityAssessments", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/sQlPoOlS/sQlPoOlVaLuE/vUlNeRaBiLiTyAsSeSsMeNtS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/vulnerabilityAssessments/default", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/sQlPoOlS/sQlPoOlVaLuE/vUlNeRaBiLiTyAsSeSsMeNtS/dEfAuLt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/vulnerabilityAssessments/default/rules", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/sQlPoOlS/sQlPoOlVaLuE/vUlNeRaBiLiTyAsSeSsMeNtS/dEfAuLt/rUlEs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/vulnerabilityAssessments/default/rules/ruleIdValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/sQlPoOlS/sQlPoOlVaLuE/vUlNeRaBiLiTyAsSeSsMeNtS/dEfAuLt/rUlEs/rUlEiDvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/vulnerabilityAssessments/default/rules/ruleIdValue/baselines", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/sQlPoOlS/sQlPoOlVaLuE/vUlNeRaBiLiTyAsSeSsMeNtS/dEfAuLt/rUlEs/rUlEiDvAlUe/bAsElInEs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/vulnerabilityAssessments/default/rules/ruleIdValue/baselines/default", + Expected: &BaselineId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + SqlPoolName: "sqlPoolValue", + RuleId: "ruleIdValue", + BaselineName: "default", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/vulnerabilityAssessments/default/rules/ruleIdValue/baselines/default/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/sQlPoOlS/sQlPoOlVaLuE/vUlNeRaBiLiTyAsSeSsMeNtS/dEfAuLt/rUlEs/rUlEiDvAlUe/bAsElInEs/dEfAuLt", + Expected: &BaselineId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + WorkspaceName: "wOrKsPaCeVaLuE", + SqlPoolName: "sQlPoOlVaLuE", + RuleId: "rUlEiDvAlUe", + BaselineName: "default", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/sQlPoOlS/sQlPoOlVaLuE/vUlNeRaBiLiTyAsSeSsMeNtS/dEfAuLt/rUlEs/rUlEiDvAlUe/bAsElInEs/dEfAuLt/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseBaselineIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + if actual.SqlPoolName != v.Expected.SqlPoolName { + t.Fatalf("Expected %q but got %q for SqlPoolName", v.Expected.SqlPoolName, actual.SqlPoolName) + } + + if actual.RuleId != v.Expected.RuleId { + t.Fatalf("Expected %q but got %q for RuleId", v.Expected.RuleId, actual.RuleId) + } + + if actual.BaselineName != v.Expected.BaselineName { + t.Fatalf("Expected %q but got %q for BaselineName", v.Expected.BaselineName, actual.BaselineName) + } + + } +} + +func TestSegmentsForBaselineId(t *testing.T) { + segments := BaselineId{}.Segments() + if len(segments) == 0 { + t.Fatalf("BaselineId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolssqlpoolvulnerabilityassesmentrulebaselines/method_sqlpoolvulnerabilityassessmentrulebaselinesget.go b/resource-manager/synapse/2021-06-01/sqlpoolssqlpoolvulnerabilityassesmentrulebaselines/method_sqlpoolvulnerabilityassessmentrulebaselinesget.go new file mode 100644 index 00000000000..f16880001cf --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolssqlpoolvulnerabilityassesmentrulebaselines/method_sqlpoolvulnerabilityassessmentrulebaselinesget.go @@ -0,0 +1,51 @@ +package sqlpoolssqlpoolvulnerabilityassesmentrulebaselines + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SqlPoolVulnerabilityAssessmentRuleBaselinesGetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *SqlPoolVulnerabilityAssessmentRuleBaseline +} + +// SqlPoolVulnerabilityAssessmentRuleBaselinesGet ... +func (c SqlPoolsSqlPoolVulnerabilityAssesmentRuleBaselinesClient) SqlPoolVulnerabilityAssessmentRuleBaselinesGet(ctx context.Context, id BaselineId) (result SqlPoolVulnerabilityAssessmentRuleBaselinesGetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolssqlpoolvulnerabilityassesmentrulebaselines/model_sqlpoolvulnerabilityassessmentrulebaseline.go b/resource-manager/synapse/2021-06-01/sqlpoolssqlpoolvulnerabilityassesmentrulebaselines/model_sqlpoolvulnerabilityassessmentrulebaseline.go new file mode 100644 index 00000000000..735f03f35a7 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolssqlpoolvulnerabilityassesmentrulebaselines/model_sqlpoolvulnerabilityassessmentrulebaseline.go @@ -0,0 +1,11 @@ +package sqlpoolssqlpoolvulnerabilityassesmentrulebaselines + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SqlPoolVulnerabilityAssessmentRuleBaseline struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *SqlPoolVulnerabilityAssessmentRuleBaselineProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolssqlpoolvulnerabilityassesmentrulebaselines/model_sqlpoolvulnerabilityassessmentrulebaselineitem.go b/resource-manager/synapse/2021-06-01/sqlpoolssqlpoolvulnerabilityassesmentrulebaselines/model_sqlpoolvulnerabilityassessmentrulebaselineitem.go new file mode 100644 index 00000000000..e5831c91485 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolssqlpoolvulnerabilityassesmentrulebaselines/model_sqlpoolvulnerabilityassessmentrulebaselineitem.go @@ -0,0 +1,8 @@ +package sqlpoolssqlpoolvulnerabilityassesmentrulebaselines + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SqlPoolVulnerabilityAssessmentRuleBaselineItem struct { + Result []string `json:"result"` +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolssqlpoolvulnerabilityassesmentrulebaselines/model_sqlpoolvulnerabilityassessmentrulebaselineproperties.go b/resource-manager/synapse/2021-06-01/sqlpoolssqlpoolvulnerabilityassesmentrulebaselines/model_sqlpoolvulnerabilityassessmentrulebaselineproperties.go new file mode 100644 index 00000000000..df7a193525c --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolssqlpoolvulnerabilityassesmentrulebaselines/model_sqlpoolvulnerabilityassessmentrulebaselineproperties.go @@ -0,0 +1,8 @@ +package sqlpoolssqlpoolvulnerabilityassesmentrulebaselines + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SqlPoolVulnerabilityAssessmentRuleBaselineProperties struct { + BaselineResults []SqlPoolVulnerabilityAssessmentRuleBaselineItem `json:"baselineResults"` +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolssqlpoolvulnerabilityassesmentrulebaselines/version.go b/resource-manager/synapse/2021-06-01/sqlpoolssqlpoolvulnerabilityassesmentrulebaselines/version.go new file mode 100644 index 00000000000..0507b4a42fd --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolssqlpoolvulnerabilityassesmentrulebaselines/version.go @@ -0,0 +1,12 @@ +package sqlpoolssqlpoolvulnerabilityassesmentrulebaselines + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2021-06-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/sqlpoolssqlpoolvulnerabilityassesmentrulebaselines/%s", defaultApiVersion) +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolssqlpoolvulnerabilityassessmentscans/README.md b/resource-manager/synapse/2021-06-01/sqlpoolssqlpoolvulnerabilityassessmentscans/README.md new file mode 100644 index 00000000000..e1221e916b6 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolssqlpoolvulnerabilityassessmentscans/README.md @@ -0,0 +1,36 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/synapse/2021-06-01/sqlpoolssqlpoolvulnerabilityassessmentscans` Documentation + +The `sqlpoolssqlpoolvulnerabilityassessmentscans` SDK allows for interaction with the Azure Resource Manager Service `synapse` (API Version `2021-06-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/synapse/2021-06-01/sqlpoolssqlpoolvulnerabilityassessmentscans" +``` + + +### Client Initialization + +```go +client := sqlpoolssqlpoolvulnerabilityassessmentscans.NewSqlPoolsSqlPoolVulnerabilityAssessmentScansClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `SqlPoolsSqlPoolVulnerabilityAssessmentScansClient.SqlPoolVulnerabilityAssessmentScansGet` + +```go +ctx := context.TODO() +id := sqlpoolssqlpoolvulnerabilityassessmentscans.NewScanID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "sqlPoolValue", "scanIdValue") + +read, err := client.SqlPoolVulnerabilityAssessmentScansGet(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` diff --git a/resource-manager/synapse/2021-06-01/sqlpoolssqlpoolvulnerabilityassessmentscans/client.go b/resource-manager/synapse/2021-06-01/sqlpoolssqlpoolvulnerabilityassessmentscans/client.go new file mode 100644 index 00000000000..4c9daed9338 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolssqlpoolvulnerabilityassessmentscans/client.go @@ -0,0 +1,26 @@ +package sqlpoolssqlpoolvulnerabilityassessmentscans + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SqlPoolsSqlPoolVulnerabilityAssessmentScansClient struct { + Client *resourcemanager.Client +} + +func NewSqlPoolsSqlPoolVulnerabilityAssessmentScansClientWithBaseURI(sdkApi sdkEnv.Api) (*SqlPoolsSqlPoolVulnerabilityAssessmentScansClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "sqlpoolssqlpoolvulnerabilityassessmentscans", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating SqlPoolsSqlPoolVulnerabilityAssessmentScansClient: %+v", err) + } + + return &SqlPoolsSqlPoolVulnerabilityAssessmentScansClient{ + Client: client, + }, nil +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolssqlpoolvulnerabilityassessmentscans/constants.go b/resource-manager/synapse/2021-06-01/sqlpoolssqlpoolvulnerabilityassessmentscans/constants.go new file mode 100644 index 00000000000..0319fb5f8db --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolssqlpoolvulnerabilityassessmentscans/constants.go @@ -0,0 +1,98 @@ +package sqlpoolssqlpoolvulnerabilityassessmentscans + +import ( + "encoding/json" + "fmt" + "strings" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type VulnerabilityAssessmentScanState string + +const ( + VulnerabilityAssessmentScanStateFailed VulnerabilityAssessmentScanState = "Failed" + VulnerabilityAssessmentScanStateFailedToRun VulnerabilityAssessmentScanState = "FailedToRun" + VulnerabilityAssessmentScanStateInProgress VulnerabilityAssessmentScanState = "InProgress" + VulnerabilityAssessmentScanStatePassed VulnerabilityAssessmentScanState = "Passed" +) + +func PossibleValuesForVulnerabilityAssessmentScanState() []string { + return []string{ + string(VulnerabilityAssessmentScanStateFailed), + string(VulnerabilityAssessmentScanStateFailedToRun), + string(VulnerabilityAssessmentScanStateInProgress), + string(VulnerabilityAssessmentScanStatePassed), + } +} + +func (s *VulnerabilityAssessmentScanState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseVulnerabilityAssessmentScanState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseVulnerabilityAssessmentScanState(input string) (*VulnerabilityAssessmentScanState, error) { + vals := map[string]VulnerabilityAssessmentScanState{ + "failed": VulnerabilityAssessmentScanStateFailed, + "failedtorun": VulnerabilityAssessmentScanStateFailedToRun, + "inprogress": VulnerabilityAssessmentScanStateInProgress, + "passed": VulnerabilityAssessmentScanStatePassed, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := VulnerabilityAssessmentScanState(input) + return &out, nil +} + +type VulnerabilityAssessmentScanTriggerType string + +const ( + VulnerabilityAssessmentScanTriggerTypeOnDemand VulnerabilityAssessmentScanTriggerType = "OnDemand" + VulnerabilityAssessmentScanTriggerTypeRecurring VulnerabilityAssessmentScanTriggerType = "Recurring" +) + +func PossibleValuesForVulnerabilityAssessmentScanTriggerType() []string { + return []string{ + string(VulnerabilityAssessmentScanTriggerTypeOnDemand), + string(VulnerabilityAssessmentScanTriggerTypeRecurring), + } +} + +func (s *VulnerabilityAssessmentScanTriggerType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseVulnerabilityAssessmentScanTriggerType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseVulnerabilityAssessmentScanTriggerType(input string) (*VulnerabilityAssessmentScanTriggerType, error) { + vals := map[string]VulnerabilityAssessmentScanTriggerType{ + "ondemand": VulnerabilityAssessmentScanTriggerTypeOnDemand, + "recurring": VulnerabilityAssessmentScanTriggerTypeRecurring, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := VulnerabilityAssessmentScanTriggerType(input) + return &out, nil +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolssqlpoolvulnerabilityassessmentscans/id_scan.go b/resource-manager/synapse/2021-06-01/sqlpoolssqlpoolvulnerabilityassessmentscans/id_scan.go new file mode 100644 index 00000000000..98d2f0815a2 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolssqlpoolvulnerabilityassessmentscans/id_scan.go @@ -0,0 +1,145 @@ +package sqlpoolssqlpoolvulnerabilityassessmentscans + +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 = &ScanId{} + +// ScanId is a struct representing the Resource ID for a Scan +type ScanId struct { + SubscriptionId string + ResourceGroupName string + WorkspaceName string + SqlPoolName string + ScanId string +} + +// NewScanID returns a new ScanId struct +func NewScanID(subscriptionId string, resourceGroupName string, workspaceName string, sqlPoolName string, scanId string) ScanId { + return ScanId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + WorkspaceName: workspaceName, + SqlPoolName: sqlPoolName, + ScanId: scanId, + } +} + +// ParseScanID parses 'input' into a ScanId +func ParseScanID(input string) (*ScanId, error) { + parser := resourceids.NewParserFromResourceIdType(&ScanId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ScanId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseScanIDInsensitively parses 'input' case-insensitively into a ScanId +// note: this method should only be used for API response data and not user input +func ParseScanIDInsensitively(input string) (*ScanId, error) { + parser := resourceids.NewParserFromResourceIdType(&ScanId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ScanId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ScanId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.WorkspaceName, ok = input.Parsed["workspaceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "workspaceName", input) + } + + if id.SqlPoolName, ok = input.Parsed["sqlPoolName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "sqlPoolName", input) + } + + if id.ScanId, ok = input.Parsed["scanId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "scanId", input) + } + + return nil +} + +// ValidateScanID checks that 'input' can be parsed as a Scan ID +func ValidateScanID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseScanID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Scan ID +func (id ScanId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Synapse/workspaces/%s/sqlPools/%s/vulnerabilityAssessments/default/scans/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.WorkspaceName, id.SqlPoolName, id.ScanId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Scan ID +func (id ScanId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftSynapse", "Microsoft.Synapse", "Microsoft.Synapse"), + resourceids.StaticSegment("staticWorkspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceName", "workspaceValue"), + resourceids.StaticSegment("staticSqlPools", "sqlPools", "sqlPools"), + resourceids.UserSpecifiedSegment("sqlPoolName", "sqlPoolValue"), + resourceids.StaticSegment("staticVulnerabilityAssessments", "vulnerabilityAssessments", "vulnerabilityAssessments"), + resourceids.StaticSegment("vulnerabilityAssessmentName", "default", "default"), + resourceids.StaticSegment("staticScans", "scans", "scans"), + resourceids.UserSpecifiedSegment("scanId", "scanIdValue"), + } +} + +// String returns a human-readable description of this Scan ID +func (id ScanId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Workspace Name: %q", id.WorkspaceName), + fmt.Sprintf("Sql Pool Name: %q", id.SqlPoolName), + fmt.Sprintf("Scan: %q", id.ScanId), + } + return fmt.Sprintf("Scan (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolssqlpoolvulnerabilityassessmentscans/id_scan_test.go b/resource-manager/synapse/2021-06-01/sqlpoolssqlpoolvulnerabilityassessmentscans/id_scan_test.go new file mode 100644 index 00000000000..b819985ae1f --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolssqlpoolvulnerabilityassessmentscans/id_scan_test.go @@ -0,0 +1,402 @@ +package sqlpoolssqlpoolvulnerabilityassessmentscans + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &ScanId{} + +func TestNewScanID(t *testing.T) { + id := NewScanID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "sqlPoolValue", "scanIdValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.WorkspaceName != "workspaceValue" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceName'", id.WorkspaceName, "workspaceValue") + } + + if id.SqlPoolName != "sqlPoolValue" { + t.Fatalf("Expected %q but got %q for Segment 'SqlPoolName'", id.SqlPoolName, "sqlPoolValue") + } + + if id.ScanId != "scanIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'ScanId'", id.ScanId, "scanIdValue") + } +} + +func TestFormatScanID(t *testing.T) { + actual := NewScanID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "sqlPoolValue", "scanIdValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/vulnerabilityAssessments/default/scans/scanIdValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseScanID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ScanId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/vulnerabilityAssessments", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/vulnerabilityAssessments/default", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/vulnerabilityAssessments/default/scans", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/vulnerabilityAssessments/default/scans/scanIdValue", + Expected: &ScanId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + SqlPoolName: "sqlPoolValue", + ScanId: "scanIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/vulnerabilityAssessments/default/scans/scanIdValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseScanID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + if actual.SqlPoolName != v.Expected.SqlPoolName { + t.Fatalf("Expected %q but got %q for SqlPoolName", v.Expected.SqlPoolName, actual.SqlPoolName) + } + + if actual.ScanId != v.Expected.ScanId { + t.Fatalf("Expected %q but got %q for ScanId", v.Expected.ScanId, actual.ScanId) + } + + } +} + +func TestParseScanIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ScanId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/sQlPoOlS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/sQlPoOlS/sQlPoOlVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/vulnerabilityAssessments", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/sQlPoOlS/sQlPoOlVaLuE/vUlNeRaBiLiTyAsSeSsMeNtS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/vulnerabilityAssessments/default", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/sQlPoOlS/sQlPoOlVaLuE/vUlNeRaBiLiTyAsSeSsMeNtS/dEfAuLt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/vulnerabilityAssessments/default/scans", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/sQlPoOlS/sQlPoOlVaLuE/vUlNeRaBiLiTyAsSeSsMeNtS/dEfAuLt/sCaNs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/vulnerabilityAssessments/default/scans/scanIdValue", + Expected: &ScanId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + SqlPoolName: "sqlPoolValue", + ScanId: "scanIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/vulnerabilityAssessments/default/scans/scanIdValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/sQlPoOlS/sQlPoOlVaLuE/vUlNeRaBiLiTyAsSeSsMeNtS/dEfAuLt/sCaNs/sCaNiDvAlUe", + Expected: &ScanId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + WorkspaceName: "wOrKsPaCeVaLuE", + SqlPoolName: "sQlPoOlVaLuE", + ScanId: "sCaNiDvAlUe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/sQlPoOlS/sQlPoOlVaLuE/vUlNeRaBiLiTyAsSeSsMeNtS/dEfAuLt/sCaNs/sCaNiDvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseScanIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + if actual.SqlPoolName != v.Expected.SqlPoolName { + t.Fatalf("Expected %q but got %q for SqlPoolName", v.Expected.SqlPoolName, actual.SqlPoolName) + } + + if actual.ScanId != v.Expected.ScanId { + t.Fatalf("Expected %q but got %q for ScanId", v.Expected.ScanId, actual.ScanId) + } + + } +} + +func TestSegmentsForScanId(t *testing.T) { + segments := ScanId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ScanId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolssqlpoolvulnerabilityassessmentscans/method_sqlpoolvulnerabilityassessmentscansget.go b/resource-manager/synapse/2021-06-01/sqlpoolssqlpoolvulnerabilityassessmentscans/method_sqlpoolvulnerabilityassessmentscansget.go new file mode 100644 index 00000000000..08e763acd78 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolssqlpoolvulnerabilityassessmentscans/method_sqlpoolvulnerabilityassessmentscansget.go @@ -0,0 +1,51 @@ +package sqlpoolssqlpoolvulnerabilityassessmentscans + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SqlPoolVulnerabilityAssessmentScansGetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *VulnerabilityAssessmentScanRecord +} + +// SqlPoolVulnerabilityAssessmentScansGet ... +func (c SqlPoolsSqlPoolVulnerabilityAssessmentScansClient) SqlPoolVulnerabilityAssessmentScansGet(ctx context.Context, id ScanId) (result SqlPoolVulnerabilityAssessmentScansGetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolssqlpoolvulnerabilityassessmentscans/model_vulnerabilityassessmentscanerror.go b/resource-manager/synapse/2021-06-01/sqlpoolssqlpoolvulnerabilityassessmentscans/model_vulnerabilityassessmentscanerror.go new file mode 100644 index 00000000000..d181f978701 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolssqlpoolvulnerabilityassessmentscans/model_vulnerabilityassessmentscanerror.go @@ -0,0 +1,9 @@ +package sqlpoolssqlpoolvulnerabilityassessmentscans + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type VulnerabilityAssessmentScanError struct { + Code *string `json:"code,omitempty"` + Message *string `json:"message,omitempty"` +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolssqlpoolvulnerabilityassessmentscans/model_vulnerabilityassessmentscanrecord.go b/resource-manager/synapse/2021-06-01/sqlpoolssqlpoolvulnerabilityassessmentscans/model_vulnerabilityassessmentscanrecord.go new file mode 100644 index 00000000000..7ce7465c06f --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolssqlpoolvulnerabilityassessmentscans/model_vulnerabilityassessmentscanrecord.go @@ -0,0 +1,11 @@ +package sqlpoolssqlpoolvulnerabilityassessmentscans + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type VulnerabilityAssessmentScanRecord struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *VulnerabilityAssessmentScanRecordProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolssqlpoolvulnerabilityassessmentscans/model_vulnerabilityassessmentscanrecordproperties.go b/resource-manager/synapse/2021-06-01/sqlpoolssqlpoolvulnerabilityassessmentscans/model_vulnerabilityassessmentscanrecordproperties.go new file mode 100644 index 00000000000..efaecd7f71c --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolssqlpoolvulnerabilityassessmentscans/model_vulnerabilityassessmentscanrecordproperties.go @@ -0,0 +1,45 @@ +package sqlpoolssqlpoolvulnerabilityassessmentscans + +import ( + "time" + + "github.com/hashicorp/go-azure-helpers/lang/dates" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type VulnerabilityAssessmentScanRecordProperties struct { + EndTime *string `json:"endTime,omitempty"` + Errors *[]VulnerabilityAssessmentScanError `json:"errors,omitempty"` + NumberOfFailedSecurityChecks *int64 `json:"numberOfFailedSecurityChecks,omitempty"` + ScanId *string `json:"scanId,omitempty"` + StartTime *string `json:"startTime,omitempty"` + State *VulnerabilityAssessmentScanState `json:"state,omitempty"` + StorageContainerPath *string `json:"storageContainerPath,omitempty"` + TriggerType *VulnerabilityAssessmentScanTriggerType `json:"triggerType,omitempty"` +} + +func (o *VulnerabilityAssessmentScanRecordProperties) GetEndTimeAsTime() (*time.Time, error) { + if o.EndTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.EndTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *VulnerabilityAssessmentScanRecordProperties) SetEndTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.EndTime = &formatted +} + +func (o *VulnerabilityAssessmentScanRecordProperties) GetStartTimeAsTime() (*time.Time, error) { + if o.StartTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.StartTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *VulnerabilityAssessmentScanRecordProperties) SetStartTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.StartTime = &formatted +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolssqlpoolvulnerabilityassessmentscans/version.go b/resource-manager/synapse/2021-06-01/sqlpoolssqlpoolvulnerabilityassessmentscans/version.go new file mode 100644 index 00000000000..9f183896ef4 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolssqlpoolvulnerabilityassessmentscans/version.go @@ -0,0 +1,12 @@ +package sqlpoolssqlpoolvulnerabilityassessmentscans + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2021-06-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/sqlpoolssqlpoolvulnerabilityassessmentscans/%s", defaultApiVersion) +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolstables/README.md b/resource-manager/synapse/2021-06-01/sqlpoolstables/README.md new file mode 100644 index 00000000000..b37b4af6e30 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolstables/README.md @@ -0,0 +1,54 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/synapse/2021-06-01/sqlpoolstables` Documentation + +The `sqlpoolstables` SDK allows for interaction with the Azure Resource Manager Service `synapse` (API Version `2021-06-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/synapse/2021-06-01/sqlpoolstables" +``` + + +### Client Initialization + +```go +client := sqlpoolstables.NewSqlPoolsTablesClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `SqlPoolsTablesClient.SqlPoolTableColumnsListByTableName` + +```go +ctx := context.TODO() +id := sqlpoolstables.NewTableID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "sqlPoolValue", "schemaValue", "tableValue") + +// alternatively `client.SqlPoolTableColumnsListByTableName(ctx, id, sqlpoolstables.DefaultSqlPoolTableColumnsListByTableNameOperationOptions())` can be used to do batched pagination +items, err := client.SqlPoolTableColumnsListByTableNameComplete(ctx, id, sqlpoolstables.DefaultSqlPoolTableColumnsListByTableNameOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `SqlPoolsTablesClient.SqlPoolTablesListBySchema` + +```go +ctx := context.TODO() +id := sqlpoolstables.NewSchemaID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "sqlPoolValue", "schemaValue") + +// alternatively `client.SqlPoolTablesListBySchema(ctx, id, sqlpoolstables.DefaultSqlPoolTablesListBySchemaOperationOptions())` can be used to do batched pagination +items, err := client.SqlPoolTablesListBySchemaComplete(ctx, id, sqlpoolstables.DefaultSqlPoolTablesListBySchemaOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/synapse/2021-06-01/sqlpoolstables/client.go b/resource-manager/synapse/2021-06-01/sqlpoolstables/client.go new file mode 100644 index 00000000000..b7d0f6e66b3 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolstables/client.go @@ -0,0 +1,26 @@ +package sqlpoolstables + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SqlPoolsTablesClient struct { + Client *resourcemanager.Client +} + +func NewSqlPoolsTablesClientWithBaseURI(sdkApi sdkEnv.Api) (*SqlPoolsTablesClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "sqlpoolstables", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating SqlPoolsTablesClient: %+v", err) + } + + return &SqlPoolsTablesClient{ + Client: client, + }, nil +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolstables/constants.go b/resource-manager/synapse/2021-06-01/sqlpoolstables/constants.go new file mode 100644 index 00000000000..03a8bae4fbe --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolstables/constants.go @@ -0,0 +1,147 @@ +package sqlpoolstables + +import ( + "encoding/json" + "fmt" + "strings" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ColumnDataType string + +const ( + ColumnDataTypeBigint ColumnDataType = "bigint" + ColumnDataTypeBinary ColumnDataType = "binary" + ColumnDataTypeBit ColumnDataType = "bit" + ColumnDataTypeChar ColumnDataType = "char" + ColumnDataTypeDate ColumnDataType = "date" + ColumnDataTypeDatetime ColumnDataType = "datetime" + ColumnDataTypeDatetimeTwo ColumnDataType = "datetime2" + ColumnDataTypeDatetimeoffset ColumnDataType = "datetimeoffset" + ColumnDataTypeDecimal ColumnDataType = "decimal" + ColumnDataTypeFloat ColumnDataType = "float" + ColumnDataTypeGeography ColumnDataType = "geography" + ColumnDataTypeGeometry ColumnDataType = "geometry" + ColumnDataTypeHierarchyid ColumnDataType = "hierarchyid" + ColumnDataTypeImage ColumnDataType = "image" + ColumnDataTypeInt ColumnDataType = "int" + ColumnDataTypeMoney ColumnDataType = "money" + ColumnDataTypeNchar ColumnDataType = "nchar" + ColumnDataTypeNtext ColumnDataType = "ntext" + ColumnDataTypeNumeric ColumnDataType = "numeric" + ColumnDataTypeNvarchar ColumnDataType = "nvarchar" + ColumnDataTypeReal ColumnDataType = "real" + ColumnDataTypeSmalldatetime ColumnDataType = "smalldatetime" + ColumnDataTypeSmallint ColumnDataType = "smallint" + ColumnDataTypeSmallmoney ColumnDataType = "smallmoney" + ColumnDataTypeSqlVariant ColumnDataType = "sql_variant" + ColumnDataTypeSysname ColumnDataType = "sysname" + ColumnDataTypeText ColumnDataType = "text" + ColumnDataTypeTime ColumnDataType = "time" + ColumnDataTypeTimestamp ColumnDataType = "timestamp" + ColumnDataTypeTinyint ColumnDataType = "tinyint" + ColumnDataTypeUniqueidentifier ColumnDataType = "uniqueidentifier" + ColumnDataTypeVarbinary ColumnDataType = "varbinary" + ColumnDataTypeVarchar ColumnDataType = "varchar" + ColumnDataTypeXml ColumnDataType = "xml" +) + +func PossibleValuesForColumnDataType() []string { + return []string{ + string(ColumnDataTypeBigint), + string(ColumnDataTypeBinary), + string(ColumnDataTypeBit), + string(ColumnDataTypeChar), + string(ColumnDataTypeDate), + string(ColumnDataTypeDatetime), + string(ColumnDataTypeDatetimeTwo), + string(ColumnDataTypeDatetimeoffset), + string(ColumnDataTypeDecimal), + string(ColumnDataTypeFloat), + string(ColumnDataTypeGeography), + string(ColumnDataTypeGeometry), + string(ColumnDataTypeHierarchyid), + string(ColumnDataTypeImage), + string(ColumnDataTypeInt), + string(ColumnDataTypeMoney), + string(ColumnDataTypeNchar), + string(ColumnDataTypeNtext), + string(ColumnDataTypeNumeric), + string(ColumnDataTypeNvarchar), + string(ColumnDataTypeReal), + string(ColumnDataTypeSmalldatetime), + string(ColumnDataTypeSmallint), + string(ColumnDataTypeSmallmoney), + string(ColumnDataTypeSqlVariant), + string(ColumnDataTypeSysname), + string(ColumnDataTypeText), + string(ColumnDataTypeTime), + string(ColumnDataTypeTimestamp), + string(ColumnDataTypeTinyint), + string(ColumnDataTypeUniqueidentifier), + string(ColumnDataTypeVarbinary), + string(ColumnDataTypeVarchar), + string(ColumnDataTypeXml), + } +} + +func (s *ColumnDataType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseColumnDataType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseColumnDataType(input string) (*ColumnDataType, error) { + vals := map[string]ColumnDataType{ + "bigint": ColumnDataTypeBigint, + "binary": ColumnDataTypeBinary, + "bit": ColumnDataTypeBit, + "char": ColumnDataTypeChar, + "date": ColumnDataTypeDate, + "datetime": ColumnDataTypeDatetime, + "datetime2": ColumnDataTypeDatetimeTwo, + "datetimeoffset": ColumnDataTypeDatetimeoffset, + "decimal": ColumnDataTypeDecimal, + "float": ColumnDataTypeFloat, + "geography": ColumnDataTypeGeography, + "geometry": ColumnDataTypeGeometry, + "hierarchyid": ColumnDataTypeHierarchyid, + "image": ColumnDataTypeImage, + "int": ColumnDataTypeInt, + "money": ColumnDataTypeMoney, + "nchar": ColumnDataTypeNchar, + "ntext": ColumnDataTypeNtext, + "numeric": ColumnDataTypeNumeric, + "nvarchar": ColumnDataTypeNvarchar, + "real": ColumnDataTypeReal, + "smalldatetime": ColumnDataTypeSmalldatetime, + "smallint": ColumnDataTypeSmallint, + "smallmoney": ColumnDataTypeSmallmoney, + "sql_variant": ColumnDataTypeSqlVariant, + "sysname": ColumnDataTypeSysname, + "text": ColumnDataTypeText, + "time": ColumnDataTypeTime, + "timestamp": ColumnDataTypeTimestamp, + "tinyint": ColumnDataTypeTinyint, + "uniqueidentifier": ColumnDataTypeUniqueidentifier, + "varbinary": ColumnDataTypeVarbinary, + "varchar": ColumnDataTypeVarchar, + "xml": ColumnDataTypeXml, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ColumnDataType(input) + return &out, nil +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolstables/id_schema.go b/resource-manager/synapse/2021-06-01/sqlpoolstables/id_schema.go new file mode 100644 index 00000000000..8d863db8f69 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolstables/id_schema.go @@ -0,0 +1,143 @@ +package sqlpoolstables + +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 = &SchemaId{} + +// SchemaId is a struct representing the Resource ID for a Schema +type SchemaId struct { + SubscriptionId string + ResourceGroupName string + WorkspaceName string + SqlPoolName string + SchemaName string +} + +// NewSchemaID returns a new SchemaId struct +func NewSchemaID(subscriptionId string, resourceGroupName string, workspaceName string, sqlPoolName string, schemaName string) SchemaId { + return SchemaId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + WorkspaceName: workspaceName, + SqlPoolName: sqlPoolName, + SchemaName: schemaName, + } +} + +// ParseSchemaID parses 'input' into a SchemaId +func ParseSchemaID(input string) (*SchemaId, error) { + parser := resourceids.NewParserFromResourceIdType(&SchemaId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := SchemaId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseSchemaIDInsensitively parses 'input' case-insensitively into a SchemaId +// note: this method should only be used for API response data and not user input +func ParseSchemaIDInsensitively(input string) (*SchemaId, error) { + parser := resourceids.NewParserFromResourceIdType(&SchemaId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := SchemaId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *SchemaId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.WorkspaceName, ok = input.Parsed["workspaceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "workspaceName", input) + } + + if id.SqlPoolName, ok = input.Parsed["sqlPoolName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "sqlPoolName", input) + } + + if id.SchemaName, ok = input.Parsed["schemaName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "schemaName", input) + } + + return nil +} + +// ValidateSchemaID checks that 'input' can be parsed as a Schema ID +func ValidateSchemaID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseSchemaID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Schema ID +func (id SchemaId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Synapse/workspaces/%s/sqlPools/%s/schemas/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.WorkspaceName, id.SqlPoolName, id.SchemaName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Schema ID +func (id SchemaId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftSynapse", "Microsoft.Synapse", "Microsoft.Synapse"), + resourceids.StaticSegment("staticWorkspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceName", "workspaceValue"), + resourceids.StaticSegment("staticSqlPools", "sqlPools", "sqlPools"), + resourceids.UserSpecifiedSegment("sqlPoolName", "sqlPoolValue"), + resourceids.StaticSegment("staticSchemas", "schemas", "schemas"), + resourceids.UserSpecifiedSegment("schemaName", "schemaValue"), + } +} + +// String returns a human-readable description of this Schema ID +func (id SchemaId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Workspace Name: %q", id.WorkspaceName), + fmt.Sprintf("Sql Pool Name: %q", id.SqlPoolName), + fmt.Sprintf("Schema Name: %q", id.SchemaName), + } + return fmt.Sprintf("Schema (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolstables/id_schema_test.go b/resource-manager/synapse/2021-06-01/sqlpoolstables/id_schema_test.go new file mode 100644 index 00000000000..9f9f512cf05 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolstables/id_schema_test.go @@ -0,0 +1,372 @@ +package sqlpoolstables + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &SchemaId{} + +func TestNewSchemaID(t *testing.T) { + id := NewSchemaID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "sqlPoolValue", "schemaValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.WorkspaceName != "workspaceValue" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceName'", id.WorkspaceName, "workspaceValue") + } + + if id.SqlPoolName != "sqlPoolValue" { + t.Fatalf("Expected %q but got %q for Segment 'SqlPoolName'", id.SqlPoolName, "sqlPoolValue") + } + + if id.SchemaName != "schemaValue" { + t.Fatalf("Expected %q but got %q for Segment 'SchemaName'", id.SchemaName, "schemaValue") + } +} + +func TestFormatSchemaID(t *testing.T) { + actual := NewSchemaID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "sqlPoolValue", "schemaValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/schemas/schemaValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseSchemaID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *SchemaId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/schemas", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/schemas/schemaValue", + Expected: &SchemaId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + SqlPoolName: "sqlPoolValue", + SchemaName: "schemaValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/schemas/schemaValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseSchemaID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + if actual.SqlPoolName != v.Expected.SqlPoolName { + t.Fatalf("Expected %q but got %q for SqlPoolName", v.Expected.SqlPoolName, actual.SqlPoolName) + } + + if actual.SchemaName != v.Expected.SchemaName { + t.Fatalf("Expected %q but got %q for SchemaName", v.Expected.SchemaName, actual.SchemaName) + } + + } +} + +func TestParseSchemaIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *SchemaId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/sQlPoOlS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/sQlPoOlS/sQlPoOlVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/schemas", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/sQlPoOlS/sQlPoOlVaLuE/sChEmAs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/schemas/schemaValue", + Expected: &SchemaId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + SqlPoolName: "sqlPoolValue", + SchemaName: "schemaValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/schemas/schemaValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/sQlPoOlS/sQlPoOlVaLuE/sChEmAs/sChEmAvAlUe", + Expected: &SchemaId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + WorkspaceName: "wOrKsPaCeVaLuE", + SqlPoolName: "sQlPoOlVaLuE", + SchemaName: "sChEmAvAlUe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/sQlPoOlS/sQlPoOlVaLuE/sChEmAs/sChEmAvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseSchemaIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + if actual.SqlPoolName != v.Expected.SqlPoolName { + t.Fatalf("Expected %q but got %q for SqlPoolName", v.Expected.SqlPoolName, actual.SqlPoolName) + } + + if actual.SchemaName != v.Expected.SchemaName { + t.Fatalf("Expected %q but got %q for SchemaName", v.Expected.SchemaName, actual.SchemaName) + } + + } +} + +func TestSegmentsForSchemaId(t *testing.T) { + segments := SchemaId{}.Segments() + if len(segments) == 0 { + t.Fatalf("SchemaId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolstables/id_table.go b/resource-manager/synapse/2021-06-01/sqlpoolstables/id_table.go new file mode 100644 index 00000000000..f86910be310 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolstables/id_table.go @@ -0,0 +1,152 @@ +package sqlpoolstables + +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 = &TableId{} + +// TableId is a struct representing the Resource ID for a Table +type TableId struct { + SubscriptionId string + ResourceGroupName string + WorkspaceName string + SqlPoolName string + SchemaName string + TableName string +} + +// NewTableID returns a new TableId struct +func NewTableID(subscriptionId string, resourceGroupName string, workspaceName string, sqlPoolName string, schemaName string, tableName string) TableId { + return TableId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + WorkspaceName: workspaceName, + SqlPoolName: sqlPoolName, + SchemaName: schemaName, + TableName: tableName, + } +} + +// ParseTableID parses 'input' into a TableId +func ParseTableID(input string) (*TableId, error) { + parser := resourceids.NewParserFromResourceIdType(&TableId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := TableId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseTableIDInsensitively parses 'input' case-insensitively into a TableId +// note: this method should only be used for API response data and not user input +func ParseTableIDInsensitively(input string) (*TableId, error) { + parser := resourceids.NewParserFromResourceIdType(&TableId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := TableId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *TableId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.WorkspaceName, ok = input.Parsed["workspaceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "workspaceName", input) + } + + if id.SqlPoolName, ok = input.Parsed["sqlPoolName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "sqlPoolName", input) + } + + if id.SchemaName, ok = input.Parsed["schemaName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "schemaName", input) + } + + if id.TableName, ok = input.Parsed["tableName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "tableName", input) + } + + return nil +} + +// ValidateTableID checks that 'input' can be parsed as a Table ID +func ValidateTableID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseTableID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Table ID +func (id TableId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Synapse/workspaces/%s/sqlPools/%s/schemas/%s/tables/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.WorkspaceName, id.SqlPoolName, id.SchemaName, id.TableName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Table ID +func (id TableId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftSynapse", "Microsoft.Synapse", "Microsoft.Synapse"), + resourceids.StaticSegment("staticWorkspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceName", "workspaceValue"), + resourceids.StaticSegment("staticSqlPools", "sqlPools", "sqlPools"), + resourceids.UserSpecifiedSegment("sqlPoolName", "sqlPoolValue"), + resourceids.StaticSegment("staticSchemas", "schemas", "schemas"), + resourceids.UserSpecifiedSegment("schemaName", "schemaValue"), + resourceids.StaticSegment("staticTables", "tables", "tables"), + resourceids.UserSpecifiedSegment("tableName", "tableValue"), + } +} + +// String returns a human-readable description of this Table ID +func (id TableId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Workspace Name: %q", id.WorkspaceName), + fmt.Sprintf("Sql Pool Name: %q", id.SqlPoolName), + fmt.Sprintf("Schema Name: %q", id.SchemaName), + fmt.Sprintf("Table Name: %q", id.TableName), + } + return fmt.Sprintf("Table (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolstables/id_table_test.go b/resource-manager/synapse/2021-06-01/sqlpoolstables/id_table_test.go new file mode 100644 index 00000000000..bf02afd868e --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolstables/id_table_test.go @@ -0,0 +1,417 @@ +package sqlpoolstables + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &TableId{} + +func TestNewTableID(t *testing.T) { + id := NewTableID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "sqlPoolValue", "schemaValue", "tableValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.WorkspaceName != "workspaceValue" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceName'", id.WorkspaceName, "workspaceValue") + } + + if id.SqlPoolName != "sqlPoolValue" { + t.Fatalf("Expected %q but got %q for Segment 'SqlPoolName'", id.SqlPoolName, "sqlPoolValue") + } + + if id.SchemaName != "schemaValue" { + t.Fatalf("Expected %q but got %q for Segment 'SchemaName'", id.SchemaName, "schemaValue") + } + + if id.TableName != "tableValue" { + t.Fatalf("Expected %q but got %q for Segment 'TableName'", id.TableName, "tableValue") + } +} + +func TestFormatTableID(t *testing.T) { + actual := NewTableID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "sqlPoolValue", "schemaValue", "tableValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/schemas/schemaValue/tables/tableValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseTableID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *TableId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/schemas", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/schemas/schemaValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/schemas/schemaValue/tables", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/schemas/schemaValue/tables/tableValue", + Expected: &TableId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + SqlPoolName: "sqlPoolValue", + SchemaName: "schemaValue", + TableName: "tableValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/schemas/schemaValue/tables/tableValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseTableID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + if actual.SqlPoolName != v.Expected.SqlPoolName { + t.Fatalf("Expected %q but got %q for SqlPoolName", v.Expected.SqlPoolName, actual.SqlPoolName) + } + + if actual.SchemaName != v.Expected.SchemaName { + t.Fatalf("Expected %q but got %q for SchemaName", v.Expected.SchemaName, actual.SchemaName) + } + + if actual.TableName != v.Expected.TableName { + t.Fatalf("Expected %q but got %q for TableName", v.Expected.TableName, actual.TableName) + } + + } +} + +func TestParseTableIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *TableId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/sQlPoOlS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/sQlPoOlS/sQlPoOlVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/schemas", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/sQlPoOlS/sQlPoOlVaLuE/sChEmAs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/schemas/schemaValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/sQlPoOlS/sQlPoOlVaLuE/sChEmAs/sChEmAvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/schemas/schemaValue/tables", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/sQlPoOlS/sQlPoOlVaLuE/sChEmAs/sChEmAvAlUe/tAbLeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/schemas/schemaValue/tables/tableValue", + Expected: &TableId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + SqlPoolName: "sqlPoolValue", + SchemaName: "schemaValue", + TableName: "tableValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/schemas/schemaValue/tables/tableValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/sQlPoOlS/sQlPoOlVaLuE/sChEmAs/sChEmAvAlUe/tAbLeS/tAbLeVaLuE", + Expected: &TableId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + WorkspaceName: "wOrKsPaCeVaLuE", + SqlPoolName: "sQlPoOlVaLuE", + SchemaName: "sChEmAvAlUe", + TableName: "tAbLeVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/sQlPoOlS/sQlPoOlVaLuE/sChEmAs/sChEmAvAlUe/tAbLeS/tAbLeVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseTableIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + if actual.SqlPoolName != v.Expected.SqlPoolName { + t.Fatalf("Expected %q but got %q for SqlPoolName", v.Expected.SqlPoolName, actual.SqlPoolName) + } + + if actual.SchemaName != v.Expected.SchemaName { + t.Fatalf("Expected %q but got %q for SchemaName", v.Expected.SchemaName, actual.SchemaName) + } + + if actual.TableName != v.Expected.TableName { + t.Fatalf("Expected %q but got %q for TableName", v.Expected.TableName, actual.TableName) + } + + } +} + +func TestSegmentsForTableId(t *testing.T) { + segments := TableId{}.Segments() + if len(segments) == 0 { + t.Fatalf("TableId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolstables/method_sqlpooltablecolumnslistbytablename.go b/resource-manager/synapse/2021-06-01/sqlpoolstables/method_sqlpooltablecolumnslistbytablename.go new file mode 100644 index 00000000000..5578de37598 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolstables/method_sqlpooltablecolumnslistbytablename.go @@ -0,0 +1,119 @@ +package sqlpoolstables + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SqlPoolTableColumnsListByTableNameOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]SqlPoolColumn +} + +type SqlPoolTableColumnsListByTableNameCompleteResult struct { + LatestHttpResponse *http.Response + Items []SqlPoolColumn +} + +type SqlPoolTableColumnsListByTableNameOperationOptions struct { + Filter *string +} + +func DefaultSqlPoolTableColumnsListByTableNameOperationOptions() SqlPoolTableColumnsListByTableNameOperationOptions { + return SqlPoolTableColumnsListByTableNameOperationOptions{} +} + +func (o SqlPoolTableColumnsListByTableNameOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o SqlPoolTableColumnsListByTableNameOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o SqlPoolTableColumnsListByTableNameOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + return &out +} + +// SqlPoolTableColumnsListByTableName ... +func (c SqlPoolsTablesClient) SqlPoolTableColumnsListByTableName(ctx context.Context, id TableId, options SqlPoolTableColumnsListByTableNameOperationOptions) (result SqlPoolTableColumnsListByTableNameOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/columns", id.ID()), + OptionsObject: options, + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]SqlPoolColumn `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// SqlPoolTableColumnsListByTableNameComplete retrieves all the results into a single object +func (c SqlPoolsTablesClient) SqlPoolTableColumnsListByTableNameComplete(ctx context.Context, id TableId, options SqlPoolTableColumnsListByTableNameOperationOptions) (SqlPoolTableColumnsListByTableNameCompleteResult, error) { + return c.SqlPoolTableColumnsListByTableNameCompleteMatchingPredicate(ctx, id, options, SqlPoolColumnOperationPredicate{}) +} + +// SqlPoolTableColumnsListByTableNameCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c SqlPoolsTablesClient) SqlPoolTableColumnsListByTableNameCompleteMatchingPredicate(ctx context.Context, id TableId, options SqlPoolTableColumnsListByTableNameOperationOptions, predicate SqlPoolColumnOperationPredicate) (result SqlPoolTableColumnsListByTableNameCompleteResult, err error) { + items := make([]SqlPoolColumn, 0) + + resp, err := c.SqlPoolTableColumnsListByTableName(ctx, id, options) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = SqlPoolTableColumnsListByTableNameCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolstables/method_sqlpooltableslistbyschema.go b/resource-manager/synapse/2021-06-01/sqlpoolstables/method_sqlpooltableslistbyschema.go new file mode 100644 index 00000000000..6634ee91fa2 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolstables/method_sqlpooltableslistbyschema.go @@ -0,0 +1,119 @@ +package sqlpoolstables + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SqlPoolTablesListBySchemaOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]Resource +} + +type SqlPoolTablesListBySchemaCompleteResult struct { + LatestHttpResponse *http.Response + Items []Resource +} + +type SqlPoolTablesListBySchemaOperationOptions struct { + Filter *string +} + +func DefaultSqlPoolTablesListBySchemaOperationOptions() SqlPoolTablesListBySchemaOperationOptions { + return SqlPoolTablesListBySchemaOperationOptions{} +} + +func (o SqlPoolTablesListBySchemaOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o SqlPoolTablesListBySchemaOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o SqlPoolTablesListBySchemaOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + return &out +} + +// SqlPoolTablesListBySchema ... +func (c SqlPoolsTablesClient) SqlPoolTablesListBySchema(ctx context.Context, id SchemaId, options SqlPoolTablesListBySchemaOperationOptions) (result SqlPoolTablesListBySchemaOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/tables", id.ID()), + OptionsObject: options, + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]Resource `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// SqlPoolTablesListBySchemaComplete retrieves all the results into a single object +func (c SqlPoolsTablesClient) SqlPoolTablesListBySchemaComplete(ctx context.Context, id SchemaId, options SqlPoolTablesListBySchemaOperationOptions) (SqlPoolTablesListBySchemaCompleteResult, error) { + return c.SqlPoolTablesListBySchemaCompleteMatchingPredicate(ctx, id, options, ResourceOperationPredicate{}) +} + +// SqlPoolTablesListBySchemaCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c SqlPoolsTablesClient) SqlPoolTablesListBySchemaCompleteMatchingPredicate(ctx context.Context, id SchemaId, options SqlPoolTablesListBySchemaOperationOptions, predicate ResourceOperationPredicate) (result SqlPoolTablesListBySchemaCompleteResult, err error) { + items := make([]Resource, 0) + + resp, err := c.SqlPoolTablesListBySchema(ctx, id, options) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = SqlPoolTablesListBySchemaCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolstables/model_resource.go b/resource-manager/synapse/2021-06-01/sqlpoolstables/model_resource.go new file mode 100644 index 00000000000..53be52da669 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolstables/model_resource.go @@ -0,0 +1,10 @@ +package sqlpoolstables + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Resource struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolstables/model_sqlpoolcolumn.go b/resource-manager/synapse/2021-06-01/sqlpoolstables/model_sqlpoolcolumn.go new file mode 100644 index 00000000000..060da6ded34 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolstables/model_sqlpoolcolumn.go @@ -0,0 +1,11 @@ +package sqlpoolstables + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SqlPoolColumn struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *SqlPoolColumnProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolstables/model_sqlpoolcolumnproperties.go b/resource-manager/synapse/2021-06-01/sqlpoolstables/model_sqlpoolcolumnproperties.go new file mode 100644 index 00000000000..b997d1e7f42 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolstables/model_sqlpoolcolumnproperties.go @@ -0,0 +1,9 @@ +package sqlpoolstables + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SqlPoolColumnProperties struct { + ColumnType *ColumnDataType `json:"columnType,omitempty"` + IsComputed *bool `json:"isComputed,omitempty"` +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolstables/predicates.go b/resource-manager/synapse/2021-06-01/sqlpoolstables/predicates.go new file mode 100644 index 00000000000..6b61d6d3a6b --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolstables/predicates.go @@ -0,0 +1,50 @@ +package sqlpoolstables + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ResourceOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p ResourceOperationPredicate) Matches(input Resource) bool { + + if p.Id != nil && (input.Id == nil || *p.Id != *input.Id) { + return false + } + + if p.Name != nil && (input.Name == nil || *p.Name != *input.Name) { + return false + } + + if p.Type != nil && (input.Type == nil || *p.Type != *input.Type) { + return false + } + + return true +} + +type SqlPoolColumnOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p SqlPoolColumnOperationPredicate) Matches(input SqlPoolColumn) bool { + + if p.Id != nil && (input.Id == nil || *p.Id != *input.Id) { + return false + } + + if p.Name != nil && (input.Name == nil || *p.Name != *input.Name) { + return false + } + + if p.Type != nil && (input.Type == nil || *p.Type != *input.Type) { + return false + } + + return true +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolstables/version.go b/resource-manager/synapse/2021-06-01/sqlpoolstables/version.go new file mode 100644 index 00000000000..ee1bad8c33e --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolstables/version.go @@ -0,0 +1,12 @@ +package sqlpoolstables + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2021-06-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/sqlpoolstables/%s", defaultApiVersion) +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolstransparentdataencryption/README.md b/resource-manager/synapse/2021-06-01/sqlpoolstransparentdataencryption/README.md new file mode 100644 index 00000000000..cea15f3bfb0 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolstransparentdataencryption/README.md @@ -0,0 +1,74 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/synapse/2021-06-01/sqlpoolstransparentdataencryption` Documentation + +The `sqlpoolstransparentdataencryption` SDK allows for interaction with the Azure Resource Manager Service `synapse` (API Version `2021-06-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/synapse/2021-06-01/sqlpoolstransparentdataencryption" +``` + + +### Client Initialization + +```go +client := sqlpoolstransparentdataencryption.NewSqlPoolsTransparentDataEncryptionClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `SqlPoolsTransparentDataEncryptionClient.SqlPoolTransparentDataEncryptionsCreateOrUpdate` + +```go +ctx := context.TODO() +id := sqlpoolstransparentdataencryption.NewSqlPoolID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "sqlPoolValue") + +payload := sqlpoolstransparentdataencryption.TransparentDataEncryption{ + // ... +} + + +read, err := client.SqlPoolTransparentDataEncryptionsCreateOrUpdate(ctx, id, payload) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `SqlPoolsTransparentDataEncryptionClient.SqlPoolTransparentDataEncryptionsGet` + +```go +ctx := context.TODO() +id := sqlpoolstransparentdataencryption.NewSqlPoolID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "sqlPoolValue") + +read, err := client.SqlPoolTransparentDataEncryptionsGet(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `SqlPoolsTransparentDataEncryptionClient.SqlPoolTransparentDataEncryptionsList` + +```go +ctx := context.TODO() +id := sqlpoolstransparentdataencryption.NewSqlPoolID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "sqlPoolValue") + +// alternatively `client.SqlPoolTransparentDataEncryptionsList(ctx, id)` can be used to do batched pagination +items, err := client.SqlPoolTransparentDataEncryptionsListComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/synapse/2021-06-01/sqlpoolstransparentdataencryption/client.go b/resource-manager/synapse/2021-06-01/sqlpoolstransparentdataencryption/client.go new file mode 100644 index 00000000000..621cb502331 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolstransparentdataencryption/client.go @@ -0,0 +1,26 @@ +package sqlpoolstransparentdataencryption + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SqlPoolsTransparentDataEncryptionClient struct { + Client *resourcemanager.Client +} + +func NewSqlPoolsTransparentDataEncryptionClientWithBaseURI(sdkApi sdkEnv.Api) (*SqlPoolsTransparentDataEncryptionClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "sqlpoolstransparentdataencryption", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating SqlPoolsTransparentDataEncryptionClient: %+v", err) + } + + return &SqlPoolsTransparentDataEncryptionClient{ + Client: client, + }, nil +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolstransparentdataencryption/constants.go b/resource-manager/synapse/2021-06-01/sqlpoolstransparentdataencryption/constants.go new file mode 100644 index 00000000000..79fade1c76d --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolstransparentdataencryption/constants.go @@ -0,0 +1,51 @@ +package sqlpoolstransparentdataencryption + +import ( + "encoding/json" + "fmt" + "strings" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type TransparentDataEncryptionStatus string + +const ( + TransparentDataEncryptionStatusDisabled TransparentDataEncryptionStatus = "Disabled" + TransparentDataEncryptionStatusEnabled TransparentDataEncryptionStatus = "Enabled" +) + +func PossibleValuesForTransparentDataEncryptionStatus() []string { + return []string{ + string(TransparentDataEncryptionStatusDisabled), + string(TransparentDataEncryptionStatusEnabled), + } +} + +func (s *TransparentDataEncryptionStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseTransparentDataEncryptionStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseTransparentDataEncryptionStatus(input string) (*TransparentDataEncryptionStatus, error) { + vals := map[string]TransparentDataEncryptionStatus{ + "disabled": TransparentDataEncryptionStatusDisabled, + "enabled": TransparentDataEncryptionStatusEnabled, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := TransparentDataEncryptionStatus(input) + return &out, nil +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolstransparentdataencryption/id_sqlpool.go b/resource-manager/synapse/2021-06-01/sqlpoolstransparentdataencryption/id_sqlpool.go new file mode 100644 index 00000000000..f2cd4aba741 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolstransparentdataencryption/id_sqlpool.go @@ -0,0 +1,134 @@ +package sqlpoolstransparentdataencryption + +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 = &SqlPoolId{} + +// SqlPoolId is a struct representing the Resource ID for a Sql Pool +type SqlPoolId struct { + SubscriptionId string + ResourceGroupName string + WorkspaceName string + SqlPoolName string +} + +// NewSqlPoolID returns a new SqlPoolId struct +func NewSqlPoolID(subscriptionId string, resourceGroupName string, workspaceName string, sqlPoolName string) SqlPoolId { + return SqlPoolId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + WorkspaceName: workspaceName, + SqlPoolName: sqlPoolName, + } +} + +// ParseSqlPoolID parses 'input' into a SqlPoolId +func ParseSqlPoolID(input string) (*SqlPoolId, error) { + parser := resourceids.NewParserFromResourceIdType(&SqlPoolId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := SqlPoolId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseSqlPoolIDInsensitively parses 'input' case-insensitively into a SqlPoolId +// note: this method should only be used for API response data and not user input +func ParseSqlPoolIDInsensitively(input string) (*SqlPoolId, error) { + parser := resourceids.NewParserFromResourceIdType(&SqlPoolId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := SqlPoolId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *SqlPoolId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.WorkspaceName, ok = input.Parsed["workspaceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "workspaceName", input) + } + + if id.SqlPoolName, ok = input.Parsed["sqlPoolName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "sqlPoolName", input) + } + + return nil +} + +// ValidateSqlPoolID checks that 'input' can be parsed as a Sql Pool ID +func ValidateSqlPoolID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseSqlPoolID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Sql Pool ID +func (id SqlPoolId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Synapse/workspaces/%s/sqlPools/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.WorkspaceName, id.SqlPoolName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Sql Pool ID +func (id SqlPoolId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftSynapse", "Microsoft.Synapse", "Microsoft.Synapse"), + resourceids.StaticSegment("staticWorkspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceName", "workspaceValue"), + resourceids.StaticSegment("staticSqlPools", "sqlPools", "sqlPools"), + resourceids.UserSpecifiedSegment("sqlPoolName", "sqlPoolValue"), + } +} + +// String returns a human-readable description of this Sql Pool ID +func (id SqlPoolId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Workspace Name: %q", id.WorkspaceName), + fmt.Sprintf("Sql Pool Name: %q", id.SqlPoolName), + } + return fmt.Sprintf("Sql Pool (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolstransparentdataencryption/id_sqlpool_test.go b/resource-manager/synapse/2021-06-01/sqlpoolstransparentdataencryption/id_sqlpool_test.go new file mode 100644 index 00000000000..5be3e703e5d --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolstransparentdataencryption/id_sqlpool_test.go @@ -0,0 +1,327 @@ +package sqlpoolstransparentdataencryption + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &SqlPoolId{} + +func TestNewSqlPoolID(t *testing.T) { + id := NewSqlPoolID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "sqlPoolValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.WorkspaceName != "workspaceValue" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceName'", id.WorkspaceName, "workspaceValue") + } + + if id.SqlPoolName != "sqlPoolValue" { + t.Fatalf("Expected %q but got %q for Segment 'SqlPoolName'", id.SqlPoolName, "sqlPoolValue") + } +} + +func TestFormatSqlPoolID(t *testing.T) { + actual := NewSqlPoolID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "sqlPoolValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseSqlPoolID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *SqlPoolId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue", + Expected: &SqlPoolId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + SqlPoolName: "sqlPoolValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseSqlPoolID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + if actual.SqlPoolName != v.Expected.SqlPoolName { + t.Fatalf("Expected %q but got %q for SqlPoolName", v.Expected.SqlPoolName, actual.SqlPoolName) + } + + } +} + +func TestParseSqlPoolIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *SqlPoolId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/sQlPoOlS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue", + Expected: &SqlPoolId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + SqlPoolName: "sqlPoolValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/sQlPoOlS/sQlPoOlVaLuE", + Expected: &SqlPoolId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + WorkspaceName: "wOrKsPaCeVaLuE", + SqlPoolName: "sQlPoOlVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/sQlPoOlS/sQlPoOlVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseSqlPoolIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + if actual.SqlPoolName != v.Expected.SqlPoolName { + t.Fatalf("Expected %q but got %q for SqlPoolName", v.Expected.SqlPoolName, actual.SqlPoolName) + } + + } +} + +func TestSegmentsForSqlPoolId(t *testing.T) { + segments := SqlPoolId{}.Segments() + if len(segments) == 0 { + t.Fatalf("SqlPoolId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolstransparentdataencryption/method_sqlpooltransparentdataencryptionscreateorupdate.go b/resource-manager/synapse/2021-06-01/sqlpoolstransparentdataencryption/method_sqlpooltransparentdataencryptionscreateorupdate.go new file mode 100644 index 00000000000..dd2c826921e --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolstransparentdataencryption/method_sqlpooltransparentdataencryptionscreateorupdate.go @@ -0,0 +1,57 @@ +package sqlpoolstransparentdataencryption + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SqlPoolTransparentDataEncryptionsCreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *TransparentDataEncryption +} + +// SqlPoolTransparentDataEncryptionsCreateOrUpdate ... +func (c SqlPoolsTransparentDataEncryptionClient) SqlPoolTransparentDataEncryptionsCreateOrUpdate(ctx context.Context, id SqlPoolId, input TransparentDataEncryption) (result SqlPoolTransparentDataEncryptionsCreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: fmt.Sprintf("%s/transparentDataEncryption/current", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolstransparentdataencryption/method_sqlpooltransparentdataencryptionsget.go b/resource-manager/synapse/2021-06-01/sqlpoolstransparentdataencryption/method_sqlpooltransparentdataencryptionsget.go new file mode 100644 index 00000000000..2204dde0533 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolstransparentdataencryption/method_sqlpooltransparentdataencryptionsget.go @@ -0,0 +1,52 @@ +package sqlpoolstransparentdataencryption + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SqlPoolTransparentDataEncryptionsGetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *TransparentDataEncryption +} + +// SqlPoolTransparentDataEncryptionsGet ... +func (c SqlPoolsTransparentDataEncryptionClient) SqlPoolTransparentDataEncryptionsGet(ctx context.Context, id SqlPoolId) (result SqlPoolTransparentDataEncryptionsGetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/transparentDataEncryption/current", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolstransparentdataencryption/method_sqlpooltransparentdataencryptionslist.go b/resource-manager/synapse/2021-06-01/sqlpoolstransparentdataencryption/method_sqlpooltransparentdataencryptionslist.go new file mode 100644 index 00000000000..dfbfe09a5fa --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolstransparentdataencryption/method_sqlpooltransparentdataencryptionslist.go @@ -0,0 +1,91 @@ +package sqlpoolstransparentdataencryption + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SqlPoolTransparentDataEncryptionsListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]TransparentDataEncryption +} + +type SqlPoolTransparentDataEncryptionsListCompleteResult struct { + LatestHttpResponse *http.Response + Items []TransparentDataEncryption +} + +// SqlPoolTransparentDataEncryptionsList ... +func (c SqlPoolsTransparentDataEncryptionClient) SqlPoolTransparentDataEncryptionsList(ctx context.Context, id SqlPoolId) (result SqlPoolTransparentDataEncryptionsListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/transparentDataEncryption", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]TransparentDataEncryption `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// SqlPoolTransparentDataEncryptionsListComplete retrieves all the results into a single object +func (c SqlPoolsTransparentDataEncryptionClient) SqlPoolTransparentDataEncryptionsListComplete(ctx context.Context, id SqlPoolId) (SqlPoolTransparentDataEncryptionsListCompleteResult, error) { + return c.SqlPoolTransparentDataEncryptionsListCompleteMatchingPredicate(ctx, id, TransparentDataEncryptionOperationPredicate{}) +} + +// SqlPoolTransparentDataEncryptionsListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c SqlPoolsTransparentDataEncryptionClient) SqlPoolTransparentDataEncryptionsListCompleteMatchingPredicate(ctx context.Context, id SqlPoolId, predicate TransparentDataEncryptionOperationPredicate) (result SqlPoolTransparentDataEncryptionsListCompleteResult, err error) { + items := make([]TransparentDataEncryption, 0) + + resp, err := c.SqlPoolTransparentDataEncryptionsList(ctx, id) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = SqlPoolTransparentDataEncryptionsListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolstransparentdataencryption/model_transparentdataencryption.go b/resource-manager/synapse/2021-06-01/sqlpoolstransparentdataencryption/model_transparentdataencryption.go new file mode 100644 index 00000000000..0bc8c64814e --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolstransparentdataencryption/model_transparentdataencryption.go @@ -0,0 +1,12 @@ +package sqlpoolstransparentdataencryption + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type TransparentDataEncryption struct { + Id *string `json:"id,omitempty"` + Location *string `json:"location,omitempty"` + Name *string `json:"name,omitempty"` + Properties *TransparentDataEncryptionProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolstransparentdataencryption/model_transparentdataencryptionproperties.go b/resource-manager/synapse/2021-06-01/sqlpoolstransparentdataencryption/model_transparentdataencryptionproperties.go new file mode 100644 index 00000000000..f560517311f --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolstransparentdataencryption/model_transparentdataencryptionproperties.go @@ -0,0 +1,8 @@ +package sqlpoolstransparentdataencryption + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type TransparentDataEncryptionProperties struct { + Status *TransparentDataEncryptionStatus `json:"status,omitempty"` +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolstransparentdataencryption/predicates.go b/resource-manager/synapse/2021-06-01/sqlpoolstransparentdataencryption/predicates.go new file mode 100644 index 00000000000..635226d891b --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolstransparentdataencryption/predicates.go @@ -0,0 +1,32 @@ +package sqlpoolstransparentdataencryption + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type TransparentDataEncryptionOperationPredicate struct { + Id *string + Location *string + Name *string + Type *string +} + +func (p TransparentDataEncryptionOperationPredicate) Matches(input TransparentDataEncryption) bool { + + if p.Id != nil && (input.Id == nil || *p.Id != *input.Id) { + return false + } + + if p.Location != nil && (input.Location == nil || *p.Location != *input.Location) { + return false + } + + if p.Name != nil && (input.Name == nil || *p.Name != *input.Name) { + return false + } + + if p.Type != nil && (input.Type == nil || *p.Type != *input.Type) { + return false + } + + return true +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolstransparentdataencryption/version.go b/resource-manager/synapse/2021-06-01/sqlpoolstransparentdataencryption/version.go new file mode 100644 index 00000000000..c6467b52bab --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolstransparentdataencryption/version.go @@ -0,0 +1,12 @@ +package sqlpoolstransparentdataencryption + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2021-06-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/sqlpoolstransparentdataencryption/%s", defaultApiVersion) +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolsusages/README.md b/resource-manager/synapse/2021-06-01/sqlpoolsusages/README.md new file mode 100644 index 00000000000..c9d0664eb10 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolsusages/README.md @@ -0,0 +1,37 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/synapse/2021-06-01/sqlpoolsusages` Documentation + +The `sqlpoolsusages` SDK allows for interaction with the Azure Resource Manager Service `synapse` (API Version `2021-06-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/synapse/2021-06-01/sqlpoolsusages" +``` + + +### Client Initialization + +```go +client := sqlpoolsusages.NewSqlPoolsUsagesClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `SqlPoolsUsagesClient.SqlPoolUsagesList` + +```go +ctx := context.TODO() +id := sqlpoolsusages.NewSqlPoolID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "sqlPoolValue") + +// alternatively `client.SqlPoolUsagesList(ctx, id)` can be used to do batched pagination +items, err := client.SqlPoolUsagesListComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/synapse/2021-06-01/sqlpoolsusages/client.go b/resource-manager/synapse/2021-06-01/sqlpoolsusages/client.go new file mode 100644 index 00000000000..2020415984e --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolsusages/client.go @@ -0,0 +1,26 @@ +package sqlpoolsusages + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SqlPoolsUsagesClient struct { + Client *resourcemanager.Client +} + +func NewSqlPoolsUsagesClientWithBaseURI(sdkApi sdkEnv.Api) (*SqlPoolsUsagesClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "sqlpoolsusages", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating SqlPoolsUsagesClient: %+v", err) + } + + return &SqlPoolsUsagesClient{ + Client: client, + }, nil +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolsusages/id_sqlpool.go b/resource-manager/synapse/2021-06-01/sqlpoolsusages/id_sqlpool.go new file mode 100644 index 00000000000..f172d2b3ee4 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolsusages/id_sqlpool.go @@ -0,0 +1,134 @@ +package sqlpoolsusages + +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 = &SqlPoolId{} + +// SqlPoolId is a struct representing the Resource ID for a Sql Pool +type SqlPoolId struct { + SubscriptionId string + ResourceGroupName string + WorkspaceName string + SqlPoolName string +} + +// NewSqlPoolID returns a new SqlPoolId struct +func NewSqlPoolID(subscriptionId string, resourceGroupName string, workspaceName string, sqlPoolName string) SqlPoolId { + return SqlPoolId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + WorkspaceName: workspaceName, + SqlPoolName: sqlPoolName, + } +} + +// ParseSqlPoolID parses 'input' into a SqlPoolId +func ParseSqlPoolID(input string) (*SqlPoolId, error) { + parser := resourceids.NewParserFromResourceIdType(&SqlPoolId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := SqlPoolId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseSqlPoolIDInsensitively parses 'input' case-insensitively into a SqlPoolId +// note: this method should only be used for API response data and not user input +func ParseSqlPoolIDInsensitively(input string) (*SqlPoolId, error) { + parser := resourceids.NewParserFromResourceIdType(&SqlPoolId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := SqlPoolId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *SqlPoolId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.WorkspaceName, ok = input.Parsed["workspaceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "workspaceName", input) + } + + if id.SqlPoolName, ok = input.Parsed["sqlPoolName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "sqlPoolName", input) + } + + return nil +} + +// ValidateSqlPoolID checks that 'input' can be parsed as a Sql Pool ID +func ValidateSqlPoolID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseSqlPoolID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Sql Pool ID +func (id SqlPoolId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Synapse/workspaces/%s/sqlPools/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.WorkspaceName, id.SqlPoolName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Sql Pool ID +func (id SqlPoolId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftSynapse", "Microsoft.Synapse", "Microsoft.Synapse"), + resourceids.StaticSegment("staticWorkspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceName", "workspaceValue"), + resourceids.StaticSegment("staticSqlPools", "sqlPools", "sqlPools"), + resourceids.UserSpecifiedSegment("sqlPoolName", "sqlPoolValue"), + } +} + +// String returns a human-readable description of this Sql Pool ID +func (id SqlPoolId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Workspace Name: %q", id.WorkspaceName), + fmt.Sprintf("Sql Pool Name: %q", id.SqlPoolName), + } + return fmt.Sprintf("Sql Pool (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolsusages/id_sqlpool_test.go b/resource-manager/synapse/2021-06-01/sqlpoolsusages/id_sqlpool_test.go new file mode 100644 index 00000000000..4ceca663019 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolsusages/id_sqlpool_test.go @@ -0,0 +1,327 @@ +package sqlpoolsusages + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &SqlPoolId{} + +func TestNewSqlPoolID(t *testing.T) { + id := NewSqlPoolID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "sqlPoolValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.WorkspaceName != "workspaceValue" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceName'", id.WorkspaceName, "workspaceValue") + } + + if id.SqlPoolName != "sqlPoolValue" { + t.Fatalf("Expected %q but got %q for Segment 'SqlPoolName'", id.SqlPoolName, "sqlPoolValue") + } +} + +func TestFormatSqlPoolID(t *testing.T) { + actual := NewSqlPoolID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "sqlPoolValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseSqlPoolID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *SqlPoolId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue", + Expected: &SqlPoolId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + SqlPoolName: "sqlPoolValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseSqlPoolID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + if actual.SqlPoolName != v.Expected.SqlPoolName { + t.Fatalf("Expected %q but got %q for SqlPoolName", v.Expected.SqlPoolName, actual.SqlPoolName) + } + + } +} + +func TestParseSqlPoolIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *SqlPoolId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/sQlPoOlS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue", + Expected: &SqlPoolId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + SqlPoolName: "sqlPoolValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/sQlPoOlS/sQlPoOlVaLuE", + Expected: &SqlPoolId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + WorkspaceName: "wOrKsPaCeVaLuE", + SqlPoolName: "sQlPoOlVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/sQlPoOlS/sQlPoOlVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseSqlPoolIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + if actual.SqlPoolName != v.Expected.SqlPoolName { + t.Fatalf("Expected %q but got %q for SqlPoolName", v.Expected.SqlPoolName, actual.SqlPoolName) + } + + } +} + +func TestSegmentsForSqlPoolId(t *testing.T) { + segments := SqlPoolId{}.Segments() + if len(segments) == 0 { + t.Fatalf("SqlPoolId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolsusages/method_sqlpoolusageslist.go b/resource-manager/synapse/2021-06-01/sqlpoolsusages/method_sqlpoolusageslist.go new file mode 100644 index 00000000000..0d2939dae52 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolsusages/method_sqlpoolusageslist.go @@ -0,0 +1,91 @@ +package sqlpoolsusages + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SqlPoolUsagesListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]SqlPoolUsage +} + +type SqlPoolUsagesListCompleteResult struct { + LatestHttpResponse *http.Response + Items []SqlPoolUsage +} + +// SqlPoolUsagesList ... +func (c SqlPoolsUsagesClient) SqlPoolUsagesList(ctx context.Context, id SqlPoolId) (result SqlPoolUsagesListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/usages", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]SqlPoolUsage `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// SqlPoolUsagesListComplete retrieves all the results into a single object +func (c SqlPoolsUsagesClient) SqlPoolUsagesListComplete(ctx context.Context, id SqlPoolId) (SqlPoolUsagesListCompleteResult, error) { + return c.SqlPoolUsagesListCompleteMatchingPredicate(ctx, id, SqlPoolUsageOperationPredicate{}) +} + +// SqlPoolUsagesListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c SqlPoolsUsagesClient) SqlPoolUsagesListCompleteMatchingPredicate(ctx context.Context, id SqlPoolId, predicate SqlPoolUsageOperationPredicate) (result SqlPoolUsagesListCompleteResult, err error) { + items := make([]SqlPoolUsage, 0) + + resp, err := c.SqlPoolUsagesList(ctx, id) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = SqlPoolUsagesListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolsusages/model_sqlpoolusage.go b/resource-manager/synapse/2021-06-01/sqlpoolsusages/model_sqlpoolusage.go new file mode 100644 index 00000000000..ef38646ab15 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolsusages/model_sqlpoolusage.go @@ -0,0 +1,32 @@ +package sqlpoolsusages + +import ( + "time" + + "github.com/hashicorp/go-azure-helpers/lang/dates" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SqlPoolUsage struct { + CurrentValue *float64 `json:"currentValue,omitempty"` + DisplayName *string `json:"displayName,omitempty"` + Limit *float64 `json:"limit,omitempty"` + Name *string `json:"name,omitempty"` + NextResetTime *string `json:"nextResetTime,omitempty"` + ResourceName *string `json:"resourceName,omitempty"` + Unit *string `json:"unit,omitempty"` +} + +func (o *SqlPoolUsage) GetNextResetTimeAsTime() (*time.Time, error) { + if o.NextResetTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.NextResetTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *SqlPoolUsage) SetNextResetTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.NextResetTime = &formatted +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolsusages/predicates.go b/resource-manager/synapse/2021-06-01/sqlpoolsusages/predicates.go new file mode 100644 index 00000000000..c8928421bce --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolsusages/predicates.go @@ -0,0 +1,47 @@ +package sqlpoolsusages + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SqlPoolUsageOperationPredicate struct { + CurrentValue *float64 + DisplayName *string + Limit *float64 + Name *string + NextResetTime *string + ResourceName *string + Unit *string +} + +func (p SqlPoolUsageOperationPredicate) Matches(input SqlPoolUsage) bool { + + if p.CurrentValue != nil && (input.CurrentValue == nil || *p.CurrentValue != *input.CurrentValue) { + return false + } + + if p.DisplayName != nil && (input.DisplayName == nil || *p.DisplayName != *input.DisplayName) { + return false + } + + if p.Limit != nil && (input.Limit == nil || *p.Limit != *input.Limit) { + return false + } + + if p.Name != nil && (input.Name == nil || *p.Name != *input.Name) { + return false + } + + if p.NextResetTime != nil && (input.NextResetTime == nil || *p.NextResetTime != *input.NextResetTime) { + return false + } + + if p.ResourceName != nil && (input.ResourceName == nil || *p.ResourceName != *input.ResourceName) { + return false + } + + if p.Unit != nil && (input.Unit == nil || *p.Unit != *input.Unit) { + return false + } + + return true +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolsusages/version.go b/resource-manager/synapse/2021-06-01/sqlpoolsusages/version.go new file mode 100644 index 00000000000..1000c1b52f9 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolsusages/version.go @@ -0,0 +1,12 @@ +package sqlpoolsusages + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2021-06-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/sqlpoolsusages/%s", defaultApiVersion) +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolsvulnerabilityassessments/README.md b/resource-manager/synapse/2021-06-01/sqlpoolsvulnerabilityassessments/README.md new file mode 100644 index 00000000000..21ed118b8a7 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolsvulnerabilityassessments/README.md @@ -0,0 +1,73 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/synapse/2021-06-01/sqlpoolsvulnerabilityassessments` Documentation + +The `sqlpoolsvulnerabilityassessments` SDK allows for interaction with the Azure Resource Manager Service `synapse` (API Version `2021-06-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/synapse/2021-06-01/sqlpoolsvulnerabilityassessments" +``` + + +### Client Initialization + +```go +client := sqlpoolsvulnerabilityassessments.NewSqlPoolsVulnerabilityAssessmentsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `SqlPoolsVulnerabilityAssessmentsClient.SqlPoolVulnerabilityAssessmentsCreateOrUpdate` + +```go +ctx := context.TODO() +id := sqlpoolsvulnerabilityassessments.NewSqlPoolID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "sqlPoolValue") + +payload := sqlpoolsvulnerabilityassessments.SqlPoolVulnerabilityAssessment{ + // ... +} + + +read, err := client.SqlPoolVulnerabilityAssessmentsCreateOrUpdate(ctx, id, payload) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `SqlPoolsVulnerabilityAssessmentsClient.SqlPoolVulnerabilityAssessmentsDelete` + +```go +ctx := context.TODO() +id := sqlpoolsvulnerabilityassessments.NewSqlPoolID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "sqlPoolValue") + +read, err := client.SqlPoolVulnerabilityAssessmentsDelete(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `SqlPoolsVulnerabilityAssessmentsClient.SqlPoolVulnerabilityAssessmentsGet` + +```go +ctx := context.TODO() +id := sqlpoolsvulnerabilityassessments.NewSqlPoolID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "sqlPoolValue") + +read, err := client.SqlPoolVulnerabilityAssessmentsGet(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` diff --git a/resource-manager/synapse/2021-06-01/sqlpoolsvulnerabilityassessments/client.go b/resource-manager/synapse/2021-06-01/sqlpoolsvulnerabilityassessments/client.go new file mode 100644 index 00000000000..ccf91d0f682 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolsvulnerabilityassessments/client.go @@ -0,0 +1,26 @@ +package sqlpoolsvulnerabilityassessments + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SqlPoolsVulnerabilityAssessmentsClient struct { + Client *resourcemanager.Client +} + +func NewSqlPoolsVulnerabilityAssessmentsClientWithBaseURI(sdkApi sdkEnv.Api) (*SqlPoolsVulnerabilityAssessmentsClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "sqlpoolsvulnerabilityassessments", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating SqlPoolsVulnerabilityAssessmentsClient: %+v", err) + } + + return &SqlPoolsVulnerabilityAssessmentsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolsvulnerabilityassessments/id_sqlpool.go b/resource-manager/synapse/2021-06-01/sqlpoolsvulnerabilityassessments/id_sqlpool.go new file mode 100644 index 00000000000..6fc2b9a8701 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolsvulnerabilityassessments/id_sqlpool.go @@ -0,0 +1,134 @@ +package sqlpoolsvulnerabilityassessments + +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 = &SqlPoolId{} + +// SqlPoolId is a struct representing the Resource ID for a Sql Pool +type SqlPoolId struct { + SubscriptionId string + ResourceGroupName string + WorkspaceName string + SqlPoolName string +} + +// NewSqlPoolID returns a new SqlPoolId struct +func NewSqlPoolID(subscriptionId string, resourceGroupName string, workspaceName string, sqlPoolName string) SqlPoolId { + return SqlPoolId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + WorkspaceName: workspaceName, + SqlPoolName: sqlPoolName, + } +} + +// ParseSqlPoolID parses 'input' into a SqlPoolId +func ParseSqlPoolID(input string) (*SqlPoolId, error) { + parser := resourceids.NewParserFromResourceIdType(&SqlPoolId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := SqlPoolId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseSqlPoolIDInsensitively parses 'input' case-insensitively into a SqlPoolId +// note: this method should only be used for API response data and not user input +func ParseSqlPoolIDInsensitively(input string) (*SqlPoolId, error) { + parser := resourceids.NewParserFromResourceIdType(&SqlPoolId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := SqlPoolId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *SqlPoolId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.WorkspaceName, ok = input.Parsed["workspaceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "workspaceName", input) + } + + if id.SqlPoolName, ok = input.Parsed["sqlPoolName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "sqlPoolName", input) + } + + return nil +} + +// ValidateSqlPoolID checks that 'input' can be parsed as a Sql Pool ID +func ValidateSqlPoolID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseSqlPoolID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Sql Pool ID +func (id SqlPoolId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Synapse/workspaces/%s/sqlPools/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.WorkspaceName, id.SqlPoolName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Sql Pool ID +func (id SqlPoolId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftSynapse", "Microsoft.Synapse", "Microsoft.Synapse"), + resourceids.StaticSegment("staticWorkspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceName", "workspaceValue"), + resourceids.StaticSegment("staticSqlPools", "sqlPools", "sqlPools"), + resourceids.UserSpecifiedSegment("sqlPoolName", "sqlPoolValue"), + } +} + +// String returns a human-readable description of this Sql Pool ID +func (id SqlPoolId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Workspace Name: %q", id.WorkspaceName), + fmt.Sprintf("Sql Pool Name: %q", id.SqlPoolName), + } + return fmt.Sprintf("Sql Pool (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolsvulnerabilityassessments/id_sqlpool_test.go b/resource-manager/synapse/2021-06-01/sqlpoolsvulnerabilityassessments/id_sqlpool_test.go new file mode 100644 index 00000000000..0fcdca5d2a7 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolsvulnerabilityassessments/id_sqlpool_test.go @@ -0,0 +1,327 @@ +package sqlpoolsvulnerabilityassessments + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &SqlPoolId{} + +func TestNewSqlPoolID(t *testing.T) { + id := NewSqlPoolID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "sqlPoolValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.WorkspaceName != "workspaceValue" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceName'", id.WorkspaceName, "workspaceValue") + } + + if id.SqlPoolName != "sqlPoolValue" { + t.Fatalf("Expected %q but got %q for Segment 'SqlPoolName'", id.SqlPoolName, "sqlPoolValue") + } +} + +func TestFormatSqlPoolID(t *testing.T) { + actual := NewSqlPoolID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "sqlPoolValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseSqlPoolID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *SqlPoolId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue", + Expected: &SqlPoolId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + SqlPoolName: "sqlPoolValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseSqlPoolID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + if actual.SqlPoolName != v.Expected.SqlPoolName { + t.Fatalf("Expected %q but got %q for SqlPoolName", v.Expected.SqlPoolName, actual.SqlPoolName) + } + + } +} + +func TestParseSqlPoolIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *SqlPoolId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/sQlPoOlS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue", + Expected: &SqlPoolId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + SqlPoolName: "sqlPoolValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/sQlPoOlS/sQlPoOlVaLuE", + Expected: &SqlPoolId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + WorkspaceName: "wOrKsPaCeVaLuE", + SqlPoolName: "sQlPoOlVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/sQlPoOlS/sQlPoOlVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseSqlPoolIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + if actual.SqlPoolName != v.Expected.SqlPoolName { + t.Fatalf("Expected %q but got %q for SqlPoolName", v.Expected.SqlPoolName, actual.SqlPoolName) + } + + } +} + +func TestSegmentsForSqlPoolId(t *testing.T) { + segments := SqlPoolId{}.Segments() + if len(segments) == 0 { + t.Fatalf("SqlPoolId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolsvulnerabilityassessments/method_sqlpoolvulnerabilityassessmentscreateorupdate.go b/resource-manager/synapse/2021-06-01/sqlpoolsvulnerabilityassessments/method_sqlpoolvulnerabilityassessmentscreateorupdate.go new file mode 100644 index 00000000000..952232149d5 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolsvulnerabilityassessments/method_sqlpoolvulnerabilityassessmentscreateorupdate.go @@ -0,0 +1,57 @@ +package sqlpoolsvulnerabilityassessments + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SqlPoolVulnerabilityAssessmentsCreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *SqlPoolVulnerabilityAssessment +} + +// SqlPoolVulnerabilityAssessmentsCreateOrUpdate ... +func (c SqlPoolsVulnerabilityAssessmentsClient) SqlPoolVulnerabilityAssessmentsCreateOrUpdate(ctx context.Context, id SqlPoolId, input SqlPoolVulnerabilityAssessment) (result SqlPoolVulnerabilityAssessmentsCreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: fmt.Sprintf("%s/vulnerabilityAssessments/default", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolsvulnerabilityassessments/method_sqlpoolvulnerabilityassessmentsdelete.go b/resource-manager/synapse/2021-06-01/sqlpoolsvulnerabilityassessments/method_sqlpoolvulnerabilityassessmentsdelete.go new file mode 100644 index 00000000000..6eab3e6aacb --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolsvulnerabilityassessments/method_sqlpoolvulnerabilityassessmentsdelete.go @@ -0,0 +1,48 @@ +package sqlpoolsvulnerabilityassessments + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SqlPoolVulnerabilityAssessmentsDeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// SqlPoolVulnerabilityAssessmentsDelete ... +func (c SqlPoolsVulnerabilityAssessmentsClient) SqlPoolVulnerabilityAssessmentsDelete(ctx context.Context, id SqlPoolId) (result SqlPoolVulnerabilityAssessmentsDeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: fmt.Sprintf("%s/vulnerabilityAssessments/default", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolsvulnerabilityassessments/method_sqlpoolvulnerabilityassessmentsget.go b/resource-manager/synapse/2021-06-01/sqlpoolsvulnerabilityassessments/method_sqlpoolvulnerabilityassessmentsget.go new file mode 100644 index 00000000000..9d13d357435 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolsvulnerabilityassessments/method_sqlpoolvulnerabilityassessmentsget.go @@ -0,0 +1,52 @@ +package sqlpoolsvulnerabilityassessments + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SqlPoolVulnerabilityAssessmentsGetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *SqlPoolVulnerabilityAssessment +} + +// SqlPoolVulnerabilityAssessmentsGet ... +func (c SqlPoolsVulnerabilityAssessmentsClient) SqlPoolVulnerabilityAssessmentsGet(ctx context.Context, id SqlPoolId) (result SqlPoolVulnerabilityAssessmentsGetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/vulnerabilityAssessments/default", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolsvulnerabilityassessments/model_sqlpoolvulnerabilityassessment.go b/resource-manager/synapse/2021-06-01/sqlpoolsvulnerabilityassessments/model_sqlpoolvulnerabilityassessment.go new file mode 100644 index 00000000000..3340e54bb90 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolsvulnerabilityassessments/model_sqlpoolvulnerabilityassessment.go @@ -0,0 +1,11 @@ +package sqlpoolsvulnerabilityassessments + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SqlPoolVulnerabilityAssessment struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *SqlPoolVulnerabilityAssessmentProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolsvulnerabilityassessments/model_sqlpoolvulnerabilityassessmentproperties.go b/resource-manager/synapse/2021-06-01/sqlpoolsvulnerabilityassessments/model_sqlpoolvulnerabilityassessmentproperties.go new file mode 100644 index 00000000000..42d08ede8de --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolsvulnerabilityassessments/model_sqlpoolvulnerabilityassessmentproperties.go @@ -0,0 +1,11 @@ +package sqlpoolsvulnerabilityassessments + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SqlPoolVulnerabilityAssessmentProperties struct { + RecurringScans *VulnerabilityAssessmentRecurringScansProperties `json:"recurringScans,omitempty"` + StorageAccountAccessKey *string `json:"storageAccountAccessKey,omitempty"` + StorageContainerPath *string `json:"storageContainerPath,omitempty"` + StorageContainerSasKey *string `json:"storageContainerSasKey,omitempty"` +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolsvulnerabilityassessments/model_vulnerabilityassessmentrecurringscansproperties.go b/resource-manager/synapse/2021-06-01/sqlpoolsvulnerabilityassessments/model_vulnerabilityassessmentrecurringscansproperties.go new file mode 100644 index 00000000000..4f5ad1bfd27 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolsvulnerabilityassessments/model_vulnerabilityassessmentrecurringscansproperties.go @@ -0,0 +1,10 @@ +package sqlpoolsvulnerabilityassessments + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type VulnerabilityAssessmentRecurringScansProperties struct { + EmailSubscriptionAdmins *bool `json:"emailSubscriptionAdmins,omitempty"` + Emails *[]string `json:"emails,omitempty"` + IsEnabled *bool `json:"isEnabled,omitempty"` +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolsvulnerabilityassessments/version.go b/resource-manager/synapse/2021-06-01/sqlpoolsvulnerabilityassessments/version.go new file mode 100644 index 00000000000..f42e71b1929 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolsvulnerabilityassessments/version.go @@ -0,0 +1,12 @@ +package sqlpoolsvulnerabilityassessments + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2021-06-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/sqlpoolsvulnerabilityassessments/%s", defaultApiVersion) +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolsvulnerabilityassessmentscansexecute/client.go b/resource-manager/synapse/2021-06-01/sqlpoolsvulnerabilityassessmentscansexecute/client.go new file mode 100644 index 00000000000..e402e0ef8ee --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolsvulnerabilityassessmentscansexecute/client.go @@ -0,0 +1,26 @@ +package sqlpoolsvulnerabilityassessmentscansexecute + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SqlPoolsVulnerabilityAssessmentScansExecuteClient struct { + Client *resourcemanager.Client +} + +func NewSqlPoolsVulnerabilityAssessmentScansExecuteClientWithBaseURI(sdkApi sdkEnv.Api) (*SqlPoolsVulnerabilityAssessmentScansExecuteClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "sqlpoolsvulnerabilityassessmentscansexecute", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating SqlPoolsVulnerabilityAssessmentScansExecuteClient: %+v", err) + } + + return &SqlPoolsVulnerabilityAssessmentScansExecuteClient{ + Client: client, + }, nil +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolsvulnerabilityassessmentscansexecute/id_scan.go b/resource-manager/synapse/2021-06-01/sqlpoolsvulnerabilityassessmentscansexecute/id_scan.go new file mode 100644 index 00000000000..0dccf2e01a4 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolsvulnerabilityassessmentscansexecute/id_scan.go @@ -0,0 +1,145 @@ +package sqlpoolsvulnerabilityassessmentscansexecute + +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 = &ScanId{} + +// ScanId is a struct representing the Resource ID for a Scan +type ScanId struct { + SubscriptionId string + ResourceGroupName string + WorkspaceName string + SqlPoolName string + ScanId string +} + +// NewScanID returns a new ScanId struct +func NewScanID(subscriptionId string, resourceGroupName string, workspaceName string, sqlPoolName string, scanId string) ScanId { + return ScanId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + WorkspaceName: workspaceName, + SqlPoolName: sqlPoolName, + ScanId: scanId, + } +} + +// ParseScanID parses 'input' into a ScanId +func ParseScanID(input string) (*ScanId, error) { + parser := resourceids.NewParserFromResourceIdType(&ScanId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ScanId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseScanIDInsensitively parses 'input' case-insensitively into a ScanId +// note: this method should only be used for API response data and not user input +func ParseScanIDInsensitively(input string) (*ScanId, error) { + parser := resourceids.NewParserFromResourceIdType(&ScanId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ScanId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ScanId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.WorkspaceName, ok = input.Parsed["workspaceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "workspaceName", input) + } + + if id.SqlPoolName, ok = input.Parsed["sqlPoolName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "sqlPoolName", input) + } + + if id.ScanId, ok = input.Parsed["scanId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "scanId", input) + } + + return nil +} + +// ValidateScanID checks that 'input' can be parsed as a Scan ID +func ValidateScanID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseScanID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Scan ID +func (id ScanId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Synapse/workspaces/%s/sqlPools/%s/vulnerabilityAssessments/default/scans/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.WorkspaceName, id.SqlPoolName, id.ScanId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Scan ID +func (id ScanId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftSynapse", "Microsoft.Synapse", "Microsoft.Synapse"), + resourceids.StaticSegment("staticWorkspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceName", "workspaceValue"), + resourceids.StaticSegment("staticSqlPools", "sqlPools", "sqlPools"), + resourceids.UserSpecifiedSegment("sqlPoolName", "sqlPoolValue"), + resourceids.StaticSegment("staticVulnerabilityAssessments", "vulnerabilityAssessments", "vulnerabilityAssessments"), + resourceids.StaticSegment("vulnerabilityAssessmentName", "default", "default"), + resourceids.StaticSegment("staticScans", "scans", "scans"), + resourceids.UserSpecifiedSegment("scanId", "scanIdValue"), + } +} + +// String returns a human-readable description of this Scan ID +func (id ScanId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Workspace Name: %q", id.WorkspaceName), + fmt.Sprintf("Sql Pool Name: %q", id.SqlPoolName), + fmt.Sprintf("Scan: %q", id.ScanId), + } + return fmt.Sprintf("Scan (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolsvulnerabilityassessmentscansexecute/id_scan_test.go b/resource-manager/synapse/2021-06-01/sqlpoolsvulnerabilityassessmentscansexecute/id_scan_test.go new file mode 100644 index 00000000000..058d639a583 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolsvulnerabilityassessmentscansexecute/id_scan_test.go @@ -0,0 +1,402 @@ +package sqlpoolsvulnerabilityassessmentscansexecute + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &ScanId{} + +func TestNewScanID(t *testing.T) { + id := NewScanID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "sqlPoolValue", "scanIdValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.WorkspaceName != "workspaceValue" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceName'", id.WorkspaceName, "workspaceValue") + } + + if id.SqlPoolName != "sqlPoolValue" { + t.Fatalf("Expected %q but got %q for Segment 'SqlPoolName'", id.SqlPoolName, "sqlPoolValue") + } + + if id.ScanId != "scanIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'ScanId'", id.ScanId, "scanIdValue") + } +} + +func TestFormatScanID(t *testing.T) { + actual := NewScanID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "sqlPoolValue", "scanIdValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/vulnerabilityAssessments/default/scans/scanIdValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseScanID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ScanId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/vulnerabilityAssessments", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/vulnerabilityAssessments/default", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/vulnerabilityAssessments/default/scans", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/vulnerabilityAssessments/default/scans/scanIdValue", + Expected: &ScanId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + SqlPoolName: "sqlPoolValue", + ScanId: "scanIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/vulnerabilityAssessments/default/scans/scanIdValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseScanID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + if actual.SqlPoolName != v.Expected.SqlPoolName { + t.Fatalf("Expected %q but got %q for SqlPoolName", v.Expected.SqlPoolName, actual.SqlPoolName) + } + + if actual.ScanId != v.Expected.ScanId { + t.Fatalf("Expected %q but got %q for ScanId", v.Expected.ScanId, actual.ScanId) + } + + } +} + +func TestParseScanIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ScanId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/sQlPoOlS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/sQlPoOlS/sQlPoOlVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/vulnerabilityAssessments", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/sQlPoOlS/sQlPoOlVaLuE/vUlNeRaBiLiTyAsSeSsMeNtS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/vulnerabilityAssessments/default", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/sQlPoOlS/sQlPoOlVaLuE/vUlNeRaBiLiTyAsSeSsMeNtS/dEfAuLt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/vulnerabilityAssessments/default/scans", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/sQlPoOlS/sQlPoOlVaLuE/vUlNeRaBiLiTyAsSeSsMeNtS/dEfAuLt/sCaNs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/vulnerabilityAssessments/default/scans/scanIdValue", + Expected: &ScanId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + SqlPoolName: "sqlPoolValue", + ScanId: "scanIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/vulnerabilityAssessments/default/scans/scanIdValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/sQlPoOlS/sQlPoOlVaLuE/vUlNeRaBiLiTyAsSeSsMeNtS/dEfAuLt/sCaNs/sCaNiDvAlUe", + Expected: &ScanId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + WorkspaceName: "wOrKsPaCeVaLuE", + SqlPoolName: "sQlPoOlVaLuE", + ScanId: "sCaNiDvAlUe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/sQlPoOlS/sQlPoOlVaLuE/vUlNeRaBiLiTyAsSeSsMeNtS/dEfAuLt/sCaNs/sCaNiDvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseScanIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + if actual.SqlPoolName != v.Expected.SqlPoolName { + t.Fatalf("Expected %q but got %q for SqlPoolName", v.Expected.SqlPoolName, actual.SqlPoolName) + } + + if actual.ScanId != v.Expected.ScanId { + t.Fatalf("Expected %q but got %q for ScanId", v.Expected.ScanId, actual.ScanId) + } + + } +} + +func TestSegmentsForScanId(t *testing.T) { + segments := ScanId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ScanId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolsvulnerabilityassessmentscansexecute/method_sqlpoolvulnerabilityassessmentscansinitiatescan.go b/resource-manager/synapse/2021-06-01/sqlpoolsvulnerabilityassessmentscansexecute/method_sqlpoolvulnerabilityassessmentscansinitiatescan.go new file mode 100644 index 00000000000..52630dd1be8 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolsvulnerabilityassessmentscansexecute/method_sqlpoolvulnerabilityassessmentscansinitiatescan.go @@ -0,0 +1,70 @@ +package sqlpoolsvulnerabilityassessmentscansexecute + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SqlPoolVulnerabilityAssessmentScansInitiateScanOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// SqlPoolVulnerabilityAssessmentScansInitiateScan ... +func (c SqlPoolsVulnerabilityAssessmentScansExecuteClient) SqlPoolVulnerabilityAssessmentScansInitiateScan(ctx context.Context, id ScanId) (result SqlPoolVulnerabilityAssessmentScansInitiateScanOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/initiateScan", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// SqlPoolVulnerabilityAssessmentScansInitiateScanThenPoll performs SqlPoolVulnerabilityAssessmentScansInitiateScan then polls until it's completed +func (c SqlPoolsVulnerabilityAssessmentScansExecuteClient) SqlPoolVulnerabilityAssessmentScansInitiateScanThenPoll(ctx context.Context, id ScanId) error { + result, err := c.SqlPoolVulnerabilityAssessmentScansInitiateScan(ctx, id) + if err != nil { + return fmt.Errorf("performing SqlPoolVulnerabilityAssessmentScansInitiateScan: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after SqlPoolVulnerabilityAssessmentScansInitiateScan: %+v", err) + } + + return nil +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolsvulnerabilityassessmentscansexecute/version.go b/resource-manager/synapse/2021-06-01/sqlpoolsvulnerabilityassessmentscansexecute/version.go new file mode 100644 index 00000000000..023f84c2c82 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolsvulnerabilityassessmentscansexecute/version.go @@ -0,0 +1,12 @@ +package sqlpoolsvulnerabilityassessmentscansexecute + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2021-06-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/sqlpoolsvulnerabilityassessmentscansexecute/%s", defaultApiVersion) +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolsvulnerabilityassessmentscansexport/README.md b/resource-manager/synapse/2021-06-01/sqlpoolsvulnerabilityassessmentscansexport/README.md new file mode 100644 index 00000000000..bd71a0240ae --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolsvulnerabilityassessmentscansexport/README.md @@ -0,0 +1,36 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/synapse/2021-06-01/sqlpoolsvulnerabilityassessmentscansexport` Documentation + +The `sqlpoolsvulnerabilityassessmentscansexport` SDK allows for interaction with the Azure Resource Manager Service `synapse` (API Version `2021-06-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/synapse/2021-06-01/sqlpoolsvulnerabilityassessmentscansexport" +``` + + +### Client Initialization + +```go +client := sqlpoolsvulnerabilityassessmentscansexport.NewSqlPoolsVulnerabilityAssessmentScansExportClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `SqlPoolsVulnerabilityAssessmentScansExportClient.SqlPoolVulnerabilityAssessmentScansExport` + +```go +ctx := context.TODO() +id := sqlpoolsvulnerabilityassessmentscansexport.NewScanID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "sqlPoolValue", "scanIdValue") + +read, err := client.SqlPoolVulnerabilityAssessmentScansExport(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` diff --git a/resource-manager/synapse/2021-06-01/sqlpoolsvulnerabilityassessmentscansexport/client.go b/resource-manager/synapse/2021-06-01/sqlpoolsvulnerabilityassessmentscansexport/client.go new file mode 100644 index 00000000000..2c37c8fe526 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolsvulnerabilityassessmentscansexport/client.go @@ -0,0 +1,26 @@ +package sqlpoolsvulnerabilityassessmentscansexport + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SqlPoolsVulnerabilityAssessmentScansExportClient struct { + Client *resourcemanager.Client +} + +func NewSqlPoolsVulnerabilityAssessmentScansExportClientWithBaseURI(sdkApi sdkEnv.Api) (*SqlPoolsVulnerabilityAssessmentScansExportClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "sqlpoolsvulnerabilityassessmentscansexport", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating SqlPoolsVulnerabilityAssessmentScansExportClient: %+v", err) + } + + return &SqlPoolsVulnerabilityAssessmentScansExportClient{ + Client: client, + }, nil +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolsvulnerabilityassessmentscansexport/id_scan.go b/resource-manager/synapse/2021-06-01/sqlpoolsvulnerabilityassessmentscansexport/id_scan.go new file mode 100644 index 00000000000..9de4e1d941e --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolsvulnerabilityassessmentscansexport/id_scan.go @@ -0,0 +1,145 @@ +package sqlpoolsvulnerabilityassessmentscansexport + +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 = &ScanId{} + +// ScanId is a struct representing the Resource ID for a Scan +type ScanId struct { + SubscriptionId string + ResourceGroupName string + WorkspaceName string + SqlPoolName string + ScanId string +} + +// NewScanID returns a new ScanId struct +func NewScanID(subscriptionId string, resourceGroupName string, workspaceName string, sqlPoolName string, scanId string) ScanId { + return ScanId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + WorkspaceName: workspaceName, + SqlPoolName: sqlPoolName, + ScanId: scanId, + } +} + +// ParseScanID parses 'input' into a ScanId +func ParseScanID(input string) (*ScanId, error) { + parser := resourceids.NewParserFromResourceIdType(&ScanId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ScanId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseScanIDInsensitively parses 'input' case-insensitively into a ScanId +// note: this method should only be used for API response data and not user input +func ParseScanIDInsensitively(input string) (*ScanId, error) { + parser := resourceids.NewParserFromResourceIdType(&ScanId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ScanId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ScanId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.WorkspaceName, ok = input.Parsed["workspaceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "workspaceName", input) + } + + if id.SqlPoolName, ok = input.Parsed["sqlPoolName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "sqlPoolName", input) + } + + if id.ScanId, ok = input.Parsed["scanId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "scanId", input) + } + + return nil +} + +// ValidateScanID checks that 'input' can be parsed as a Scan ID +func ValidateScanID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseScanID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Scan ID +func (id ScanId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Synapse/workspaces/%s/sqlPools/%s/vulnerabilityAssessments/default/scans/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.WorkspaceName, id.SqlPoolName, id.ScanId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Scan ID +func (id ScanId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftSynapse", "Microsoft.Synapse", "Microsoft.Synapse"), + resourceids.StaticSegment("staticWorkspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceName", "workspaceValue"), + resourceids.StaticSegment("staticSqlPools", "sqlPools", "sqlPools"), + resourceids.UserSpecifiedSegment("sqlPoolName", "sqlPoolValue"), + resourceids.StaticSegment("staticVulnerabilityAssessments", "vulnerabilityAssessments", "vulnerabilityAssessments"), + resourceids.StaticSegment("vulnerabilityAssessmentName", "default", "default"), + resourceids.StaticSegment("staticScans", "scans", "scans"), + resourceids.UserSpecifiedSegment("scanId", "scanIdValue"), + } +} + +// String returns a human-readable description of this Scan ID +func (id ScanId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Workspace Name: %q", id.WorkspaceName), + fmt.Sprintf("Sql Pool Name: %q", id.SqlPoolName), + fmt.Sprintf("Scan: %q", id.ScanId), + } + return fmt.Sprintf("Scan (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolsvulnerabilityassessmentscansexport/id_scan_test.go b/resource-manager/synapse/2021-06-01/sqlpoolsvulnerabilityassessmentscansexport/id_scan_test.go new file mode 100644 index 00000000000..ff67c98ff43 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolsvulnerabilityassessmentscansexport/id_scan_test.go @@ -0,0 +1,402 @@ +package sqlpoolsvulnerabilityassessmentscansexport + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &ScanId{} + +func TestNewScanID(t *testing.T) { + id := NewScanID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "sqlPoolValue", "scanIdValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.WorkspaceName != "workspaceValue" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceName'", id.WorkspaceName, "workspaceValue") + } + + if id.SqlPoolName != "sqlPoolValue" { + t.Fatalf("Expected %q but got %q for Segment 'SqlPoolName'", id.SqlPoolName, "sqlPoolValue") + } + + if id.ScanId != "scanIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'ScanId'", id.ScanId, "scanIdValue") + } +} + +func TestFormatScanID(t *testing.T) { + actual := NewScanID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "sqlPoolValue", "scanIdValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/vulnerabilityAssessments/default/scans/scanIdValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseScanID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ScanId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/vulnerabilityAssessments", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/vulnerabilityAssessments/default", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/vulnerabilityAssessments/default/scans", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/vulnerabilityAssessments/default/scans/scanIdValue", + Expected: &ScanId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + SqlPoolName: "sqlPoolValue", + ScanId: "scanIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/vulnerabilityAssessments/default/scans/scanIdValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseScanID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + if actual.SqlPoolName != v.Expected.SqlPoolName { + t.Fatalf("Expected %q but got %q for SqlPoolName", v.Expected.SqlPoolName, actual.SqlPoolName) + } + + if actual.ScanId != v.Expected.ScanId { + t.Fatalf("Expected %q but got %q for ScanId", v.Expected.ScanId, actual.ScanId) + } + + } +} + +func TestParseScanIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ScanId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/sQlPoOlS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/sQlPoOlS/sQlPoOlVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/vulnerabilityAssessments", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/sQlPoOlS/sQlPoOlVaLuE/vUlNeRaBiLiTyAsSeSsMeNtS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/vulnerabilityAssessments/default", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/sQlPoOlS/sQlPoOlVaLuE/vUlNeRaBiLiTyAsSeSsMeNtS/dEfAuLt", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/vulnerabilityAssessments/default/scans", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/sQlPoOlS/sQlPoOlVaLuE/vUlNeRaBiLiTyAsSeSsMeNtS/dEfAuLt/sCaNs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/vulnerabilityAssessments/default/scans/scanIdValue", + Expected: &ScanId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + SqlPoolName: "sqlPoolValue", + ScanId: "scanIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/vulnerabilityAssessments/default/scans/scanIdValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/sQlPoOlS/sQlPoOlVaLuE/vUlNeRaBiLiTyAsSeSsMeNtS/dEfAuLt/sCaNs/sCaNiDvAlUe", + Expected: &ScanId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + WorkspaceName: "wOrKsPaCeVaLuE", + SqlPoolName: "sQlPoOlVaLuE", + ScanId: "sCaNiDvAlUe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/sQlPoOlS/sQlPoOlVaLuE/vUlNeRaBiLiTyAsSeSsMeNtS/dEfAuLt/sCaNs/sCaNiDvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseScanIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + if actual.SqlPoolName != v.Expected.SqlPoolName { + t.Fatalf("Expected %q but got %q for SqlPoolName", v.Expected.SqlPoolName, actual.SqlPoolName) + } + + if actual.ScanId != v.Expected.ScanId { + t.Fatalf("Expected %q but got %q for ScanId", v.Expected.ScanId, actual.ScanId) + } + + } +} + +func TestSegmentsForScanId(t *testing.T) { + segments := ScanId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ScanId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolsvulnerabilityassessmentscansexport/method_sqlpoolvulnerabilityassessmentscansexport.go b/resource-manager/synapse/2021-06-01/sqlpoolsvulnerabilityassessmentscansexport/method_sqlpoolvulnerabilityassessmentscansexport.go new file mode 100644 index 00000000000..82d4b2047d0 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolsvulnerabilityassessmentscansexport/method_sqlpoolvulnerabilityassessmentscansexport.go @@ -0,0 +1,52 @@ +package sqlpoolsvulnerabilityassessmentscansexport + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SqlPoolVulnerabilityAssessmentScansExportOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *SqlPoolVulnerabilityAssessmentScansExport +} + +// SqlPoolVulnerabilityAssessmentScansExport ... +func (c SqlPoolsVulnerabilityAssessmentScansExportClient) SqlPoolVulnerabilityAssessmentScansExport(ctx context.Context, id ScanId) (result SqlPoolVulnerabilityAssessmentScansExportOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/export", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolsvulnerabilityassessmentscansexport/model_sqlpoolvulnerabilityassessmentscanexportproperties.go b/resource-manager/synapse/2021-06-01/sqlpoolsvulnerabilityassessmentscansexport/model_sqlpoolvulnerabilityassessmentscanexportproperties.go new file mode 100644 index 00000000000..6d0a0d557bf --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolsvulnerabilityassessmentscansexport/model_sqlpoolvulnerabilityassessmentscanexportproperties.go @@ -0,0 +1,8 @@ +package sqlpoolsvulnerabilityassessmentscansexport + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SqlPoolVulnerabilityAssessmentScanExportProperties struct { + ExportedReportLocation *string `json:"exportedReportLocation,omitempty"` +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolsvulnerabilityassessmentscansexport/model_sqlpoolvulnerabilityassessmentscansexport.go b/resource-manager/synapse/2021-06-01/sqlpoolsvulnerabilityassessmentscansexport/model_sqlpoolvulnerabilityassessmentscansexport.go new file mode 100644 index 00000000000..daa086ab7ae --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolsvulnerabilityassessmentscansexport/model_sqlpoolvulnerabilityassessmentscansexport.go @@ -0,0 +1,11 @@ +package sqlpoolsvulnerabilityassessmentscansexport + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SqlPoolVulnerabilityAssessmentScansExport struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *SqlPoolVulnerabilityAssessmentScanExportProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolsvulnerabilityassessmentscansexport/version.go b/resource-manager/synapse/2021-06-01/sqlpoolsvulnerabilityassessmentscansexport/version.go new file mode 100644 index 00000000000..513c620822e --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolsvulnerabilityassessmentscansexport/version.go @@ -0,0 +1,12 @@ +package sqlpoolsvulnerabilityassessmentscansexport + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2021-06-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/sqlpoolsvulnerabilityassessmentscansexport/%s", defaultApiVersion) +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolsworkloadclassifiers/README.md b/resource-manager/synapse/2021-06-01/sqlpoolsworkloadclassifiers/README.md new file mode 100644 index 00000000000..8d85c9c81b3 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolsworkloadclassifiers/README.md @@ -0,0 +1,82 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/synapse/2021-06-01/sqlpoolsworkloadclassifiers` Documentation + +The `sqlpoolsworkloadclassifiers` SDK allows for interaction with the Azure Resource Manager Service `synapse` (API Version `2021-06-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/synapse/2021-06-01/sqlpoolsworkloadclassifiers" +``` + + +### Client Initialization + +```go +client := sqlpoolsworkloadclassifiers.NewSqlPoolsWorkloadClassifiersClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `SqlPoolsWorkloadClassifiersClient.SqlPoolWorkloadClassifierCreateOrUpdate` + +```go +ctx := context.TODO() +id := sqlpoolsworkloadclassifiers.NewWorkloadClassifierID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "sqlPoolValue", "workloadGroupValue", "workloadClassifierValue") + +payload := sqlpoolsworkloadclassifiers.WorkloadClassifier{ + // ... +} + + +if err := client.SqlPoolWorkloadClassifierCreateOrUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `SqlPoolsWorkloadClassifiersClient.SqlPoolWorkloadClassifierDelete` + +```go +ctx := context.TODO() +id := sqlpoolsworkloadclassifiers.NewWorkloadClassifierID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "sqlPoolValue", "workloadGroupValue", "workloadClassifierValue") + +if err := client.SqlPoolWorkloadClassifierDeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `SqlPoolsWorkloadClassifiersClient.SqlPoolWorkloadClassifierGet` + +```go +ctx := context.TODO() +id := sqlpoolsworkloadclassifiers.NewWorkloadClassifierID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "sqlPoolValue", "workloadGroupValue", "workloadClassifierValue") + +read, err := client.SqlPoolWorkloadClassifierGet(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `SqlPoolsWorkloadClassifiersClient.SqlPoolWorkloadClassifierList` + +```go +ctx := context.TODO() +id := sqlpoolsworkloadclassifiers.NewWorkloadGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "sqlPoolValue", "workloadGroupValue") + +// alternatively `client.SqlPoolWorkloadClassifierList(ctx, id)` can be used to do batched pagination +items, err := client.SqlPoolWorkloadClassifierListComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/synapse/2021-06-01/sqlpoolsworkloadclassifiers/client.go b/resource-manager/synapse/2021-06-01/sqlpoolsworkloadclassifiers/client.go new file mode 100644 index 00000000000..d2a3948ee2e --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolsworkloadclassifiers/client.go @@ -0,0 +1,26 @@ +package sqlpoolsworkloadclassifiers + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SqlPoolsWorkloadClassifiersClient struct { + Client *resourcemanager.Client +} + +func NewSqlPoolsWorkloadClassifiersClientWithBaseURI(sdkApi sdkEnv.Api) (*SqlPoolsWorkloadClassifiersClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "sqlpoolsworkloadclassifiers", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating SqlPoolsWorkloadClassifiersClient: %+v", err) + } + + return &SqlPoolsWorkloadClassifiersClient{ + Client: client, + }, nil +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolsworkloadclassifiers/id_workloadclassifier.go b/resource-manager/synapse/2021-06-01/sqlpoolsworkloadclassifiers/id_workloadclassifier.go new file mode 100644 index 00000000000..ed355fff853 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolsworkloadclassifiers/id_workloadclassifier.go @@ -0,0 +1,152 @@ +package sqlpoolsworkloadclassifiers + +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 = &WorkloadClassifierId{} + +// WorkloadClassifierId is a struct representing the Resource ID for a Workload Classifier +type WorkloadClassifierId struct { + SubscriptionId string + ResourceGroupName string + WorkspaceName string + SqlPoolName string + WorkloadGroupName string + WorkloadClassifierName string +} + +// NewWorkloadClassifierID returns a new WorkloadClassifierId struct +func NewWorkloadClassifierID(subscriptionId string, resourceGroupName string, workspaceName string, sqlPoolName string, workloadGroupName string, workloadClassifierName string) WorkloadClassifierId { + return WorkloadClassifierId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + WorkspaceName: workspaceName, + SqlPoolName: sqlPoolName, + WorkloadGroupName: workloadGroupName, + WorkloadClassifierName: workloadClassifierName, + } +} + +// ParseWorkloadClassifierID parses 'input' into a WorkloadClassifierId +func ParseWorkloadClassifierID(input string) (*WorkloadClassifierId, error) { + parser := resourceids.NewParserFromResourceIdType(&WorkloadClassifierId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := WorkloadClassifierId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseWorkloadClassifierIDInsensitively parses 'input' case-insensitively into a WorkloadClassifierId +// note: this method should only be used for API response data and not user input +func ParseWorkloadClassifierIDInsensitively(input string) (*WorkloadClassifierId, error) { + parser := resourceids.NewParserFromResourceIdType(&WorkloadClassifierId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := WorkloadClassifierId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *WorkloadClassifierId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.WorkspaceName, ok = input.Parsed["workspaceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "workspaceName", input) + } + + if id.SqlPoolName, ok = input.Parsed["sqlPoolName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "sqlPoolName", input) + } + + if id.WorkloadGroupName, ok = input.Parsed["workloadGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "workloadGroupName", input) + } + + if id.WorkloadClassifierName, ok = input.Parsed["workloadClassifierName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "workloadClassifierName", input) + } + + return nil +} + +// ValidateWorkloadClassifierID checks that 'input' can be parsed as a Workload Classifier ID +func ValidateWorkloadClassifierID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseWorkloadClassifierID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Workload Classifier ID +func (id WorkloadClassifierId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Synapse/workspaces/%s/sqlPools/%s/workloadGroups/%s/workloadClassifiers/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.WorkspaceName, id.SqlPoolName, id.WorkloadGroupName, id.WorkloadClassifierName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Workload Classifier ID +func (id WorkloadClassifierId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftSynapse", "Microsoft.Synapse", "Microsoft.Synapse"), + resourceids.StaticSegment("staticWorkspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceName", "workspaceValue"), + resourceids.StaticSegment("staticSqlPools", "sqlPools", "sqlPools"), + resourceids.UserSpecifiedSegment("sqlPoolName", "sqlPoolValue"), + resourceids.StaticSegment("staticWorkloadGroups", "workloadGroups", "workloadGroups"), + resourceids.UserSpecifiedSegment("workloadGroupName", "workloadGroupValue"), + resourceids.StaticSegment("staticWorkloadClassifiers", "workloadClassifiers", "workloadClassifiers"), + resourceids.UserSpecifiedSegment("workloadClassifierName", "workloadClassifierValue"), + } +} + +// String returns a human-readable description of this Workload Classifier ID +func (id WorkloadClassifierId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Workspace Name: %q", id.WorkspaceName), + fmt.Sprintf("Sql Pool Name: %q", id.SqlPoolName), + fmt.Sprintf("Workload Group Name: %q", id.WorkloadGroupName), + fmt.Sprintf("Workload Classifier Name: %q", id.WorkloadClassifierName), + } + return fmt.Sprintf("Workload Classifier (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolsworkloadclassifiers/id_workloadclassifier_test.go b/resource-manager/synapse/2021-06-01/sqlpoolsworkloadclassifiers/id_workloadclassifier_test.go new file mode 100644 index 00000000000..738f5b7fb82 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolsworkloadclassifiers/id_workloadclassifier_test.go @@ -0,0 +1,417 @@ +package sqlpoolsworkloadclassifiers + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &WorkloadClassifierId{} + +func TestNewWorkloadClassifierID(t *testing.T) { + id := NewWorkloadClassifierID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "sqlPoolValue", "workloadGroupValue", "workloadClassifierValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.WorkspaceName != "workspaceValue" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceName'", id.WorkspaceName, "workspaceValue") + } + + if id.SqlPoolName != "sqlPoolValue" { + t.Fatalf("Expected %q but got %q for Segment 'SqlPoolName'", id.SqlPoolName, "sqlPoolValue") + } + + if id.WorkloadGroupName != "workloadGroupValue" { + t.Fatalf("Expected %q but got %q for Segment 'WorkloadGroupName'", id.WorkloadGroupName, "workloadGroupValue") + } + + if id.WorkloadClassifierName != "workloadClassifierValue" { + t.Fatalf("Expected %q but got %q for Segment 'WorkloadClassifierName'", id.WorkloadClassifierName, "workloadClassifierValue") + } +} + +func TestFormatWorkloadClassifierID(t *testing.T) { + actual := NewWorkloadClassifierID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "sqlPoolValue", "workloadGroupValue", "workloadClassifierValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/workloadGroups/workloadGroupValue/workloadClassifiers/workloadClassifierValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseWorkloadClassifierID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkloadClassifierId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/workloadGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/workloadGroups/workloadGroupValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/workloadGroups/workloadGroupValue/workloadClassifiers", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/workloadGroups/workloadGroupValue/workloadClassifiers/workloadClassifierValue", + Expected: &WorkloadClassifierId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + SqlPoolName: "sqlPoolValue", + WorkloadGroupName: "workloadGroupValue", + WorkloadClassifierName: "workloadClassifierValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/workloadGroups/workloadGroupValue/workloadClassifiers/workloadClassifierValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkloadClassifierID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + if actual.SqlPoolName != v.Expected.SqlPoolName { + t.Fatalf("Expected %q but got %q for SqlPoolName", v.Expected.SqlPoolName, actual.SqlPoolName) + } + + if actual.WorkloadGroupName != v.Expected.WorkloadGroupName { + t.Fatalf("Expected %q but got %q for WorkloadGroupName", v.Expected.WorkloadGroupName, actual.WorkloadGroupName) + } + + if actual.WorkloadClassifierName != v.Expected.WorkloadClassifierName { + t.Fatalf("Expected %q but got %q for WorkloadClassifierName", v.Expected.WorkloadClassifierName, actual.WorkloadClassifierName) + } + + } +} + +func TestParseWorkloadClassifierIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkloadClassifierId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/sQlPoOlS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/sQlPoOlS/sQlPoOlVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/workloadGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/sQlPoOlS/sQlPoOlVaLuE/wOrKlOaDgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/workloadGroups/workloadGroupValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/sQlPoOlS/sQlPoOlVaLuE/wOrKlOaDgRoUpS/wOrKlOaDgRoUpVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/workloadGroups/workloadGroupValue/workloadClassifiers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/sQlPoOlS/sQlPoOlVaLuE/wOrKlOaDgRoUpS/wOrKlOaDgRoUpVaLuE/wOrKlOaDcLaSsIfIeRs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/workloadGroups/workloadGroupValue/workloadClassifiers/workloadClassifierValue", + Expected: &WorkloadClassifierId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + SqlPoolName: "sqlPoolValue", + WorkloadGroupName: "workloadGroupValue", + WorkloadClassifierName: "workloadClassifierValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/workloadGroups/workloadGroupValue/workloadClassifiers/workloadClassifierValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/sQlPoOlS/sQlPoOlVaLuE/wOrKlOaDgRoUpS/wOrKlOaDgRoUpVaLuE/wOrKlOaDcLaSsIfIeRs/wOrKlOaDcLaSsIfIeRvAlUe", + Expected: &WorkloadClassifierId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + WorkspaceName: "wOrKsPaCeVaLuE", + SqlPoolName: "sQlPoOlVaLuE", + WorkloadGroupName: "wOrKlOaDgRoUpVaLuE", + WorkloadClassifierName: "wOrKlOaDcLaSsIfIeRvAlUe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/sQlPoOlS/sQlPoOlVaLuE/wOrKlOaDgRoUpS/wOrKlOaDgRoUpVaLuE/wOrKlOaDcLaSsIfIeRs/wOrKlOaDcLaSsIfIeRvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkloadClassifierIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + if actual.SqlPoolName != v.Expected.SqlPoolName { + t.Fatalf("Expected %q but got %q for SqlPoolName", v.Expected.SqlPoolName, actual.SqlPoolName) + } + + if actual.WorkloadGroupName != v.Expected.WorkloadGroupName { + t.Fatalf("Expected %q but got %q for WorkloadGroupName", v.Expected.WorkloadGroupName, actual.WorkloadGroupName) + } + + if actual.WorkloadClassifierName != v.Expected.WorkloadClassifierName { + t.Fatalf("Expected %q but got %q for WorkloadClassifierName", v.Expected.WorkloadClassifierName, actual.WorkloadClassifierName) + } + + } +} + +func TestSegmentsForWorkloadClassifierId(t *testing.T) { + segments := WorkloadClassifierId{}.Segments() + if len(segments) == 0 { + t.Fatalf("WorkloadClassifierId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolsworkloadclassifiers/id_workloadgroup.go b/resource-manager/synapse/2021-06-01/sqlpoolsworkloadclassifiers/id_workloadgroup.go new file mode 100644 index 00000000000..c82bd2f937f --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolsworkloadclassifiers/id_workloadgroup.go @@ -0,0 +1,143 @@ +package sqlpoolsworkloadclassifiers + +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 = &WorkloadGroupId{} + +// WorkloadGroupId is a struct representing the Resource ID for a Workload Group +type WorkloadGroupId struct { + SubscriptionId string + ResourceGroupName string + WorkspaceName string + SqlPoolName string + WorkloadGroupName string +} + +// NewWorkloadGroupID returns a new WorkloadGroupId struct +func NewWorkloadGroupID(subscriptionId string, resourceGroupName string, workspaceName string, sqlPoolName string, workloadGroupName string) WorkloadGroupId { + return WorkloadGroupId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + WorkspaceName: workspaceName, + SqlPoolName: sqlPoolName, + WorkloadGroupName: workloadGroupName, + } +} + +// ParseWorkloadGroupID parses 'input' into a WorkloadGroupId +func ParseWorkloadGroupID(input string) (*WorkloadGroupId, error) { + parser := resourceids.NewParserFromResourceIdType(&WorkloadGroupId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := WorkloadGroupId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseWorkloadGroupIDInsensitively parses 'input' case-insensitively into a WorkloadGroupId +// note: this method should only be used for API response data and not user input +func ParseWorkloadGroupIDInsensitively(input string) (*WorkloadGroupId, error) { + parser := resourceids.NewParserFromResourceIdType(&WorkloadGroupId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := WorkloadGroupId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *WorkloadGroupId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.WorkspaceName, ok = input.Parsed["workspaceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "workspaceName", input) + } + + if id.SqlPoolName, ok = input.Parsed["sqlPoolName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "sqlPoolName", input) + } + + if id.WorkloadGroupName, ok = input.Parsed["workloadGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "workloadGroupName", input) + } + + return nil +} + +// ValidateWorkloadGroupID checks that 'input' can be parsed as a Workload Group ID +func ValidateWorkloadGroupID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseWorkloadGroupID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Workload Group ID +func (id WorkloadGroupId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Synapse/workspaces/%s/sqlPools/%s/workloadGroups/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.WorkspaceName, id.SqlPoolName, id.WorkloadGroupName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Workload Group ID +func (id WorkloadGroupId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftSynapse", "Microsoft.Synapse", "Microsoft.Synapse"), + resourceids.StaticSegment("staticWorkspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceName", "workspaceValue"), + resourceids.StaticSegment("staticSqlPools", "sqlPools", "sqlPools"), + resourceids.UserSpecifiedSegment("sqlPoolName", "sqlPoolValue"), + resourceids.StaticSegment("staticWorkloadGroups", "workloadGroups", "workloadGroups"), + resourceids.UserSpecifiedSegment("workloadGroupName", "workloadGroupValue"), + } +} + +// String returns a human-readable description of this Workload Group ID +func (id WorkloadGroupId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Workspace Name: %q", id.WorkspaceName), + fmt.Sprintf("Sql Pool Name: %q", id.SqlPoolName), + fmt.Sprintf("Workload Group Name: %q", id.WorkloadGroupName), + } + return fmt.Sprintf("Workload Group (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolsworkloadclassifiers/id_workloadgroup_test.go b/resource-manager/synapse/2021-06-01/sqlpoolsworkloadclassifiers/id_workloadgroup_test.go new file mode 100644 index 00000000000..9c27961336f --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolsworkloadclassifiers/id_workloadgroup_test.go @@ -0,0 +1,372 @@ +package sqlpoolsworkloadclassifiers + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &WorkloadGroupId{} + +func TestNewWorkloadGroupID(t *testing.T) { + id := NewWorkloadGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "sqlPoolValue", "workloadGroupValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.WorkspaceName != "workspaceValue" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceName'", id.WorkspaceName, "workspaceValue") + } + + if id.SqlPoolName != "sqlPoolValue" { + t.Fatalf("Expected %q but got %q for Segment 'SqlPoolName'", id.SqlPoolName, "sqlPoolValue") + } + + if id.WorkloadGroupName != "workloadGroupValue" { + t.Fatalf("Expected %q but got %q for Segment 'WorkloadGroupName'", id.WorkloadGroupName, "workloadGroupValue") + } +} + +func TestFormatWorkloadGroupID(t *testing.T) { + actual := NewWorkloadGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "sqlPoolValue", "workloadGroupValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/workloadGroups/workloadGroupValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseWorkloadGroupID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkloadGroupId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/workloadGroups", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/workloadGroups/workloadGroupValue", + Expected: &WorkloadGroupId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + SqlPoolName: "sqlPoolValue", + WorkloadGroupName: "workloadGroupValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/workloadGroups/workloadGroupValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkloadGroupID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + if actual.SqlPoolName != v.Expected.SqlPoolName { + t.Fatalf("Expected %q but got %q for SqlPoolName", v.Expected.SqlPoolName, actual.SqlPoolName) + } + + if actual.WorkloadGroupName != v.Expected.WorkloadGroupName { + t.Fatalf("Expected %q but got %q for WorkloadGroupName", v.Expected.WorkloadGroupName, actual.WorkloadGroupName) + } + + } +} + +func TestParseWorkloadGroupIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkloadGroupId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/sQlPoOlS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/sQlPoOlS/sQlPoOlVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/workloadGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/sQlPoOlS/sQlPoOlVaLuE/wOrKlOaDgRoUpS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/workloadGroups/workloadGroupValue", + Expected: &WorkloadGroupId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + SqlPoolName: "sqlPoolValue", + WorkloadGroupName: "workloadGroupValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/workloadGroups/workloadGroupValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/sQlPoOlS/sQlPoOlVaLuE/wOrKlOaDgRoUpS/wOrKlOaDgRoUpVaLuE", + Expected: &WorkloadGroupId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + WorkspaceName: "wOrKsPaCeVaLuE", + SqlPoolName: "sQlPoOlVaLuE", + WorkloadGroupName: "wOrKlOaDgRoUpVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/sQlPoOlS/sQlPoOlVaLuE/wOrKlOaDgRoUpS/wOrKlOaDgRoUpVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkloadGroupIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + if actual.SqlPoolName != v.Expected.SqlPoolName { + t.Fatalf("Expected %q but got %q for SqlPoolName", v.Expected.SqlPoolName, actual.SqlPoolName) + } + + if actual.WorkloadGroupName != v.Expected.WorkloadGroupName { + t.Fatalf("Expected %q but got %q for WorkloadGroupName", v.Expected.WorkloadGroupName, actual.WorkloadGroupName) + } + + } +} + +func TestSegmentsForWorkloadGroupId(t *testing.T) { + segments := WorkloadGroupId{}.Segments() + if len(segments) == 0 { + t.Fatalf("WorkloadGroupId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolsworkloadclassifiers/method_sqlpoolworkloadclassifiercreateorupdate.go b/resource-manager/synapse/2021-06-01/sqlpoolsworkloadclassifiers/method_sqlpoolworkloadclassifiercreateorupdate.go new file mode 100644 index 00000000000..73f20ae3bfe --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolsworkloadclassifiers/method_sqlpoolworkloadclassifiercreateorupdate.go @@ -0,0 +1,76 @@ +package sqlpoolsworkloadclassifiers + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SqlPoolWorkloadClassifierCreateOrUpdateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *WorkloadClassifier +} + +// SqlPoolWorkloadClassifierCreateOrUpdate ... +func (c SqlPoolsWorkloadClassifiersClient) SqlPoolWorkloadClassifierCreateOrUpdate(ctx context.Context, id WorkloadClassifierId, input WorkloadClassifier) (result SqlPoolWorkloadClassifierCreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// SqlPoolWorkloadClassifierCreateOrUpdateThenPoll performs SqlPoolWorkloadClassifierCreateOrUpdate then polls until it's completed +func (c SqlPoolsWorkloadClassifiersClient) SqlPoolWorkloadClassifierCreateOrUpdateThenPoll(ctx context.Context, id WorkloadClassifierId, input WorkloadClassifier) error { + result, err := c.SqlPoolWorkloadClassifierCreateOrUpdate(ctx, id, input) + if err != nil { + return fmt.Errorf("performing SqlPoolWorkloadClassifierCreateOrUpdate: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after SqlPoolWorkloadClassifierCreateOrUpdate: %+v", err) + } + + return nil +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolsworkloadclassifiers/method_sqlpoolworkloadclassifierdelete.go b/resource-manager/synapse/2021-06-01/sqlpoolsworkloadclassifiers/method_sqlpoolworkloadclassifierdelete.go new file mode 100644 index 00000000000..7419085942b --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolsworkloadclassifiers/method_sqlpoolworkloadclassifierdelete.go @@ -0,0 +1,71 @@ +package sqlpoolsworkloadclassifiers + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SqlPoolWorkloadClassifierDeleteOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// SqlPoolWorkloadClassifierDelete ... +func (c SqlPoolsWorkloadClassifiersClient) SqlPoolWorkloadClassifierDelete(ctx context.Context, id WorkloadClassifierId) (result SqlPoolWorkloadClassifierDeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// SqlPoolWorkloadClassifierDeleteThenPoll performs SqlPoolWorkloadClassifierDelete then polls until it's completed +func (c SqlPoolsWorkloadClassifiersClient) SqlPoolWorkloadClassifierDeleteThenPoll(ctx context.Context, id WorkloadClassifierId) error { + result, err := c.SqlPoolWorkloadClassifierDelete(ctx, id) + if err != nil { + return fmt.Errorf("performing SqlPoolWorkloadClassifierDelete: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after SqlPoolWorkloadClassifierDelete: %+v", err) + } + + return nil +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolsworkloadclassifiers/method_sqlpoolworkloadclassifierget.go b/resource-manager/synapse/2021-06-01/sqlpoolsworkloadclassifiers/method_sqlpoolworkloadclassifierget.go new file mode 100644 index 00000000000..238bcfffa0f --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolsworkloadclassifiers/method_sqlpoolworkloadclassifierget.go @@ -0,0 +1,51 @@ +package sqlpoolsworkloadclassifiers + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SqlPoolWorkloadClassifierGetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *WorkloadClassifier +} + +// SqlPoolWorkloadClassifierGet ... +func (c SqlPoolsWorkloadClassifiersClient) SqlPoolWorkloadClassifierGet(ctx context.Context, id WorkloadClassifierId) (result SqlPoolWorkloadClassifierGetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolsworkloadclassifiers/method_sqlpoolworkloadclassifierlist.go b/resource-manager/synapse/2021-06-01/sqlpoolsworkloadclassifiers/method_sqlpoolworkloadclassifierlist.go new file mode 100644 index 00000000000..369144f8861 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolsworkloadclassifiers/method_sqlpoolworkloadclassifierlist.go @@ -0,0 +1,91 @@ +package sqlpoolsworkloadclassifiers + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SqlPoolWorkloadClassifierListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]WorkloadClassifier +} + +type SqlPoolWorkloadClassifierListCompleteResult struct { + LatestHttpResponse *http.Response + Items []WorkloadClassifier +} + +// SqlPoolWorkloadClassifierList ... +func (c SqlPoolsWorkloadClassifiersClient) SqlPoolWorkloadClassifierList(ctx context.Context, id WorkloadGroupId) (result SqlPoolWorkloadClassifierListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/workloadClassifiers", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]WorkloadClassifier `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// SqlPoolWorkloadClassifierListComplete retrieves all the results into a single object +func (c SqlPoolsWorkloadClassifiersClient) SqlPoolWorkloadClassifierListComplete(ctx context.Context, id WorkloadGroupId) (SqlPoolWorkloadClassifierListCompleteResult, error) { + return c.SqlPoolWorkloadClassifierListCompleteMatchingPredicate(ctx, id, WorkloadClassifierOperationPredicate{}) +} + +// SqlPoolWorkloadClassifierListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c SqlPoolsWorkloadClassifiersClient) SqlPoolWorkloadClassifierListCompleteMatchingPredicate(ctx context.Context, id WorkloadGroupId, predicate WorkloadClassifierOperationPredicate) (result SqlPoolWorkloadClassifierListCompleteResult, err error) { + items := make([]WorkloadClassifier, 0) + + resp, err := c.SqlPoolWorkloadClassifierList(ctx, id) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = SqlPoolWorkloadClassifierListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolsworkloadclassifiers/model_workloadclassifier.go b/resource-manager/synapse/2021-06-01/sqlpoolsworkloadclassifiers/model_workloadclassifier.go new file mode 100644 index 00000000000..25ebae3de27 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolsworkloadclassifiers/model_workloadclassifier.go @@ -0,0 +1,11 @@ +package sqlpoolsworkloadclassifiers + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type WorkloadClassifier struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *WorkloadClassifierProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolsworkloadclassifiers/model_workloadclassifierproperties.go b/resource-manager/synapse/2021-06-01/sqlpoolsworkloadclassifiers/model_workloadclassifierproperties.go new file mode 100644 index 00000000000..6fd79354394 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolsworkloadclassifiers/model_workloadclassifierproperties.go @@ -0,0 +1,13 @@ +package sqlpoolsworkloadclassifiers + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type WorkloadClassifierProperties struct { + Context *string `json:"context,omitempty"` + EndTime *string `json:"endTime,omitempty"` + Importance *string `json:"importance,omitempty"` + Label *string `json:"label,omitempty"` + MemberName string `json:"memberName"` + StartTime *string `json:"startTime,omitempty"` +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolsworkloadclassifiers/predicates.go b/resource-manager/synapse/2021-06-01/sqlpoolsworkloadclassifiers/predicates.go new file mode 100644 index 00000000000..18337d8a769 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolsworkloadclassifiers/predicates.go @@ -0,0 +1,27 @@ +package sqlpoolsworkloadclassifiers + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type WorkloadClassifierOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p WorkloadClassifierOperationPredicate) Matches(input WorkloadClassifier) bool { + + if p.Id != nil && (input.Id == nil || *p.Id != *input.Id) { + return false + } + + if p.Name != nil && (input.Name == nil || *p.Name != *input.Name) { + return false + } + + if p.Type != nil && (input.Type == nil || *p.Type != *input.Type) { + return false + } + + return true +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolsworkloadclassifiers/version.go b/resource-manager/synapse/2021-06-01/sqlpoolsworkloadclassifiers/version.go new file mode 100644 index 00000000000..8f5e6480847 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolsworkloadclassifiers/version.go @@ -0,0 +1,12 @@ +package sqlpoolsworkloadclassifiers + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2021-06-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/sqlpoolsworkloadclassifiers/%s", defaultApiVersion) +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolsworkloadgroups/README.md b/resource-manager/synapse/2021-06-01/sqlpoolsworkloadgroups/README.md new file mode 100644 index 00000000000..5d44c77acc5 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolsworkloadgroups/README.md @@ -0,0 +1,82 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/synapse/2021-06-01/sqlpoolsworkloadgroups` Documentation + +The `sqlpoolsworkloadgroups` SDK allows for interaction with the Azure Resource Manager Service `synapse` (API Version `2021-06-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/synapse/2021-06-01/sqlpoolsworkloadgroups" +``` + + +### Client Initialization + +```go +client := sqlpoolsworkloadgroups.NewSqlPoolsWorkloadGroupsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `SqlPoolsWorkloadGroupsClient.SqlPoolWorkloadGroupCreateOrUpdate` + +```go +ctx := context.TODO() +id := sqlpoolsworkloadgroups.NewWorkloadGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "sqlPoolValue", "workloadGroupValue") + +payload := sqlpoolsworkloadgroups.WorkloadGroup{ + // ... +} + + +if err := client.SqlPoolWorkloadGroupCreateOrUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `SqlPoolsWorkloadGroupsClient.SqlPoolWorkloadGroupDelete` + +```go +ctx := context.TODO() +id := sqlpoolsworkloadgroups.NewWorkloadGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "sqlPoolValue", "workloadGroupValue") + +if err := client.SqlPoolWorkloadGroupDeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `SqlPoolsWorkloadGroupsClient.SqlPoolWorkloadGroupGet` + +```go +ctx := context.TODO() +id := sqlpoolsworkloadgroups.NewWorkloadGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "sqlPoolValue", "workloadGroupValue") + +read, err := client.SqlPoolWorkloadGroupGet(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `SqlPoolsWorkloadGroupsClient.SqlPoolWorkloadGroupList` + +```go +ctx := context.TODO() +id := sqlpoolsworkloadgroups.NewSqlPoolID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "sqlPoolValue") + +// alternatively `client.SqlPoolWorkloadGroupList(ctx, id)` can be used to do batched pagination +items, err := client.SqlPoolWorkloadGroupListComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/synapse/2021-06-01/sqlpoolsworkloadgroups/client.go b/resource-manager/synapse/2021-06-01/sqlpoolsworkloadgroups/client.go new file mode 100644 index 00000000000..62d97be546e --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolsworkloadgroups/client.go @@ -0,0 +1,26 @@ +package sqlpoolsworkloadgroups + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SqlPoolsWorkloadGroupsClient struct { + Client *resourcemanager.Client +} + +func NewSqlPoolsWorkloadGroupsClientWithBaseURI(sdkApi sdkEnv.Api) (*SqlPoolsWorkloadGroupsClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "sqlpoolsworkloadgroups", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating SqlPoolsWorkloadGroupsClient: %+v", err) + } + + return &SqlPoolsWorkloadGroupsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolsworkloadgroups/id_sqlpool.go b/resource-manager/synapse/2021-06-01/sqlpoolsworkloadgroups/id_sqlpool.go new file mode 100644 index 00000000000..d0a34121d81 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolsworkloadgroups/id_sqlpool.go @@ -0,0 +1,134 @@ +package sqlpoolsworkloadgroups + +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 = &SqlPoolId{} + +// SqlPoolId is a struct representing the Resource ID for a Sql Pool +type SqlPoolId struct { + SubscriptionId string + ResourceGroupName string + WorkspaceName string + SqlPoolName string +} + +// NewSqlPoolID returns a new SqlPoolId struct +func NewSqlPoolID(subscriptionId string, resourceGroupName string, workspaceName string, sqlPoolName string) SqlPoolId { + return SqlPoolId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + WorkspaceName: workspaceName, + SqlPoolName: sqlPoolName, + } +} + +// ParseSqlPoolID parses 'input' into a SqlPoolId +func ParseSqlPoolID(input string) (*SqlPoolId, error) { + parser := resourceids.NewParserFromResourceIdType(&SqlPoolId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := SqlPoolId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseSqlPoolIDInsensitively parses 'input' case-insensitively into a SqlPoolId +// note: this method should only be used for API response data and not user input +func ParseSqlPoolIDInsensitively(input string) (*SqlPoolId, error) { + parser := resourceids.NewParserFromResourceIdType(&SqlPoolId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := SqlPoolId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *SqlPoolId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.WorkspaceName, ok = input.Parsed["workspaceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "workspaceName", input) + } + + if id.SqlPoolName, ok = input.Parsed["sqlPoolName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "sqlPoolName", input) + } + + return nil +} + +// ValidateSqlPoolID checks that 'input' can be parsed as a Sql Pool ID +func ValidateSqlPoolID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseSqlPoolID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Sql Pool ID +func (id SqlPoolId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Synapse/workspaces/%s/sqlPools/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.WorkspaceName, id.SqlPoolName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Sql Pool ID +func (id SqlPoolId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftSynapse", "Microsoft.Synapse", "Microsoft.Synapse"), + resourceids.StaticSegment("staticWorkspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceName", "workspaceValue"), + resourceids.StaticSegment("staticSqlPools", "sqlPools", "sqlPools"), + resourceids.UserSpecifiedSegment("sqlPoolName", "sqlPoolValue"), + } +} + +// String returns a human-readable description of this Sql Pool ID +func (id SqlPoolId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Workspace Name: %q", id.WorkspaceName), + fmt.Sprintf("Sql Pool Name: %q", id.SqlPoolName), + } + return fmt.Sprintf("Sql Pool (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolsworkloadgroups/id_sqlpool_test.go b/resource-manager/synapse/2021-06-01/sqlpoolsworkloadgroups/id_sqlpool_test.go new file mode 100644 index 00000000000..26e86c93495 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolsworkloadgroups/id_sqlpool_test.go @@ -0,0 +1,327 @@ +package sqlpoolsworkloadgroups + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &SqlPoolId{} + +func TestNewSqlPoolID(t *testing.T) { + id := NewSqlPoolID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "sqlPoolValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.WorkspaceName != "workspaceValue" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceName'", id.WorkspaceName, "workspaceValue") + } + + if id.SqlPoolName != "sqlPoolValue" { + t.Fatalf("Expected %q but got %q for Segment 'SqlPoolName'", id.SqlPoolName, "sqlPoolValue") + } +} + +func TestFormatSqlPoolID(t *testing.T) { + actual := NewSqlPoolID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "sqlPoolValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseSqlPoolID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *SqlPoolId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue", + Expected: &SqlPoolId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + SqlPoolName: "sqlPoolValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseSqlPoolID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + if actual.SqlPoolName != v.Expected.SqlPoolName { + t.Fatalf("Expected %q but got %q for SqlPoolName", v.Expected.SqlPoolName, actual.SqlPoolName) + } + + } +} + +func TestParseSqlPoolIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *SqlPoolId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/sQlPoOlS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue", + Expected: &SqlPoolId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + SqlPoolName: "sqlPoolValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/sQlPoOlS/sQlPoOlVaLuE", + Expected: &SqlPoolId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + WorkspaceName: "wOrKsPaCeVaLuE", + SqlPoolName: "sQlPoOlVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/sQlPoOlS/sQlPoOlVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseSqlPoolIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + if actual.SqlPoolName != v.Expected.SqlPoolName { + t.Fatalf("Expected %q but got %q for SqlPoolName", v.Expected.SqlPoolName, actual.SqlPoolName) + } + + } +} + +func TestSegmentsForSqlPoolId(t *testing.T) { + segments := SqlPoolId{}.Segments() + if len(segments) == 0 { + t.Fatalf("SqlPoolId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolsworkloadgroups/id_workloadgroup.go b/resource-manager/synapse/2021-06-01/sqlpoolsworkloadgroups/id_workloadgroup.go new file mode 100644 index 00000000000..b2f29724a51 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolsworkloadgroups/id_workloadgroup.go @@ -0,0 +1,143 @@ +package sqlpoolsworkloadgroups + +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 = &WorkloadGroupId{} + +// WorkloadGroupId is a struct representing the Resource ID for a Workload Group +type WorkloadGroupId struct { + SubscriptionId string + ResourceGroupName string + WorkspaceName string + SqlPoolName string + WorkloadGroupName string +} + +// NewWorkloadGroupID returns a new WorkloadGroupId struct +func NewWorkloadGroupID(subscriptionId string, resourceGroupName string, workspaceName string, sqlPoolName string, workloadGroupName string) WorkloadGroupId { + return WorkloadGroupId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + WorkspaceName: workspaceName, + SqlPoolName: sqlPoolName, + WorkloadGroupName: workloadGroupName, + } +} + +// ParseWorkloadGroupID parses 'input' into a WorkloadGroupId +func ParseWorkloadGroupID(input string) (*WorkloadGroupId, error) { + parser := resourceids.NewParserFromResourceIdType(&WorkloadGroupId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := WorkloadGroupId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseWorkloadGroupIDInsensitively parses 'input' case-insensitively into a WorkloadGroupId +// note: this method should only be used for API response data and not user input +func ParseWorkloadGroupIDInsensitively(input string) (*WorkloadGroupId, error) { + parser := resourceids.NewParserFromResourceIdType(&WorkloadGroupId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := WorkloadGroupId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *WorkloadGroupId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.WorkspaceName, ok = input.Parsed["workspaceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "workspaceName", input) + } + + if id.SqlPoolName, ok = input.Parsed["sqlPoolName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "sqlPoolName", input) + } + + if id.WorkloadGroupName, ok = input.Parsed["workloadGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "workloadGroupName", input) + } + + return nil +} + +// ValidateWorkloadGroupID checks that 'input' can be parsed as a Workload Group ID +func ValidateWorkloadGroupID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseWorkloadGroupID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Workload Group ID +func (id WorkloadGroupId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Synapse/workspaces/%s/sqlPools/%s/workloadGroups/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.WorkspaceName, id.SqlPoolName, id.WorkloadGroupName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Workload Group ID +func (id WorkloadGroupId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftSynapse", "Microsoft.Synapse", "Microsoft.Synapse"), + resourceids.StaticSegment("staticWorkspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceName", "workspaceValue"), + resourceids.StaticSegment("staticSqlPools", "sqlPools", "sqlPools"), + resourceids.UserSpecifiedSegment("sqlPoolName", "sqlPoolValue"), + resourceids.StaticSegment("staticWorkloadGroups", "workloadGroups", "workloadGroups"), + resourceids.UserSpecifiedSegment("workloadGroupName", "workloadGroupValue"), + } +} + +// String returns a human-readable description of this Workload Group ID +func (id WorkloadGroupId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Workspace Name: %q", id.WorkspaceName), + fmt.Sprintf("Sql Pool Name: %q", id.SqlPoolName), + fmt.Sprintf("Workload Group Name: %q", id.WorkloadGroupName), + } + return fmt.Sprintf("Workload Group (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolsworkloadgroups/id_workloadgroup_test.go b/resource-manager/synapse/2021-06-01/sqlpoolsworkloadgroups/id_workloadgroup_test.go new file mode 100644 index 00000000000..516e81c20b6 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolsworkloadgroups/id_workloadgroup_test.go @@ -0,0 +1,372 @@ +package sqlpoolsworkloadgroups + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &WorkloadGroupId{} + +func TestNewWorkloadGroupID(t *testing.T) { + id := NewWorkloadGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "sqlPoolValue", "workloadGroupValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.WorkspaceName != "workspaceValue" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceName'", id.WorkspaceName, "workspaceValue") + } + + if id.SqlPoolName != "sqlPoolValue" { + t.Fatalf("Expected %q but got %q for Segment 'SqlPoolName'", id.SqlPoolName, "sqlPoolValue") + } + + if id.WorkloadGroupName != "workloadGroupValue" { + t.Fatalf("Expected %q but got %q for Segment 'WorkloadGroupName'", id.WorkloadGroupName, "workloadGroupValue") + } +} + +func TestFormatWorkloadGroupID(t *testing.T) { + actual := NewWorkloadGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "sqlPoolValue", "workloadGroupValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/workloadGroups/workloadGroupValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseWorkloadGroupID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkloadGroupId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/workloadGroups", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/workloadGroups/workloadGroupValue", + Expected: &WorkloadGroupId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + SqlPoolName: "sqlPoolValue", + WorkloadGroupName: "workloadGroupValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/workloadGroups/workloadGroupValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkloadGroupID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + if actual.SqlPoolName != v.Expected.SqlPoolName { + t.Fatalf("Expected %q but got %q for SqlPoolName", v.Expected.SqlPoolName, actual.SqlPoolName) + } + + if actual.WorkloadGroupName != v.Expected.WorkloadGroupName { + t.Fatalf("Expected %q but got %q for WorkloadGroupName", v.Expected.WorkloadGroupName, actual.WorkloadGroupName) + } + + } +} + +func TestParseWorkloadGroupIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkloadGroupId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/sQlPoOlS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/sQlPoOlS/sQlPoOlVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/workloadGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/sQlPoOlS/sQlPoOlVaLuE/wOrKlOaDgRoUpS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/workloadGroups/workloadGroupValue", + Expected: &WorkloadGroupId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + SqlPoolName: "sqlPoolValue", + WorkloadGroupName: "workloadGroupValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/sqlPools/sqlPoolValue/workloadGroups/workloadGroupValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/sQlPoOlS/sQlPoOlVaLuE/wOrKlOaDgRoUpS/wOrKlOaDgRoUpVaLuE", + Expected: &WorkloadGroupId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + WorkspaceName: "wOrKsPaCeVaLuE", + SqlPoolName: "sQlPoOlVaLuE", + WorkloadGroupName: "wOrKlOaDgRoUpVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/sQlPoOlS/sQlPoOlVaLuE/wOrKlOaDgRoUpS/wOrKlOaDgRoUpVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkloadGroupIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + if actual.SqlPoolName != v.Expected.SqlPoolName { + t.Fatalf("Expected %q but got %q for SqlPoolName", v.Expected.SqlPoolName, actual.SqlPoolName) + } + + if actual.WorkloadGroupName != v.Expected.WorkloadGroupName { + t.Fatalf("Expected %q but got %q for WorkloadGroupName", v.Expected.WorkloadGroupName, actual.WorkloadGroupName) + } + + } +} + +func TestSegmentsForWorkloadGroupId(t *testing.T) { + segments := WorkloadGroupId{}.Segments() + if len(segments) == 0 { + t.Fatalf("WorkloadGroupId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolsworkloadgroups/method_sqlpoolworkloadgroupcreateorupdate.go b/resource-manager/synapse/2021-06-01/sqlpoolsworkloadgroups/method_sqlpoolworkloadgroupcreateorupdate.go new file mode 100644 index 00000000000..bf6c1a3fcb1 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolsworkloadgroups/method_sqlpoolworkloadgroupcreateorupdate.go @@ -0,0 +1,76 @@ +package sqlpoolsworkloadgroups + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SqlPoolWorkloadGroupCreateOrUpdateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *WorkloadGroup +} + +// SqlPoolWorkloadGroupCreateOrUpdate ... +func (c SqlPoolsWorkloadGroupsClient) SqlPoolWorkloadGroupCreateOrUpdate(ctx context.Context, id WorkloadGroupId, input WorkloadGroup) (result SqlPoolWorkloadGroupCreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// SqlPoolWorkloadGroupCreateOrUpdateThenPoll performs SqlPoolWorkloadGroupCreateOrUpdate then polls until it's completed +func (c SqlPoolsWorkloadGroupsClient) SqlPoolWorkloadGroupCreateOrUpdateThenPoll(ctx context.Context, id WorkloadGroupId, input WorkloadGroup) error { + result, err := c.SqlPoolWorkloadGroupCreateOrUpdate(ctx, id, input) + if err != nil { + return fmt.Errorf("performing SqlPoolWorkloadGroupCreateOrUpdate: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after SqlPoolWorkloadGroupCreateOrUpdate: %+v", err) + } + + return nil +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolsworkloadgroups/method_sqlpoolworkloadgroupdelete.go b/resource-manager/synapse/2021-06-01/sqlpoolsworkloadgroups/method_sqlpoolworkloadgroupdelete.go new file mode 100644 index 00000000000..c4ef5f4bbf2 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolsworkloadgroups/method_sqlpoolworkloadgroupdelete.go @@ -0,0 +1,71 @@ +package sqlpoolsworkloadgroups + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SqlPoolWorkloadGroupDeleteOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// SqlPoolWorkloadGroupDelete ... +func (c SqlPoolsWorkloadGroupsClient) SqlPoolWorkloadGroupDelete(ctx context.Context, id WorkloadGroupId) (result SqlPoolWorkloadGroupDeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// SqlPoolWorkloadGroupDeleteThenPoll performs SqlPoolWorkloadGroupDelete then polls until it's completed +func (c SqlPoolsWorkloadGroupsClient) SqlPoolWorkloadGroupDeleteThenPoll(ctx context.Context, id WorkloadGroupId) error { + result, err := c.SqlPoolWorkloadGroupDelete(ctx, id) + if err != nil { + return fmt.Errorf("performing SqlPoolWorkloadGroupDelete: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after SqlPoolWorkloadGroupDelete: %+v", err) + } + + return nil +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolsworkloadgroups/method_sqlpoolworkloadgroupget.go b/resource-manager/synapse/2021-06-01/sqlpoolsworkloadgroups/method_sqlpoolworkloadgroupget.go new file mode 100644 index 00000000000..73b905baf23 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolsworkloadgroups/method_sqlpoolworkloadgroupget.go @@ -0,0 +1,51 @@ +package sqlpoolsworkloadgroups + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SqlPoolWorkloadGroupGetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *WorkloadGroup +} + +// SqlPoolWorkloadGroupGet ... +func (c SqlPoolsWorkloadGroupsClient) SqlPoolWorkloadGroupGet(ctx context.Context, id WorkloadGroupId) (result SqlPoolWorkloadGroupGetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolsworkloadgroups/method_sqlpoolworkloadgrouplist.go b/resource-manager/synapse/2021-06-01/sqlpoolsworkloadgroups/method_sqlpoolworkloadgrouplist.go new file mode 100644 index 00000000000..a3aa3ac98c0 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolsworkloadgroups/method_sqlpoolworkloadgrouplist.go @@ -0,0 +1,91 @@ +package sqlpoolsworkloadgroups + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SqlPoolWorkloadGroupListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]WorkloadGroup +} + +type SqlPoolWorkloadGroupListCompleteResult struct { + LatestHttpResponse *http.Response + Items []WorkloadGroup +} + +// SqlPoolWorkloadGroupList ... +func (c SqlPoolsWorkloadGroupsClient) SqlPoolWorkloadGroupList(ctx context.Context, id SqlPoolId) (result SqlPoolWorkloadGroupListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/workloadGroups", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]WorkloadGroup `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// SqlPoolWorkloadGroupListComplete retrieves all the results into a single object +func (c SqlPoolsWorkloadGroupsClient) SqlPoolWorkloadGroupListComplete(ctx context.Context, id SqlPoolId) (SqlPoolWorkloadGroupListCompleteResult, error) { + return c.SqlPoolWorkloadGroupListCompleteMatchingPredicate(ctx, id, WorkloadGroupOperationPredicate{}) +} + +// SqlPoolWorkloadGroupListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c SqlPoolsWorkloadGroupsClient) SqlPoolWorkloadGroupListCompleteMatchingPredicate(ctx context.Context, id SqlPoolId, predicate WorkloadGroupOperationPredicate) (result SqlPoolWorkloadGroupListCompleteResult, err error) { + items := make([]WorkloadGroup, 0) + + resp, err := c.SqlPoolWorkloadGroupList(ctx, id) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = SqlPoolWorkloadGroupListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolsworkloadgroups/model_workloadgroup.go b/resource-manager/synapse/2021-06-01/sqlpoolsworkloadgroups/model_workloadgroup.go new file mode 100644 index 00000000000..17cd892ae36 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolsworkloadgroups/model_workloadgroup.go @@ -0,0 +1,11 @@ +package sqlpoolsworkloadgroups + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type WorkloadGroup struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *WorkloadGroupProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolsworkloadgroups/model_workloadgroupproperties.go b/resource-manager/synapse/2021-06-01/sqlpoolsworkloadgroups/model_workloadgroupproperties.go new file mode 100644 index 00000000000..47f258d5387 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolsworkloadgroups/model_workloadgroupproperties.go @@ -0,0 +1,13 @@ +package sqlpoolsworkloadgroups + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type WorkloadGroupProperties struct { + Importance *string `json:"importance,omitempty"` + MaxResourcePercent int64 `json:"maxResourcePercent"` + MaxResourcePercentPerRequest *float64 `json:"maxResourcePercentPerRequest,omitempty"` + MinResourcePercent int64 `json:"minResourcePercent"` + MinResourcePercentPerRequest float64 `json:"minResourcePercentPerRequest"` + QueryExecutionTimeout *int64 `json:"queryExecutionTimeout,omitempty"` +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolsworkloadgroups/predicates.go b/resource-manager/synapse/2021-06-01/sqlpoolsworkloadgroups/predicates.go new file mode 100644 index 00000000000..c03726cb4ac --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolsworkloadgroups/predicates.go @@ -0,0 +1,27 @@ +package sqlpoolsworkloadgroups + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type WorkloadGroupOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p WorkloadGroupOperationPredicate) Matches(input WorkloadGroup) bool { + + if p.Id != nil && (input.Id == nil || *p.Id != *input.Id) { + return false + } + + if p.Name != nil && (input.Name == nil || *p.Name != *input.Name) { + return false + } + + if p.Type != nil && (input.Type == nil || *p.Type != *input.Type) { + return false + } + + return true +} diff --git a/resource-manager/synapse/2021-06-01/sqlpoolsworkloadgroups/version.go b/resource-manager/synapse/2021-06-01/sqlpoolsworkloadgroups/version.go new file mode 100644 index 00000000000..47f44c18bc3 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/sqlpoolsworkloadgroups/version.go @@ -0,0 +1,12 @@ +package sqlpoolsworkloadgroups + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2021-06-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/sqlpoolsworkloadgroups/%s", defaultApiVersion) +} diff --git a/resource-manager/synapse/2021-06-01/workspaceazureadonlyauthentications/README.md b/resource-manager/synapse/2021-06-01/workspaceazureadonlyauthentications/README.md new file mode 100644 index 00000000000..ec38d992523 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/workspaceazureadonlyauthentications/README.md @@ -0,0 +1,70 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/synapse/2021-06-01/workspaceazureadonlyauthentications` Documentation + +The `workspaceazureadonlyauthentications` SDK allows for interaction with the Azure Resource Manager Service `synapse` (API Version `2021-06-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/synapse/2021-06-01/workspaceazureadonlyauthentications" +``` + + +### Client Initialization + +```go +client := workspaceazureadonlyauthentications.NewWorkspaceAzureADOnlyAuthenticationsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `WorkspaceAzureADOnlyAuthenticationsClient.AzureADOnlyAuthenticationsCreate` + +```go +ctx := context.TODO() +id := workspaceazureadonlyauthentications.NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue") + +payload := workspaceazureadonlyauthentications.AzureADOnlyAuthentication{ + // ... +} + + +if err := client.AzureADOnlyAuthenticationsCreateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `WorkspaceAzureADOnlyAuthenticationsClient.AzureADOnlyAuthenticationsGet` + +```go +ctx := context.TODO() +id := workspaceazureadonlyauthentications.NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue") + +read, err := client.AzureADOnlyAuthenticationsGet(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `WorkspaceAzureADOnlyAuthenticationsClient.AzureADOnlyAuthenticationsList` + +```go +ctx := context.TODO() +id := workspaceazureadonlyauthentications.NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue") + +// alternatively `client.AzureADOnlyAuthenticationsList(ctx, id)` can be used to do batched pagination +items, err := client.AzureADOnlyAuthenticationsListComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/synapse/2021-06-01/workspaceazureadonlyauthentications/client.go b/resource-manager/synapse/2021-06-01/workspaceazureadonlyauthentications/client.go new file mode 100644 index 00000000000..2e07d07884d --- /dev/null +++ b/resource-manager/synapse/2021-06-01/workspaceazureadonlyauthentications/client.go @@ -0,0 +1,26 @@ +package workspaceazureadonlyauthentications + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type WorkspaceAzureADOnlyAuthenticationsClient struct { + Client *resourcemanager.Client +} + +func NewWorkspaceAzureADOnlyAuthenticationsClientWithBaseURI(sdkApi sdkEnv.Api) (*WorkspaceAzureADOnlyAuthenticationsClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "workspaceazureadonlyauthentications", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating WorkspaceAzureADOnlyAuthenticationsClient: %+v", err) + } + + return &WorkspaceAzureADOnlyAuthenticationsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/synapse/2021-06-01/workspaceazureadonlyauthentications/constants.go b/resource-manager/synapse/2021-06-01/workspaceazureadonlyauthentications/constants.go new file mode 100644 index 00000000000..9c26837e174 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/workspaceazureadonlyauthentications/constants.go @@ -0,0 +1,54 @@ +package workspaceazureadonlyauthentications + +import ( + "encoding/json" + "fmt" + "strings" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type StateValue string + +const ( + StateValueConsistent StateValue = "Consistent" + StateValueInConsistent StateValue = "InConsistent" + StateValueUpdating StateValue = "Updating" +) + +func PossibleValuesForStateValue() []string { + return []string{ + string(StateValueConsistent), + string(StateValueInConsistent), + string(StateValueUpdating), + } +} + +func (s *StateValue) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseStateValue(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseStateValue(input string) (*StateValue, error) { + vals := map[string]StateValue{ + "consistent": StateValueConsistent, + "inconsistent": StateValueInConsistent, + "updating": StateValueUpdating, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := StateValue(input) + return &out, nil +} diff --git a/resource-manager/synapse/2021-06-01/workspaceazureadonlyauthentications/id_workspace.go b/resource-manager/synapse/2021-06-01/workspaceazureadonlyauthentications/id_workspace.go new file mode 100644 index 00000000000..5e9e5386c15 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/workspaceazureadonlyauthentications/id_workspace.go @@ -0,0 +1,125 @@ +package workspaceazureadonlyauthentications + +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 = &WorkspaceId{} + +// WorkspaceId is a struct representing the Resource ID for a Workspace +type WorkspaceId struct { + SubscriptionId string + ResourceGroupName string + WorkspaceName string +} + +// NewWorkspaceID returns a new WorkspaceId struct +func NewWorkspaceID(subscriptionId string, resourceGroupName string, workspaceName string) WorkspaceId { + return WorkspaceId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + WorkspaceName: workspaceName, + } +} + +// ParseWorkspaceID parses 'input' into a WorkspaceId +func ParseWorkspaceID(input string) (*WorkspaceId, error) { + parser := resourceids.NewParserFromResourceIdType(&WorkspaceId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := WorkspaceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseWorkspaceIDInsensitively parses 'input' case-insensitively into a WorkspaceId +// note: this method should only be used for API response data and not user input +func ParseWorkspaceIDInsensitively(input string) (*WorkspaceId, error) { + parser := resourceids.NewParserFromResourceIdType(&WorkspaceId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := WorkspaceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *WorkspaceId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.WorkspaceName, ok = input.Parsed["workspaceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "workspaceName", input) + } + + return nil +} + +// ValidateWorkspaceID checks that 'input' can be parsed as a Workspace ID +func ValidateWorkspaceID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseWorkspaceID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Workspace ID +func (id WorkspaceId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Synapse/workspaces/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.WorkspaceName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Workspace ID +func (id WorkspaceId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftSynapse", "Microsoft.Synapse", "Microsoft.Synapse"), + resourceids.StaticSegment("staticWorkspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceName", "workspaceValue"), + } +} + +// String returns a human-readable description of this Workspace ID +func (id WorkspaceId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Workspace Name: %q", id.WorkspaceName), + } + return fmt.Sprintf("Workspace (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/synapse/2021-06-01/workspaceazureadonlyauthentications/id_workspace_test.go b/resource-manager/synapse/2021-06-01/workspaceazureadonlyauthentications/id_workspace_test.go new file mode 100644 index 00000000000..f9c044b04bb --- /dev/null +++ b/resource-manager/synapse/2021-06-01/workspaceazureadonlyauthentications/id_workspace_test.go @@ -0,0 +1,282 @@ +package workspaceazureadonlyauthentications + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &WorkspaceId{} + +func TestNewWorkspaceID(t *testing.T) { + id := NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.WorkspaceName != "workspaceValue" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceName'", id.WorkspaceName, "workspaceValue") + } +} + +func TestFormatWorkspaceID(t *testing.T) { + actual := NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseWorkspaceID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkspaceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue", + Expected: &WorkspaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkspaceID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + } +} + +func TestParseWorkspaceIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkspaceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue", + Expected: &WorkspaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE", + Expected: &WorkspaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + WorkspaceName: "wOrKsPaCeVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkspaceIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + } +} + +func TestSegmentsForWorkspaceId(t *testing.T) { + segments := WorkspaceId{}.Segments() + if len(segments) == 0 { + t.Fatalf("WorkspaceId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/synapse/2021-06-01/workspaceazureadonlyauthentications/method_azureadonlyauthenticationscreate.go b/resource-manager/synapse/2021-06-01/workspaceazureadonlyauthentications/method_azureadonlyauthenticationscreate.go new file mode 100644 index 00000000000..af52b804f11 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/workspaceazureadonlyauthentications/method_azureadonlyauthenticationscreate.go @@ -0,0 +1,76 @@ +package workspaceazureadonlyauthentications + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AzureADOnlyAuthenticationsCreateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *AzureADOnlyAuthentication +} + +// AzureADOnlyAuthenticationsCreate ... +func (c WorkspaceAzureADOnlyAuthenticationsClient) AzureADOnlyAuthenticationsCreate(ctx context.Context, id WorkspaceId, input AzureADOnlyAuthentication) (result AzureADOnlyAuthenticationsCreateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: fmt.Sprintf("%s/azureADOnlyAuthentications/default", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// AzureADOnlyAuthenticationsCreateThenPoll performs AzureADOnlyAuthenticationsCreate then polls until it's completed +func (c WorkspaceAzureADOnlyAuthenticationsClient) AzureADOnlyAuthenticationsCreateThenPoll(ctx context.Context, id WorkspaceId, input AzureADOnlyAuthentication) error { + result, err := c.AzureADOnlyAuthenticationsCreate(ctx, id, input) + if err != nil { + return fmt.Errorf("performing AzureADOnlyAuthenticationsCreate: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after AzureADOnlyAuthenticationsCreate: %+v", err) + } + + return nil +} diff --git a/resource-manager/synapse/2021-06-01/workspaceazureadonlyauthentications/method_azureadonlyauthenticationsget.go b/resource-manager/synapse/2021-06-01/workspaceazureadonlyauthentications/method_azureadonlyauthenticationsget.go new file mode 100644 index 00000000000..5a3e9182657 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/workspaceazureadonlyauthentications/method_azureadonlyauthenticationsget.go @@ -0,0 +1,52 @@ +package workspaceazureadonlyauthentications + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AzureADOnlyAuthenticationsGetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *AzureADOnlyAuthentication +} + +// AzureADOnlyAuthenticationsGet ... +func (c WorkspaceAzureADOnlyAuthenticationsClient) AzureADOnlyAuthenticationsGet(ctx context.Context, id WorkspaceId) (result AzureADOnlyAuthenticationsGetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/azureADOnlyAuthentications/default", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/synapse/2021-06-01/workspaceazureadonlyauthentications/method_azureadonlyauthenticationslist.go b/resource-manager/synapse/2021-06-01/workspaceazureadonlyauthentications/method_azureadonlyauthenticationslist.go new file mode 100644 index 00000000000..374ce797e8b --- /dev/null +++ b/resource-manager/synapse/2021-06-01/workspaceazureadonlyauthentications/method_azureadonlyauthenticationslist.go @@ -0,0 +1,91 @@ +package workspaceazureadonlyauthentications + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AzureADOnlyAuthenticationsListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]AzureADOnlyAuthentication +} + +type AzureADOnlyAuthenticationsListCompleteResult struct { + LatestHttpResponse *http.Response + Items []AzureADOnlyAuthentication +} + +// AzureADOnlyAuthenticationsList ... +func (c WorkspaceAzureADOnlyAuthenticationsClient) AzureADOnlyAuthenticationsList(ctx context.Context, id WorkspaceId) (result AzureADOnlyAuthenticationsListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/azureADOnlyAuthentications", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]AzureADOnlyAuthentication `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// AzureADOnlyAuthenticationsListComplete retrieves all the results into a single object +func (c WorkspaceAzureADOnlyAuthenticationsClient) AzureADOnlyAuthenticationsListComplete(ctx context.Context, id WorkspaceId) (AzureADOnlyAuthenticationsListCompleteResult, error) { + return c.AzureADOnlyAuthenticationsListCompleteMatchingPredicate(ctx, id, AzureADOnlyAuthenticationOperationPredicate{}) +} + +// AzureADOnlyAuthenticationsListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c WorkspaceAzureADOnlyAuthenticationsClient) AzureADOnlyAuthenticationsListCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, predicate AzureADOnlyAuthenticationOperationPredicate) (result AzureADOnlyAuthenticationsListCompleteResult, err error) { + items := make([]AzureADOnlyAuthentication, 0) + + resp, err := c.AzureADOnlyAuthenticationsList(ctx, id) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = AzureADOnlyAuthenticationsListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/synapse/2021-06-01/workspaceazureadonlyauthentications/model_azureadonlyauthentication.go b/resource-manager/synapse/2021-06-01/workspaceazureadonlyauthentications/model_azureadonlyauthentication.go new file mode 100644 index 00000000000..d6e219acc15 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/workspaceazureadonlyauthentications/model_azureadonlyauthentication.go @@ -0,0 +1,11 @@ +package workspaceazureadonlyauthentications + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AzureADOnlyAuthentication struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *AzureADOnlyAuthenticationProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/synapse/2021-06-01/workspaceazureadonlyauthentications/model_azureadonlyauthenticationproperties.go b/resource-manager/synapse/2021-06-01/workspaceazureadonlyauthentications/model_azureadonlyauthenticationproperties.go new file mode 100644 index 00000000000..e1699084448 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/workspaceazureadonlyauthentications/model_azureadonlyauthenticationproperties.go @@ -0,0 +1,28 @@ +package workspaceazureadonlyauthentications + +import ( + "time" + + "github.com/hashicorp/go-azure-helpers/lang/dates" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AzureADOnlyAuthenticationProperties struct { + AzureADOnlyAuthentication bool `json:"azureADOnlyAuthentication"` + CreationDate *string `json:"creationDate,omitempty"` + State *StateValue `json:"state,omitempty"` +} + +func (o *AzureADOnlyAuthenticationProperties) GetCreationDateAsTime() (*time.Time, error) { + if o.CreationDate == nil { + return nil, nil + } + return dates.ParseAsFormat(o.CreationDate, "2006-01-02T15:04:05Z07:00") +} + +func (o *AzureADOnlyAuthenticationProperties) SetCreationDateAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.CreationDate = &formatted +} diff --git a/resource-manager/synapse/2021-06-01/workspaceazureadonlyauthentications/predicates.go b/resource-manager/synapse/2021-06-01/workspaceazureadonlyauthentications/predicates.go new file mode 100644 index 00000000000..c94523046f4 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/workspaceazureadonlyauthentications/predicates.go @@ -0,0 +1,27 @@ +package workspaceazureadonlyauthentications + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AzureADOnlyAuthenticationOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p AzureADOnlyAuthenticationOperationPredicate) Matches(input AzureADOnlyAuthentication) bool { + + if p.Id != nil && (input.Id == nil || *p.Id != *input.Id) { + return false + } + + if p.Name != nil && (input.Name == nil || *p.Name != *input.Name) { + return false + } + + if p.Type != nil && (input.Type == nil || *p.Type != *input.Type) { + return false + } + + return true +} diff --git a/resource-manager/synapse/2021-06-01/workspaceazureadonlyauthentications/version.go b/resource-manager/synapse/2021-06-01/workspaceazureadonlyauthentications/version.go new file mode 100644 index 00000000000..7a551f6b06f --- /dev/null +++ b/resource-manager/synapse/2021-06-01/workspaceazureadonlyauthentications/version.go @@ -0,0 +1,12 @@ +package workspaceazureadonlyauthentications + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2021-06-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/workspaceazureadonlyauthentications/%s", defaultApiVersion) +} diff --git a/resource-manager/synapse/2021-06-01/workspacemanagedsqlserver/README.md b/resource-manager/synapse/2021-06-01/workspacemanagedsqlserver/README.md new file mode 100644 index 00000000000..70f30e0d1c3 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/workspacemanagedsqlserver/README.md @@ -0,0 +1,53 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/synapse/2021-06-01/workspacemanagedsqlserver` Documentation + +The `workspacemanagedsqlserver` SDK allows for interaction with the Azure Resource Manager Service `synapse` (API Version `2021-06-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/synapse/2021-06-01/workspacemanagedsqlserver" +``` + + +### Client Initialization + +```go +client := workspacemanagedsqlserver.NewWorkspaceManagedSqlServerClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `WorkspaceManagedSqlServerClient.RecoverableSqlPoolsGet` + +```go +ctx := context.TODO() +id := workspacemanagedsqlserver.NewRecoverableSqlPoolID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "recoverableSqlPoolValue") + +read, err := client.RecoverableSqlPoolsGet(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `WorkspaceManagedSqlServerClient.RecoverableSqlPoolsList` + +```go +ctx := context.TODO() +id := workspacemanagedsqlserver.NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue") + +// alternatively `client.RecoverableSqlPoolsList(ctx, id)` can be used to do batched pagination +items, err := client.RecoverableSqlPoolsListComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/synapse/2021-06-01/workspacemanagedsqlserver/client.go b/resource-manager/synapse/2021-06-01/workspacemanagedsqlserver/client.go new file mode 100644 index 00000000000..8af9e101a72 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/workspacemanagedsqlserver/client.go @@ -0,0 +1,26 @@ +package workspacemanagedsqlserver + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type WorkspaceManagedSqlServerClient struct { + Client *resourcemanager.Client +} + +func NewWorkspaceManagedSqlServerClientWithBaseURI(sdkApi sdkEnv.Api) (*WorkspaceManagedSqlServerClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "workspacemanagedsqlserver", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating WorkspaceManagedSqlServerClient: %+v", err) + } + + return &WorkspaceManagedSqlServerClient{ + Client: client, + }, nil +} diff --git a/resource-manager/synapse/2021-06-01/workspacemanagedsqlserver/id_recoverablesqlpool.go b/resource-manager/synapse/2021-06-01/workspacemanagedsqlserver/id_recoverablesqlpool.go new file mode 100644 index 00000000000..474592d4583 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/workspacemanagedsqlserver/id_recoverablesqlpool.go @@ -0,0 +1,134 @@ +package workspacemanagedsqlserver + +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 = &RecoverableSqlPoolId{} + +// RecoverableSqlPoolId is a struct representing the Resource ID for a Recoverable Sql Pool +type RecoverableSqlPoolId struct { + SubscriptionId string + ResourceGroupName string + WorkspaceName string + RecoverableSqlPoolName string +} + +// NewRecoverableSqlPoolID returns a new RecoverableSqlPoolId struct +func NewRecoverableSqlPoolID(subscriptionId string, resourceGroupName string, workspaceName string, recoverableSqlPoolName string) RecoverableSqlPoolId { + return RecoverableSqlPoolId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + WorkspaceName: workspaceName, + RecoverableSqlPoolName: recoverableSqlPoolName, + } +} + +// ParseRecoverableSqlPoolID parses 'input' into a RecoverableSqlPoolId +func ParseRecoverableSqlPoolID(input string) (*RecoverableSqlPoolId, error) { + parser := resourceids.NewParserFromResourceIdType(&RecoverableSqlPoolId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := RecoverableSqlPoolId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseRecoverableSqlPoolIDInsensitively parses 'input' case-insensitively into a RecoverableSqlPoolId +// note: this method should only be used for API response data and not user input +func ParseRecoverableSqlPoolIDInsensitively(input string) (*RecoverableSqlPoolId, error) { + parser := resourceids.NewParserFromResourceIdType(&RecoverableSqlPoolId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := RecoverableSqlPoolId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *RecoverableSqlPoolId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.WorkspaceName, ok = input.Parsed["workspaceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "workspaceName", input) + } + + if id.RecoverableSqlPoolName, ok = input.Parsed["recoverableSqlPoolName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "recoverableSqlPoolName", input) + } + + return nil +} + +// ValidateRecoverableSqlPoolID checks that 'input' can be parsed as a Recoverable Sql Pool ID +func ValidateRecoverableSqlPoolID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseRecoverableSqlPoolID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Recoverable Sql Pool ID +func (id RecoverableSqlPoolId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Synapse/workspaces/%s/recoverableSqlPools/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.WorkspaceName, id.RecoverableSqlPoolName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Recoverable Sql Pool ID +func (id RecoverableSqlPoolId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftSynapse", "Microsoft.Synapse", "Microsoft.Synapse"), + resourceids.StaticSegment("staticWorkspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceName", "workspaceValue"), + resourceids.StaticSegment("staticRecoverableSqlPools", "recoverableSqlPools", "recoverableSqlPools"), + resourceids.UserSpecifiedSegment("recoverableSqlPoolName", "recoverableSqlPoolValue"), + } +} + +// String returns a human-readable description of this Recoverable Sql Pool ID +func (id RecoverableSqlPoolId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Workspace Name: %q", id.WorkspaceName), + fmt.Sprintf("Recoverable Sql Pool Name: %q", id.RecoverableSqlPoolName), + } + return fmt.Sprintf("Recoverable Sql Pool (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/synapse/2021-06-01/workspacemanagedsqlserver/id_recoverablesqlpool_test.go b/resource-manager/synapse/2021-06-01/workspacemanagedsqlserver/id_recoverablesqlpool_test.go new file mode 100644 index 00000000000..ab191a37540 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/workspacemanagedsqlserver/id_recoverablesqlpool_test.go @@ -0,0 +1,327 @@ +package workspacemanagedsqlserver + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &RecoverableSqlPoolId{} + +func TestNewRecoverableSqlPoolID(t *testing.T) { + id := NewRecoverableSqlPoolID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "recoverableSqlPoolValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.WorkspaceName != "workspaceValue" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceName'", id.WorkspaceName, "workspaceValue") + } + + if id.RecoverableSqlPoolName != "recoverableSqlPoolValue" { + t.Fatalf("Expected %q but got %q for Segment 'RecoverableSqlPoolName'", id.RecoverableSqlPoolName, "recoverableSqlPoolValue") + } +} + +func TestFormatRecoverableSqlPoolID(t *testing.T) { + actual := NewRecoverableSqlPoolID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "recoverableSqlPoolValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/recoverableSqlPools/recoverableSqlPoolValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseRecoverableSqlPoolID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *RecoverableSqlPoolId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/recoverableSqlPools", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/recoverableSqlPools/recoverableSqlPoolValue", + Expected: &RecoverableSqlPoolId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + RecoverableSqlPoolName: "recoverableSqlPoolValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/recoverableSqlPools/recoverableSqlPoolValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseRecoverableSqlPoolID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + if actual.RecoverableSqlPoolName != v.Expected.RecoverableSqlPoolName { + t.Fatalf("Expected %q but got %q for RecoverableSqlPoolName", v.Expected.RecoverableSqlPoolName, actual.RecoverableSqlPoolName) + } + + } +} + +func TestParseRecoverableSqlPoolIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *RecoverableSqlPoolId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/recoverableSqlPools", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/rEcOvErAbLeSqLpOoLs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/recoverableSqlPools/recoverableSqlPoolValue", + Expected: &RecoverableSqlPoolId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + RecoverableSqlPoolName: "recoverableSqlPoolValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/recoverableSqlPools/recoverableSqlPoolValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/rEcOvErAbLeSqLpOoLs/rEcOvErAbLeSqLpOoLvAlUe", + Expected: &RecoverableSqlPoolId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + WorkspaceName: "wOrKsPaCeVaLuE", + RecoverableSqlPoolName: "rEcOvErAbLeSqLpOoLvAlUe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/rEcOvErAbLeSqLpOoLs/rEcOvErAbLeSqLpOoLvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseRecoverableSqlPoolIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + if actual.RecoverableSqlPoolName != v.Expected.RecoverableSqlPoolName { + t.Fatalf("Expected %q but got %q for RecoverableSqlPoolName", v.Expected.RecoverableSqlPoolName, actual.RecoverableSqlPoolName) + } + + } +} + +func TestSegmentsForRecoverableSqlPoolId(t *testing.T) { + segments := RecoverableSqlPoolId{}.Segments() + if len(segments) == 0 { + t.Fatalf("RecoverableSqlPoolId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/synapse/2021-06-01/workspacemanagedsqlserver/id_workspace.go b/resource-manager/synapse/2021-06-01/workspacemanagedsqlserver/id_workspace.go new file mode 100644 index 00000000000..ba6e321cb0f --- /dev/null +++ b/resource-manager/synapse/2021-06-01/workspacemanagedsqlserver/id_workspace.go @@ -0,0 +1,125 @@ +package workspacemanagedsqlserver + +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 = &WorkspaceId{} + +// WorkspaceId is a struct representing the Resource ID for a Workspace +type WorkspaceId struct { + SubscriptionId string + ResourceGroupName string + WorkspaceName string +} + +// NewWorkspaceID returns a new WorkspaceId struct +func NewWorkspaceID(subscriptionId string, resourceGroupName string, workspaceName string) WorkspaceId { + return WorkspaceId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + WorkspaceName: workspaceName, + } +} + +// ParseWorkspaceID parses 'input' into a WorkspaceId +func ParseWorkspaceID(input string) (*WorkspaceId, error) { + parser := resourceids.NewParserFromResourceIdType(&WorkspaceId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := WorkspaceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseWorkspaceIDInsensitively parses 'input' case-insensitively into a WorkspaceId +// note: this method should only be used for API response data and not user input +func ParseWorkspaceIDInsensitively(input string) (*WorkspaceId, error) { + parser := resourceids.NewParserFromResourceIdType(&WorkspaceId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := WorkspaceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *WorkspaceId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.WorkspaceName, ok = input.Parsed["workspaceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "workspaceName", input) + } + + return nil +} + +// ValidateWorkspaceID checks that 'input' can be parsed as a Workspace ID +func ValidateWorkspaceID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseWorkspaceID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Workspace ID +func (id WorkspaceId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Synapse/workspaces/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.WorkspaceName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Workspace ID +func (id WorkspaceId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftSynapse", "Microsoft.Synapse", "Microsoft.Synapse"), + resourceids.StaticSegment("staticWorkspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceName", "workspaceValue"), + } +} + +// String returns a human-readable description of this Workspace ID +func (id WorkspaceId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Workspace Name: %q", id.WorkspaceName), + } + return fmt.Sprintf("Workspace (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/synapse/2021-06-01/workspacemanagedsqlserver/id_workspace_test.go b/resource-manager/synapse/2021-06-01/workspacemanagedsqlserver/id_workspace_test.go new file mode 100644 index 00000000000..181f08c5c57 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/workspacemanagedsqlserver/id_workspace_test.go @@ -0,0 +1,282 @@ +package workspacemanagedsqlserver + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &WorkspaceId{} + +func TestNewWorkspaceID(t *testing.T) { + id := NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.WorkspaceName != "workspaceValue" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceName'", id.WorkspaceName, "workspaceValue") + } +} + +func TestFormatWorkspaceID(t *testing.T) { + actual := NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseWorkspaceID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkspaceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue", + Expected: &WorkspaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkspaceID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + } +} + +func TestParseWorkspaceIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkspaceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue", + Expected: &WorkspaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE", + Expected: &WorkspaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + WorkspaceName: "wOrKsPaCeVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkspaceIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + } +} + +func TestSegmentsForWorkspaceId(t *testing.T) { + segments := WorkspaceId{}.Segments() + if len(segments) == 0 { + t.Fatalf("WorkspaceId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/synapse/2021-06-01/workspacemanagedsqlserver/method_recoverablesqlpoolsget.go b/resource-manager/synapse/2021-06-01/workspacemanagedsqlserver/method_recoverablesqlpoolsget.go new file mode 100644 index 00000000000..054d49f8afa --- /dev/null +++ b/resource-manager/synapse/2021-06-01/workspacemanagedsqlserver/method_recoverablesqlpoolsget.go @@ -0,0 +1,51 @@ +package workspacemanagedsqlserver + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RecoverableSqlPoolsGetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *RecoverableSqlPool +} + +// RecoverableSqlPoolsGet ... +func (c WorkspaceManagedSqlServerClient) RecoverableSqlPoolsGet(ctx context.Context, id RecoverableSqlPoolId) (result RecoverableSqlPoolsGetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/synapse/2021-06-01/workspacemanagedsqlserver/method_recoverablesqlpoolslist.go b/resource-manager/synapse/2021-06-01/workspacemanagedsqlserver/method_recoverablesqlpoolslist.go new file mode 100644 index 00000000000..5914bd6a565 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/workspacemanagedsqlserver/method_recoverablesqlpoolslist.go @@ -0,0 +1,91 @@ +package workspacemanagedsqlserver + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RecoverableSqlPoolsListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]RecoverableSqlPool +} + +type RecoverableSqlPoolsListCompleteResult struct { + LatestHttpResponse *http.Response + Items []RecoverableSqlPool +} + +// RecoverableSqlPoolsList ... +func (c WorkspaceManagedSqlServerClient) RecoverableSqlPoolsList(ctx context.Context, id WorkspaceId) (result RecoverableSqlPoolsListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/recoverableSqlPools", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]RecoverableSqlPool `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// RecoverableSqlPoolsListComplete retrieves all the results into a single object +func (c WorkspaceManagedSqlServerClient) RecoverableSqlPoolsListComplete(ctx context.Context, id WorkspaceId) (RecoverableSqlPoolsListCompleteResult, error) { + return c.RecoverableSqlPoolsListCompleteMatchingPredicate(ctx, id, RecoverableSqlPoolOperationPredicate{}) +} + +// RecoverableSqlPoolsListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c WorkspaceManagedSqlServerClient) RecoverableSqlPoolsListCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, predicate RecoverableSqlPoolOperationPredicate) (result RecoverableSqlPoolsListCompleteResult, err error) { + items := make([]RecoverableSqlPool, 0) + + resp, err := c.RecoverableSqlPoolsList(ctx, id) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = RecoverableSqlPoolsListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/synapse/2021-06-01/workspacemanagedsqlserver/model_recoverablesqlpool.go b/resource-manager/synapse/2021-06-01/workspacemanagedsqlserver/model_recoverablesqlpool.go new file mode 100644 index 00000000000..158e09842a7 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/workspacemanagedsqlserver/model_recoverablesqlpool.go @@ -0,0 +1,11 @@ +package workspacemanagedsqlserver + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RecoverableSqlPool struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *RecoverableSqlPoolProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/synapse/2021-06-01/workspacemanagedsqlserver/model_recoverablesqlpoolproperties.go b/resource-manager/synapse/2021-06-01/workspacemanagedsqlserver/model_recoverablesqlpoolproperties.go new file mode 100644 index 00000000000..a211b790b02 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/workspacemanagedsqlserver/model_recoverablesqlpoolproperties.go @@ -0,0 +1,29 @@ +package workspacemanagedsqlserver + +import ( + "time" + + "github.com/hashicorp/go-azure-helpers/lang/dates" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RecoverableSqlPoolProperties struct { + Edition *string `json:"edition,omitempty"` + ElasticPoolName *string `json:"elasticPoolName,omitempty"` + LastAvailableBackupDate *string `json:"lastAvailableBackupDate,omitempty"` + ServiceLevelObjective *string `json:"serviceLevelObjective,omitempty"` +} + +func (o *RecoverableSqlPoolProperties) GetLastAvailableBackupDateAsTime() (*time.Time, error) { + if o.LastAvailableBackupDate == nil { + return nil, nil + } + return dates.ParseAsFormat(o.LastAvailableBackupDate, "2006-01-02T15:04:05Z07:00") +} + +func (o *RecoverableSqlPoolProperties) SetLastAvailableBackupDateAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.LastAvailableBackupDate = &formatted +} diff --git a/resource-manager/synapse/2021-06-01/workspacemanagedsqlserver/predicates.go b/resource-manager/synapse/2021-06-01/workspacemanagedsqlserver/predicates.go new file mode 100644 index 00000000000..9838a0bd62b --- /dev/null +++ b/resource-manager/synapse/2021-06-01/workspacemanagedsqlserver/predicates.go @@ -0,0 +1,27 @@ +package workspacemanagedsqlserver + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RecoverableSqlPoolOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p RecoverableSqlPoolOperationPredicate) Matches(input RecoverableSqlPool) bool { + + if p.Id != nil && (input.Id == nil || *p.Id != *input.Id) { + return false + } + + if p.Name != nil && (input.Name == nil || *p.Name != *input.Name) { + return false + } + + if p.Type != nil && (input.Type == nil || *p.Type != *input.Type) { + return false + } + + return true +} diff --git a/resource-manager/synapse/2021-06-01/workspacemanagedsqlserver/version.go b/resource-manager/synapse/2021-06-01/workspacemanagedsqlserver/version.go new file mode 100644 index 00000000000..3f3d5f36fdb --- /dev/null +++ b/resource-manager/synapse/2021-06-01/workspacemanagedsqlserver/version.go @@ -0,0 +1,12 @@ +package workspacemanagedsqlserver + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2021-06-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/workspacemanagedsqlserver/%s", defaultApiVersion) +} diff --git a/resource-manager/synapse/2021-06-01/workspacemanagedsqlserverblobauditing/README.md b/resource-manager/synapse/2021-06-01/workspacemanagedsqlserverblobauditing/README.md new file mode 100644 index 00000000000..8286bac255b --- /dev/null +++ b/resource-manager/synapse/2021-06-01/workspacemanagedsqlserverblobauditing/README.md @@ -0,0 +1,120 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/synapse/2021-06-01/workspacemanagedsqlserverblobauditing` Documentation + +The `workspacemanagedsqlserverblobauditing` SDK allows for interaction with the Azure Resource Manager Service `synapse` (API Version `2021-06-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/synapse/2021-06-01/workspacemanagedsqlserverblobauditing" +``` + + +### Client Initialization + +```go +client := workspacemanagedsqlserverblobauditing.NewWorkspaceManagedSqlServerBlobAuditingClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `WorkspaceManagedSqlServerBlobAuditingClient.WorkspaceManagedSqlServerBlobAuditingPoliciesCreateOrUpdate` + +```go +ctx := context.TODO() +id := workspacemanagedsqlserverblobauditing.NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue") + +payload := workspacemanagedsqlserverblobauditing.ServerBlobAuditingPolicy{ + // ... +} + + +if err := client.WorkspaceManagedSqlServerBlobAuditingPoliciesCreateOrUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `WorkspaceManagedSqlServerBlobAuditingClient.WorkspaceManagedSqlServerBlobAuditingPoliciesGet` + +```go +ctx := context.TODO() +id := workspacemanagedsqlserverblobauditing.NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue") + +read, err := client.WorkspaceManagedSqlServerBlobAuditingPoliciesGet(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `WorkspaceManagedSqlServerBlobAuditingClient.WorkspaceManagedSqlServerBlobAuditingPoliciesListByWorkspace` + +```go +ctx := context.TODO() +id := workspacemanagedsqlserverblobauditing.NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue") + +// alternatively `client.WorkspaceManagedSqlServerBlobAuditingPoliciesListByWorkspace(ctx, id)` can be used to do batched pagination +items, err := client.WorkspaceManagedSqlServerBlobAuditingPoliciesListByWorkspaceComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `WorkspaceManagedSqlServerBlobAuditingClient.WorkspaceManagedSqlServerExtendedBlobAuditingPoliciesCreateOrUpdate` + +```go +ctx := context.TODO() +id := workspacemanagedsqlserverblobauditing.NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue") + +payload := workspacemanagedsqlserverblobauditing.ExtendedServerBlobAuditingPolicy{ + // ... +} + + +if err := client.WorkspaceManagedSqlServerExtendedBlobAuditingPoliciesCreateOrUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `WorkspaceManagedSqlServerBlobAuditingClient.WorkspaceManagedSqlServerExtendedBlobAuditingPoliciesGet` + +```go +ctx := context.TODO() +id := workspacemanagedsqlserverblobauditing.NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue") + +read, err := client.WorkspaceManagedSqlServerExtendedBlobAuditingPoliciesGet(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `WorkspaceManagedSqlServerBlobAuditingClient.WorkspaceManagedSqlServerExtendedBlobAuditingPoliciesListByWorkspace` + +```go +ctx := context.TODO() +id := workspacemanagedsqlserverblobauditing.NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue") + +// alternatively `client.WorkspaceManagedSqlServerExtendedBlobAuditingPoliciesListByWorkspace(ctx, id)` can be used to do batched pagination +items, err := client.WorkspaceManagedSqlServerExtendedBlobAuditingPoliciesListByWorkspaceComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/synapse/2021-06-01/workspacemanagedsqlserverblobauditing/client.go b/resource-manager/synapse/2021-06-01/workspacemanagedsqlserverblobauditing/client.go new file mode 100644 index 00000000000..c6b3ddff3d1 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/workspacemanagedsqlserverblobauditing/client.go @@ -0,0 +1,26 @@ +package workspacemanagedsqlserverblobauditing + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type WorkspaceManagedSqlServerBlobAuditingClient struct { + Client *resourcemanager.Client +} + +func NewWorkspaceManagedSqlServerBlobAuditingClientWithBaseURI(sdkApi sdkEnv.Api) (*WorkspaceManagedSqlServerBlobAuditingClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "workspacemanagedsqlserverblobauditing", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating WorkspaceManagedSqlServerBlobAuditingClient: %+v", err) + } + + return &WorkspaceManagedSqlServerBlobAuditingClient{ + Client: client, + }, nil +} diff --git a/resource-manager/synapse/2021-06-01/workspacemanagedsqlserverblobauditing/constants.go b/resource-manager/synapse/2021-06-01/workspacemanagedsqlserverblobauditing/constants.go new file mode 100644 index 00000000000..b6c690ea714 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/workspacemanagedsqlserverblobauditing/constants.go @@ -0,0 +1,51 @@ +package workspacemanagedsqlserverblobauditing + +import ( + "encoding/json" + "fmt" + "strings" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type BlobAuditingPolicyState string + +const ( + BlobAuditingPolicyStateDisabled BlobAuditingPolicyState = "Disabled" + BlobAuditingPolicyStateEnabled BlobAuditingPolicyState = "Enabled" +) + +func PossibleValuesForBlobAuditingPolicyState() []string { + return []string{ + string(BlobAuditingPolicyStateDisabled), + string(BlobAuditingPolicyStateEnabled), + } +} + +func (s *BlobAuditingPolicyState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseBlobAuditingPolicyState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseBlobAuditingPolicyState(input string) (*BlobAuditingPolicyState, error) { + vals := map[string]BlobAuditingPolicyState{ + "disabled": BlobAuditingPolicyStateDisabled, + "enabled": BlobAuditingPolicyStateEnabled, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := BlobAuditingPolicyState(input) + return &out, nil +} diff --git a/resource-manager/synapse/2021-06-01/workspacemanagedsqlserverblobauditing/id_workspace.go b/resource-manager/synapse/2021-06-01/workspacemanagedsqlserverblobauditing/id_workspace.go new file mode 100644 index 00000000000..89000c4a7b7 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/workspacemanagedsqlserverblobauditing/id_workspace.go @@ -0,0 +1,125 @@ +package workspacemanagedsqlserverblobauditing + +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 = &WorkspaceId{} + +// WorkspaceId is a struct representing the Resource ID for a Workspace +type WorkspaceId struct { + SubscriptionId string + ResourceGroupName string + WorkspaceName string +} + +// NewWorkspaceID returns a new WorkspaceId struct +func NewWorkspaceID(subscriptionId string, resourceGroupName string, workspaceName string) WorkspaceId { + return WorkspaceId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + WorkspaceName: workspaceName, + } +} + +// ParseWorkspaceID parses 'input' into a WorkspaceId +func ParseWorkspaceID(input string) (*WorkspaceId, error) { + parser := resourceids.NewParserFromResourceIdType(&WorkspaceId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := WorkspaceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseWorkspaceIDInsensitively parses 'input' case-insensitively into a WorkspaceId +// note: this method should only be used for API response data and not user input +func ParseWorkspaceIDInsensitively(input string) (*WorkspaceId, error) { + parser := resourceids.NewParserFromResourceIdType(&WorkspaceId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := WorkspaceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *WorkspaceId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.WorkspaceName, ok = input.Parsed["workspaceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "workspaceName", input) + } + + return nil +} + +// ValidateWorkspaceID checks that 'input' can be parsed as a Workspace ID +func ValidateWorkspaceID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseWorkspaceID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Workspace ID +func (id WorkspaceId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Synapse/workspaces/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.WorkspaceName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Workspace ID +func (id WorkspaceId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftSynapse", "Microsoft.Synapse", "Microsoft.Synapse"), + resourceids.StaticSegment("staticWorkspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceName", "workspaceValue"), + } +} + +// String returns a human-readable description of this Workspace ID +func (id WorkspaceId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Workspace Name: %q", id.WorkspaceName), + } + return fmt.Sprintf("Workspace (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/synapse/2021-06-01/workspacemanagedsqlserverblobauditing/id_workspace_test.go b/resource-manager/synapse/2021-06-01/workspacemanagedsqlserverblobauditing/id_workspace_test.go new file mode 100644 index 00000000000..80d2f37a3b2 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/workspacemanagedsqlserverblobauditing/id_workspace_test.go @@ -0,0 +1,282 @@ +package workspacemanagedsqlserverblobauditing + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &WorkspaceId{} + +func TestNewWorkspaceID(t *testing.T) { + id := NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.WorkspaceName != "workspaceValue" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceName'", id.WorkspaceName, "workspaceValue") + } +} + +func TestFormatWorkspaceID(t *testing.T) { + actual := NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseWorkspaceID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkspaceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue", + Expected: &WorkspaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkspaceID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + } +} + +func TestParseWorkspaceIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkspaceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue", + Expected: &WorkspaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE", + Expected: &WorkspaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + WorkspaceName: "wOrKsPaCeVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkspaceIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + } +} + +func TestSegmentsForWorkspaceId(t *testing.T) { + segments := WorkspaceId{}.Segments() + if len(segments) == 0 { + t.Fatalf("WorkspaceId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/synapse/2021-06-01/workspacemanagedsqlserverblobauditing/method_workspacemanagedsqlserverblobauditingpoliciescreateorupdate.go b/resource-manager/synapse/2021-06-01/workspacemanagedsqlserverblobauditing/method_workspacemanagedsqlserverblobauditingpoliciescreateorupdate.go new file mode 100644 index 00000000000..81f2ac8bab0 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/workspacemanagedsqlserverblobauditing/method_workspacemanagedsqlserverblobauditingpoliciescreateorupdate.go @@ -0,0 +1,75 @@ +package workspacemanagedsqlserverblobauditing + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type WorkspaceManagedSqlServerBlobAuditingPoliciesCreateOrUpdateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *ServerBlobAuditingPolicy +} + +// WorkspaceManagedSqlServerBlobAuditingPoliciesCreateOrUpdate ... +func (c WorkspaceManagedSqlServerBlobAuditingClient) WorkspaceManagedSqlServerBlobAuditingPoliciesCreateOrUpdate(ctx context.Context, id WorkspaceId, input ServerBlobAuditingPolicy) (result WorkspaceManagedSqlServerBlobAuditingPoliciesCreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: fmt.Sprintf("%s/auditingSettings/default", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// WorkspaceManagedSqlServerBlobAuditingPoliciesCreateOrUpdateThenPoll performs WorkspaceManagedSqlServerBlobAuditingPoliciesCreateOrUpdate then polls until it's completed +func (c WorkspaceManagedSqlServerBlobAuditingClient) WorkspaceManagedSqlServerBlobAuditingPoliciesCreateOrUpdateThenPoll(ctx context.Context, id WorkspaceId, input ServerBlobAuditingPolicy) error { + result, err := c.WorkspaceManagedSqlServerBlobAuditingPoliciesCreateOrUpdate(ctx, id, input) + if err != nil { + return fmt.Errorf("performing WorkspaceManagedSqlServerBlobAuditingPoliciesCreateOrUpdate: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after WorkspaceManagedSqlServerBlobAuditingPoliciesCreateOrUpdate: %+v", err) + } + + return nil +} diff --git a/resource-manager/synapse/2021-06-01/workspacemanagedsqlserverblobauditing/method_workspacemanagedsqlserverblobauditingpoliciesget.go b/resource-manager/synapse/2021-06-01/workspacemanagedsqlserverblobauditing/method_workspacemanagedsqlserverblobauditingpoliciesget.go new file mode 100644 index 00000000000..0067ef35930 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/workspacemanagedsqlserverblobauditing/method_workspacemanagedsqlserverblobauditingpoliciesget.go @@ -0,0 +1,52 @@ +package workspacemanagedsqlserverblobauditing + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type WorkspaceManagedSqlServerBlobAuditingPoliciesGetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *ServerBlobAuditingPolicy +} + +// WorkspaceManagedSqlServerBlobAuditingPoliciesGet ... +func (c WorkspaceManagedSqlServerBlobAuditingClient) WorkspaceManagedSqlServerBlobAuditingPoliciesGet(ctx context.Context, id WorkspaceId) (result WorkspaceManagedSqlServerBlobAuditingPoliciesGetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/auditingSettings/default", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/synapse/2021-06-01/workspacemanagedsqlserverblobauditing/method_workspacemanagedsqlserverblobauditingpolicieslistbyworkspace.go b/resource-manager/synapse/2021-06-01/workspacemanagedsqlserverblobauditing/method_workspacemanagedsqlserverblobauditingpolicieslistbyworkspace.go new file mode 100644 index 00000000000..24f9f78d8a7 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/workspacemanagedsqlserverblobauditing/method_workspacemanagedsqlserverblobauditingpolicieslistbyworkspace.go @@ -0,0 +1,91 @@ +package workspacemanagedsqlserverblobauditing + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type WorkspaceManagedSqlServerBlobAuditingPoliciesListByWorkspaceOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]ServerBlobAuditingPolicy +} + +type WorkspaceManagedSqlServerBlobAuditingPoliciesListByWorkspaceCompleteResult struct { + LatestHttpResponse *http.Response + Items []ServerBlobAuditingPolicy +} + +// WorkspaceManagedSqlServerBlobAuditingPoliciesListByWorkspace ... +func (c WorkspaceManagedSqlServerBlobAuditingClient) WorkspaceManagedSqlServerBlobAuditingPoliciesListByWorkspace(ctx context.Context, id WorkspaceId) (result WorkspaceManagedSqlServerBlobAuditingPoliciesListByWorkspaceOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/auditingSettings", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]ServerBlobAuditingPolicy `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// WorkspaceManagedSqlServerBlobAuditingPoliciesListByWorkspaceComplete retrieves all the results into a single object +func (c WorkspaceManagedSqlServerBlobAuditingClient) WorkspaceManagedSqlServerBlobAuditingPoliciesListByWorkspaceComplete(ctx context.Context, id WorkspaceId) (WorkspaceManagedSqlServerBlobAuditingPoliciesListByWorkspaceCompleteResult, error) { + return c.WorkspaceManagedSqlServerBlobAuditingPoliciesListByWorkspaceCompleteMatchingPredicate(ctx, id, ServerBlobAuditingPolicyOperationPredicate{}) +} + +// WorkspaceManagedSqlServerBlobAuditingPoliciesListByWorkspaceCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c WorkspaceManagedSqlServerBlobAuditingClient) WorkspaceManagedSqlServerBlobAuditingPoliciesListByWorkspaceCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, predicate ServerBlobAuditingPolicyOperationPredicate) (result WorkspaceManagedSqlServerBlobAuditingPoliciesListByWorkspaceCompleteResult, err error) { + items := make([]ServerBlobAuditingPolicy, 0) + + resp, err := c.WorkspaceManagedSqlServerBlobAuditingPoliciesListByWorkspace(ctx, id) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = WorkspaceManagedSqlServerBlobAuditingPoliciesListByWorkspaceCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/synapse/2021-06-01/workspacemanagedsqlserverblobauditing/method_workspacemanagedsqlserverextendedblobauditingpoliciescreateorupdate.go b/resource-manager/synapse/2021-06-01/workspacemanagedsqlserverblobauditing/method_workspacemanagedsqlserverextendedblobauditingpoliciescreateorupdate.go new file mode 100644 index 00000000000..21cb83b8923 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/workspacemanagedsqlserverblobauditing/method_workspacemanagedsqlserverextendedblobauditingpoliciescreateorupdate.go @@ -0,0 +1,75 @@ +package workspacemanagedsqlserverblobauditing + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type WorkspaceManagedSqlServerExtendedBlobAuditingPoliciesCreateOrUpdateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *ExtendedServerBlobAuditingPolicy +} + +// WorkspaceManagedSqlServerExtendedBlobAuditingPoliciesCreateOrUpdate ... +func (c WorkspaceManagedSqlServerBlobAuditingClient) WorkspaceManagedSqlServerExtendedBlobAuditingPoliciesCreateOrUpdate(ctx context.Context, id WorkspaceId, input ExtendedServerBlobAuditingPolicy) (result WorkspaceManagedSqlServerExtendedBlobAuditingPoliciesCreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: fmt.Sprintf("%s/extendedAuditingSettings/default", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// WorkspaceManagedSqlServerExtendedBlobAuditingPoliciesCreateOrUpdateThenPoll performs WorkspaceManagedSqlServerExtendedBlobAuditingPoliciesCreateOrUpdate then polls until it's completed +func (c WorkspaceManagedSqlServerBlobAuditingClient) WorkspaceManagedSqlServerExtendedBlobAuditingPoliciesCreateOrUpdateThenPoll(ctx context.Context, id WorkspaceId, input ExtendedServerBlobAuditingPolicy) error { + result, err := c.WorkspaceManagedSqlServerExtendedBlobAuditingPoliciesCreateOrUpdate(ctx, id, input) + if err != nil { + return fmt.Errorf("performing WorkspaceManagedSqlServerExtendedBlobAuditingPoliciesCreateOrUpdate: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after WorkspaceManagedSqlServerExtendedBlobAuditingPoliciesCreateOrUpdate: %+v", err) + } + + return nil +} diff --git a/resource-manager/synapse/2021-06-01/workspacemanagedsqlserverblobauditing/method_workspacemanagedsqlserverextendedblobauditingpoliciesget.go b/resource-manager/synapse/2021-06-01/workspacemanagedsqlserverblobauditing/method_workspacemanagedsqlserverextendedblobauditingpoliciesget.go new file mode 100644 index 00000000000..7d894c7ff26 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/workspacemanagedsqlserverblobauditing/method_workspacemanagedsqlserverextendedblobauditingpoliciesget.go @@ -0,0 +1,52 @@ +package workspacemanagedsqlserverblobauditing + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type WorkspaceManagedSqlServerExtendedBlobAuditingPoliciesGetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *ExtendedServerBlobAuditingPolicy +} + +// WorkspaceManagedSqlServerExtendedBlobAuditingPoliciesGet ... +func (c WorkspaceManagedSqlServerBlobAuditingClient) WorkspaceManagedSqlServerExtendedBlobAuditingPoliciesGet(ctx context.Context, id WorkspaceId) (result WorkspaceManagedSqlServerExtendedBlobAuditingPoliciesGetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/extendedAuditingSettings/default", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/synapse/2021-06-01/workspacemanagedsqlserverblobauditing/method_workspacemanagedsqlserverextendedblobauditingpolicieslistbyworkspace.go b/resource-manager/synapse/2021-06-01/workspacemanagedsqlserverblobauditing/method_workspacemanagedsqlserverextendedblobauditingpolicieslistbyworkspace.go new file mode 100644 index 00000000000..aea672035c8 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/workspacemanagedsqlserverblobauditing/method_workspacemanagedsqlserverextendedblobauditingpolicieslistbyworkspace.go @@ -0,0 +1,91 @@ +package workspacemanagedsqlserverblobauditing + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type WorkspaceManagedSqlServerExtendedBlobAuditingPoliciesListByWorkspaceOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]ExtendedServerBlobAuditingPolicy +} + +type WorkspaceManagedSqlServerExtendedBlobAuditingPoliciesListByWorkspaceCompleteResult struct { + LatestHttpResponse *http.Response + Items []ExtendedServerBlobAuditingPolicy +} + +// WorkspaceManagedSqlServerExtendedBlobAuditingPoliciesListByWorkspace ... +func (c WorkspaceManagedSqlServerBlobAuditingClient) WorkspaceManagedSqlServerExtendedBlobAuditingPoliciesListByWorkspace(ctx context.Context, id WorkspaceId) (result WorkspaceManagedSqlServerExtendedBlobAuditingPoliciesListByWorkspaceOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/extendedAuditingSettings", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]ExtendedServerBlobAuditingPolicy `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// WorkspaceManagedSqlServerExtendedBlobAuditingPoliciesListByWorkspaceComplete retrieves all the results into a single object +func (c WorkspaceManagedSqlServerBlobAuditingClient) WorkspaceManagedSqlServerExtendedBlobAuditingPoliciesListByWorkspaceComplete(ctx context.Context, id WorkspaceId) (WorkspaceManagedSqlServerExtendedBlobAuditingPoliciesListByWorkspaceCompleteResult, error) { + return c.WorkspaceManagedSqlServerExtendedBlobAuditingPoliciesListByWorkspaceCompleteMatchingPredicate(ctx, id, ExtendedServerBlobAuditingPolicyOperationPredicate{}) +} + +// WorkspaceManagedSqlServerExtendedBlobAuditingPoliciesListByWorkspaceCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c WorkspaceManagedSqlServerBlobAuditingClient) WorkspaceManagedSqlServerExtendedBlobAuditingPoliciesListByWorkspaceCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, predicate ExtendedServerBlobAuditingPolicyOperationPredicate) (result WorkspaceManagedSqlServerExtendedBlobAuditingPoliciesListByWorkspaceCompleteResult, err error) { + items := make([]ExtendedServerBlobAuditingPolicy, 0) + + resp, err := c.WorkspaceManagedSqlServerExtendedBlobAuditingPoliciesListByWorkspace(ctx, id) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = WorkspaceManagedSqlServerExtendedBlobAuditingPoliciesListByWorkspaceCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/synapse/2021-06-01/workspacemanagedsqlserverblobauditing/model_extendedserverblobauditingpolicy.go b/resource-manager/synapse/2021-06-01/workspacemanagedsqlserverblobauditing/model_extendedserverblobauditingpolicy.go new file mode 100644 index 00000000000..c3e44fb46ea --- /dev/null +++ b/resource-manager/synapse/2021-06-01/workspacemanagedsqlserverblobauditing/model_extendedserverblobauditingpolicy.go @@ -0,0 +1,11 @@ +package workspacemanagedsqlserverblobauditing + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ExtendedServerBlobAuditingPolicy struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *ExtendedServerBlobAuditingPolicyProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/synapse/2021-06-01/workspacemanagedsqlserverblobauditing/model_extendedserverblobauditingpolicyproperties.go b/resource-manager/synapse/2021-06-01/workspacemanagedsqlserverblobauditing/model_extendedserverblobauditingpolicyproperties.go new file mode 100644 index 00000000000..e616e89de8d --- /dev/null +++ b/resource-manager/synapse/2021-06-01/workspacemanagedsqlserverblobauditing/model_extendedserverblobauditingpolicyproperties.go @@ -0,0 +1,18 @@ +package workspacemanagedsqlserverblobauditing + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ExtendedServerBlobAuditingPolicyProperties struct { + AuditActionsAndGroups *[]string `json:"auditActionsAndGroups,omitempty"` + IsAzureMonitorTargetEnabled *bool `json:"isAzureMonitorTargetEnabled,omitempty"` + IsDevopsAuditEnabled *bool `json:"isDevopsAuditEnabled,omitempty"` + IsStorageSecondaryKeyInUse *bool `json:"isStorageSecondaryKeyInUse,omitempty"` + PredicateExpression *string `json:"predicateExpression,omitempty"` + QueueDelayMs *int64 `json:"queueDelayMs,omitempty"` + RetentionDays *int64 `json:"retentionDays,omitempty"` + State BlobAuditingPolicyState `json:"state"` + StorageAccountAccessKey *string `json:"storageAccountAccessKey,omitempty"` + StorageAccountSubscriptionId *string `json:"storageAccountSubscriptionId,omitempty"` + StorageEndpoint *string `json:"storageEndpoint,omitempty"` +} diff --git a/resource-manager/synapse/2021-06-01/workspacemanagedsqlserverblobauditing/model_serverblobauditingpolicy.go b/resource-manager/synapse/2021-06-01/workspacemanagedsqlserverblobauditing/model_serverblobauditingpolicy.go new file mode 100644 index 00000000000..e027caae646 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/workspacemanagedsqlserverblobauditing/model_serverblobauditingpolicy.go @@ -0,0 +1,11 @@ +package workspacemanagedsqlserverblobauditing + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ServerBlobAuditingPolicy struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *ServerBlobAuditingPolicyProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/synapse/2021-06-01/workspacemanagedsqlserverblobauditing/model_serverblobauditingpolicyproperties.go b/resource-manager/synapse/2021-06-01/workspacemanagedsqlserverblobauditing/model_serverblobauditingpolicyproperties.go new file mode 100644 index 00000000000..181834d1566 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/workspacemanagedsqlserverblobauditing/model_serverblobauditingpolicyproperties.go @@ -0,0 +1,17 @@ +package workspacemanagedsqlserverblobauditing + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ServerBlobAuditingPolicyProperties struct { + AuditActionsAndGroups *[]string `json:"auditActionsAndGroups,omitempty"` + IsAzureMonitorTargetEnabled *bool `json:"isAzureMonitorTargetEnabled,omitempty"` + IsDevopsAuditEnabled *bool `json:"isDevopsAuditEnabled,omitempty"` + IsStorageSecondaryKeyInUse *bool `json:"isStorageSecondaryKeyInUse,omitempty"` + QueueDelayMs *int64 `json:"queueDelayMs,omitempty"` + RetentionDays *int64 `json:"retentionDays,omitempty"` + State BlobAuditingPolicyState `json:"state"` + StorageAccountAccessKey *string `json:"storageAccountAccessKey,omitempty"` + StorageAccountSubscriptionId *string `json:"storageAccountSubscriptionId,omitempty"` + StorageEndpoint *string `json:"storageEndpoint,omitempty"` +} diff --git a/resource-manager/synapse/2021-06-01/workspacemanagedsqlserverblobauditing/predicates.go b/resource-manager/synapse/2021-06-01/workspacemanagedsqlserverblobauditing/predicates.go new file mode 100644 index 00000000000..fee9137b590 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/workspacemanagedsqlserverblobauditing/predicates.go @@ -0,0 +1,50 @@ +package workspacemanagedsqlserverblobauditing + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ExtendedServerBlobAuditingPolicyOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p ExtendedServerBlobAuditingPolicyOperationPredicate) Matches(input ExtendedServerBlobAuditingPolicy) bool { + + if p.Id != nil && (input.Id == nil || *p.Id != *input.Id) { + return false + } + + if p.Name != nil && (input.Name == nil || *p.Name != *input.Name) { + return false + } + + if p.Type != nil && (input.Type == nil || *p.Type != *input.Type) { + return false + } + + return true +} + +type ServerBlobAuditingPolicyOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p ServerBlobAuditingPolicyOperationPredicate) Matches(input ServerBlobAuditingPolicy) bool { + + if p.Id != nil && (input.Id == nil || *p.Id != *input.Id) { + return false + } + + if p.Name != nil && (input.Name == nil || *p.Name != *input.Name) { + return false + } + + if p.Type != nil && (input.Type == nil || *p.Type != *input.Type) { + return false + } + + return true +} diff --git a/resource-manager/synapse/2021-06-01/workspacemanagedsqlserverblobauditing/version.go b/resource-manager/synapse/2021-06-01/workspacemanagedsqlserverblobauditing/version.go new file mode 100644 index 00000000000..be48e786dc0 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/workspacemanagedsqlserverblobauditing/version.go @@ -0,0 +1,12 @@ +package workspacemanagedsqlserverblobauditing + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2021-06-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/workspacemanagedsqlserverblobauditing/%s", defaultApiVersion) +} diff --git a/resource-manager/synapse/2021-06-01/workspacemanagedsqlserverdedicatedsqlminimaltlssettings/README.md b/resource-manager/synapse/2021-06-01/workspacemanagedsqlserverdedicatedsqlminimaltlssettings/README.md new file mode 100644 index 00000000000..5cc82b6a42d --- /dev/null +++ b/resource-manager/synapse/2021-06-01/workspacemanagedsqlserverdedicatedsqlminimaltlssettings/README.md @@ -0,0 +1,70 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/synapse/2021-06-01/workspacemanagedsqlserverdedicatedsqlminimaltlssettings` Documentation + +The `workspacemanagedsqlserverdedicatedsqlminimaltlssettings` SDK allows for interaction with the Azure Resource Manager Service `synapse` (API Version `2021-06-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/synapse/2021-06-01/workspacemanagedsqlserverdedicatedsqlminimaltlssettings" +``` + + +### Client Initialization + +```go +client := workspacemanagedsqlserverdedicatedsqlminimaltlssettings.NewWorkspaceManagedSqlServerDedicatedSQLminimalTlsSettingsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `WorkspaceManagedSqlServerDedicatedSQLminimalTlsSettingsClient.Get` + +```go +ctx := context.TODO() +id := workspacemanagedsqlserverdedicatedsqlminimaltlssettings.NewDedicatedSQLMinimalTLSSettingID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "dedicatedSQLMinimalTLSSettingValue") + +read, err := client.Get(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `WorkspaceManagedSqlServerDedicatedSQLminimalTlsSettingsClient.List` + +```go +ctx := context.TODO() +id := workspacemanagedsqlserverdedicatedsqlminimaltlssettings.NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue") + +// alternatively `client.List(ctx, id)` can be used to do batched pagination +items, err := client.ListComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `WorkspaceManagedSqlServerDedicatedSQLminimalTlsSettingsClient.Update` + +```go +ctx := context.TODO() +id := workspacemanagedsqlserverdedicatedsqlminimaltlssettings.NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue") + +payload := workspacemanagedsqlserverdedicatedsqlminimaltlssettings.DedicatedSQLMinimalTLSSettings{ + // ... +} + + +if err := client.UpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` diff --git a/resource-manager/synapse/2021-06-01/workspacemanagedsqlserverdedicatedsqlminimaltlssettings/client.go b/resource-manager/synapse/2021-06-01/workspacemanagedsqlserverdedicatedsqlminimaltlssettings/client.go new file mode 100644 index 00000000000..2162f7dd54e --- /dev/null +++ b/resource-manager/synapse/2021-06-01/workspacemanagedsqlserverdedicatedsqlminimaltlssettings/client.go @@ -0,0 +1,26 @@ +package workspacemanagedsqlserverdedicatedsqlminimaltlssettings + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type WorkspaceManagedSqlServerDedicatedSQLminimalTlsSettingsClient struct { + Client *resourcemanager.Client +} + +func NewWorkspaceManagedSqlServerDedicatedSQLminimalTlsSettingsClientWithBaseURI(sdkApi sdkEnv.Api) (*WorkspaceManagedSqlServerDedicatedSQLminimalTlsSettingsClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "workspacemanagedsqlserverdedicatedsqlminimaltlssettings", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating WorkspaceManagedSqlServerDedicatedSQLminimalTlsSettingsClient: %+v", err) + } + + return &WorkspaceManagedSqlServerDedicatedSQLminimalTlsSettingsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/synapse/2021-06-01/workspacemanagedsqlserverdedicatedsqlminimaltlssettings/id_dedicatedsqlminimaltlssetting.go b/resource-manager/synapse/2021-06-01/workspacemanagedsqlserverdedicatedsqlminimaltlssettings/id_dedicatedsqlminimaltlssetting.go new file mode 100644 index 00000000000..e6f43892c09 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/workspacemanagedsqlserverdedicatedsqlminimaltlssettings/id_dedicatedsqlminimaltlssetting.go @@ -0,0 +1,134 @@ +package workspacemanagedsqlserverdedicatedsqlminimaltlssettings + +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 = &DedicatedSQLMinimalTLSSettingId{} + +// DedicatedSQLMinimalTLSSettingId is a struct representing the Resource ID for a Dedicated S Q L Minimal T L S Setting +type DedicatedSQLMinimalTLSSettingId struct { + SubscriptionId string + ResourceGroupName string + WorkspaceName string + DedicatedSQLMinimalTLSSettingName string +} + +// NewDedicatedSQLMinimalTLSSettingID returns a new DedicatedSQLMinimalTLSSettingId struct +func NewDedicatedSQLMinimalTLSSettingID(subscriptionId string, resourceGroupName string, workspaceName string, dedicatedSQLMinimalTLSSettingName string) DedicatedSQLMinimalTLSSettingId { + return DedicatedSQLMinimalTLSSettingId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + WorkspaceName: workspaceName, + DedicatedSQLMinimalTLSSettingName: dedicatedSQLMinimalTLSSettingName, + } +} + +// ParseDedicatedSQLMinimalTLSSettingID parses 'input' into a DedicatedSQLMinimalTLSSettingId +func ParseDedicatedSQLMinimalTLSSettingID(input string) (*DedicatedSQLMinimalTLSSettingId, error) { + parser := resourceids.NewParserFromResourceIdType(&DedicatedSQLMinimalTLSSettingId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := DedicatedSQLMinimalTLSSettingId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseDedicatedSQLMinimalTLSSettingIDInsensitively parses 'input' case-insensitively into a DedicatedSQLMinimalTLSSettingId +// note: this method should only be used for API response data and not user input +func ParseDedicatedSQLMinimalTLSSettingIDInsensitively(input string) (*DedicatedSQLMinimalTLSSettingId, error) { + parser := resourceids.NewParserFromResourceIdType(&DedicatedSQLMinimalTLSSettingId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := DedicatedSQLMinimalTLSSettingId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *DedicatedSQLMinimalTLSSettingId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.WorkspaceName, ok = input.Parsed["workspaceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "workspaceName", input) + } + + if id.DedicatedSQLMinimalTLSSettingName, ok = input.Parsed["dedicatedSQLMinimalTLSSettingName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "dedicatedSQLMinimalTLSSettingName", input) + } + + return nil +} + +// ValidateDedicatedSQLMinimalTLSSettingID checks that 'input' can be parsed as a Dedicated S Q L Minimal T L S Setting ID +func ValidateDedicatedSQLMinimalTLSSettingID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseDedicatedSQLMinimalTLSSettingID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Dedicated S Q L Minimal T L S Setting ID +func (id DedicatedSQLMinimalTLSSettingId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Synapse/workspaces/%s/dedicatedSQLMinimalTLSSettings/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.WorkspaceName, id.DedicatedSQLMinimalTLSSettingName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Dedicated S Q L Minimal T L S Setting ID +func (id DedicatedSQLMinimalTLSSettingId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftSynapse", "Microsoft.Synapse", "Microsoft.Synapse"), + resourceids.StaticSegment("staticWorkspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceName", "workspaceValue"), + resourceids.StaticSegment("staticDedicatedSQLMinimalTLSSettings", "dedicatedSQLMinimalTLSSettings", "dedicatedSQLMinimalTLSSettings"), + resourceids.UserSpecifiedSegment("dedicatedSQLMinimalTLSSettingName", "dedicatedSQLMinimalTLSSettingValue"), + } +} + +// String returns a human-readable description of this Dedicated S Q L Minimal T L S Setting ID +func (id DedicatedSQLMinimalTLSSettingId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Workspace Name: %q", id.WorkspaceName), + fmt.Sprintf("Dedicated S Q L Minimal T L S Setting Name: %q", id.DedicatedSQLMinimalTLSSettingName), + } + return fmt.Sprintf("Dedicated S Q L Minimal T L S Setting (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/synapse/2021-06-01/workspacemanagedsqlserverdedicatedsqlminimaltlssettings/id_dedicatedsqlminimaltlssetting_test.go b/resource-manager/synapse/2021-06-01/workspacemanagedsqlserverdedicatedsqlminimaltlssettings/id_dedicatedsqlminimaltlssetting_test.go new file mode 100644 index 00000000000..7bb27135354 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/workspacemanagedsqlserverdedicatedsqlminimaltlssettings/id_dedicatedsqlminimaltlssetting_test.go @@ -0,0 +1,327 @@ +package workspacemanagedsqlserverdedicatedsqlminimaltlssettings + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &DedicatedSQLMinimalTLSSettingId{} + +func TestNewDedicatedSQLMinimalTLSSettingID(t *testing.T) { + id := NewDedicatedSQLMinimalTLSSettingID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "dedicatedSQLMinimalTLSSettingValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.WorkspaceName != "workspaceValue" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceName'", id.WorkspaceName, "workspaceValue") + } + + if id.DedicatedSQLMinimalTLSSettingName != "dedicatedSQLMinimalTLSSettingValue" { + t.Fatalf("Expected %q but got %q for Segment 'DedicatedSQLMinimalTLSSettingName'", id.DedicatedSQLMinimalTLSSettingName, "dedicatedSQLMinimalTLSSettingValue") + } +} + +func TestFormatDedicatedSQLMinimalTLSSettingID(t *testing.T) { + actual := NewDedicatedSQLMinimalTLSSettingID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "dedicatedSQLMinimalTLSSettingValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/dedicatedSQLMinimalTLSSettings/dedicatedSQLMinimalTLSSettingValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseDedicatedSQLMinimalTLSSettingID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *DedicatedSQLMinimalTLSSettingId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/dedicatedSQLMinimalTLSSettings", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/dedicatedSQLMinimalTLSSettings/dedicatedSQLMinimalTLSSettingValue", + Expected: &DedicatedSQLMinimalTLSSettingId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + DedicatedSQLMinimalTLSSettingName: "dedicatedSQLMinimalTLSSettingValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/dedicatedSQLMinimalTLSSettings/dedicatedSQLMinimalTLSSettingValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseDedicatedSQLMinimalTLSSettingID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + if actual.DedicatedSQLMinimalTLSSettingName != v.Expected.DedicatedSQLMinimalTLSSettingName { + t.Fatalf("Expected %q but got %q for DedicatedSQLMinimalTLSSettingName", v.Expected.DedicatedSQLMinimalTLSSettingName, actual.DedicatedSQLMinimalTLSSettingName) + } + + } +} + +func TestParseDedicatedSQLMinimalTLSSettingIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *DedicatedSQLMinimalTLSSettingId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/dedicatedSQLMinimalTLSSettings", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/dEdIcAtEdSqLmInImAlTlSsEtTiNgS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/dedicatedSQLMinimalTLSSettings/dedicatedSQLMinimalTLSSettingValue", + Expected: &DedicatedSQLMinimalTLSSettingId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + DedicatedSQLMinimalTLSSettingName: "dedicatedSQLMinimalTLSSettingValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/dedicatedSQLMinimalTLSSettings/dedicatedSQLMinimalTLSSettingValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/dEdIcAtEdSqLmInImAlTlSsEtTiNgS/dEdIcAtEdSqLmInImAlTlSsEtTiNgVaLuE", + Expected: &DedicatedSQLMinimalTLSSettingId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + WorkspaceName: "wOrKsPaCeVaLuE", + DedicatedSQLMinimalTLSSettingName: "dEdIcAtEdSqLmInImAlTlSsEtTiNgVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/dEdIcAtEdSqLmInImAlTlSsEtTiNgS/dEdIcAtEdSqLmInImAlTlSsEtTiNgVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseDedicatedSQLMinimalTLSSettingIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + if actual.DedicatedSQLMinimalTLSSettingName != v.Expected.DedicatedSQLMinimalTLSSettingName { + t.Fatalf("Expected %q but got %q for DedicatedSQLMinimalTLSSettingName", v.Expected.DedicatedSQLMinimalTLSSettingName, actual.DedicatedSQLMinimalTLSSettingName) + } + + } +} + +func TestSegmentsForDedicatedSQLMinimalTLSSettingId(t *testing.T) { + segments := DedicatedSQLMinimalTLSSettingId{}.Segments() + if len(segments) == 0 { + t.Fatalf("DedicatedSQLMinimalTLSSettingId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/synapse/2021-06-01/workspacemanagedsqlserverdedicatedsqlminimaltlssettings/id_workspace.go b/resource-manager/synapse/2021-06-01/workspacemanagedsqlserverdedicatedsqlminimaltlssettings/id_workspace.go new file mode 100644 index 00000000000..451589c722a --- /dev/null +++ b/resource-manager/synapse/2021-06-01/workspacemanagedsqlserverdedicatedsqlminimaltlssettings/id_workspace.go @@ -0,0 +1,125 @@ +package workspacemanagedsqlserverdedicatedsqlminimaltlssettings + +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 = &WorkspaceId{} + +// WorkspaceId is a struct representing the Resource ID for a Workspace +type WorkspaceId struct { + SubscriptionId string + ResourceGroupName string + WorkspaceName string +} + +// NewWorkspaceID returns a new WorkspaceId struct +func NewWorkspaceID(subscriptionId string, resourceGroupName string, workspaceName string) WorkspaceId { + return WorkspaceId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + WorkspaceName: workspaceName, + } +} + +// ParseWorkspaceID parses 'input' into a WorkspaceId +func ParseWorkspaceID(input string) (*WorkspaceId, error) { + parser := resourceids.NewParserFromResourceIdType(&WorkspaceId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := WorkspaceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseWorkspaceIDInsensitively parses 'input' case-insensitively into a WorkspaceId +// note: this method should only be used for API response data and not user input +func ParseWorkspaceIDInsensitively(input string) (*WorkspaceId, error) { + parser := resourceids.NewParserFromResourceIdType(&WorkspaceId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := WorkspaceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *WorkspaceId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.WorkspaceName, ok = input.Parsed["workspaceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "workspaceName", input) + } + + return nil +} + +// ValidateWorkspaceID checks that 'input' can be parsed as a Workspace ID +func ValidateWorkspaceID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseWorkspaceID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Workspace ID +func (id WorkspaceId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Synapse/workspaces/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.WorkspaceName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Workspace ID +func (id WorkspaceId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftSynapse", "Microsoft.Synapse", "Microsoft.Synapse"), + resourceids.StaticSegment("staticWorkspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceName", "workspaceValue"), + } +} + +// String returns a human-readable description of this Workspace ID +func (id WorkspaceId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Workspace Name: %q", id.WorkspaceName), + } + return fmt.Sprintf("Workspace (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/synapse/2021-06-01/workspacemanagedsqlserverdedicatedsqlminimaltlssettings/id_workspace_test.go b/resource-manager/synapse/2021-06-01/workspacemanagedsqlserverdedicatedsqlminimaltlssettings/id_workspace_test.go new file mode 100644 index 00000000000..3fbc111795c --- /dev/null +++ b/resource-manager/synapse/2021-06-01/workspacemanagedsqlserverdedicatedsqlminimaltlssettings/id_workspace_test.go @@ -0,0 +1,282 @@ +package workspacemanagedsqlserverdedicatedsqlminimaltlssettings + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &WorkspaceId{} + +func TestNewWorkspaceID(t *testing.T) { + id := NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.WorkspaceName != "workspaceValue" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceName'", id.WorkspaceName, "workspaceValue") + } +} + +func TestFormatWorkspaceID(t *testing.T) { + actual := NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseWorkspaceID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkspaceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue", + Expected: &WorkspaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkspaceID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + } +} + +func TestParseWorkspaceIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkspaceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue", + Expected: &WorkspaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE", + Expected: &WorkspaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + WorkspaceName: "wOrKsPaCeVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkspaceIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + } +} + +func TestSegmentsForWorkspaceId(t *testing.T) { + segments := WorkspaceId{}.Segments() + if len(segments) == 0 { + t.Fatalf("WorkspaceId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/synapse/2021-06-01/workspacemanagedsqlserverdedicatedsqlminimaltlssettings/method_get.go b/resource-manager/synapse/2021-06-01/workspacemanagedsqlserverdedicatedsqlminimaltlssettings/method_get.go new file mode 100644 index 00000000000..dc8bb2ab149 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/workspacemanagedsqlserverdedicatedsqlminimaltlssettings/method_get.go @@ -0,0 +1,51 @@ +package workspacemanagedsqlserverdedicatedsqlminimaltlssettings + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *DedicatedSQLMinimalTLSSettings +} + +// Get ... +func (c WorkspaceManagedSqlServerDedicatedSQLminimalTlsSettingsClient) Get(ctx context.Context, id DedicatedSQLMinimalTLSSettingId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/synapse/2021-06-01/workspacemanagedsqlserverdedicatedsqlminimaltlssettings/method_list.go b/resource-manager/synapse/2021-06-01/workspacemanagedsqlserverdedicatedsqlminimaltlssettings/method_list.go new file mode 100644 index 00000000000..0d7103563c4 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/workspacemanagedsqlserverdedicatedsqlminimaltlssettings/method_list.go @@ -0,0 +1,91 @@ +package workspacemanagedsqlserverdedicatedsqlminimaltlssettings + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]DedicatedSQLMinimalTLSSettings +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []DedicatedSQLMinimalTLSSettings +} + +// List ... +func (c WorkspaceManagedSqlServerDedicatedSQLminimalTlsSettingsClient) List(ctx context.Context, id WorkspaceId) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/dedicatedSQLMinimalTLSSettings", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]DedicatedSQLMinimalTLSSettings `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListComplete retrieves all the results into a single object +func (c WorkspaceManagedSqlServerDedicatedSQLminimalTlsSettingsClient) ListComplete(ctx context.Context, id WorkspaceId) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, DedicatedSQLMinimalTLSSettingsOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c WorkspaceManagedSqlServerDedicatedSQLminimalTlsSettingsClient) ListCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, predicate DedicatedSQLMinimalTLSSettingsOperationPredicate) (result ListCompleteResult, err error) { + items := make([]DedicatedSQLMinimalTLSSettings, 0) + + resp, err := c.List(ctx, id) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/synapse/2021-06-01/workspacemanagedsqlserverdedicatedsqlminimaltlssettings/method_update.go b/resource-manager/synapse/2021-06-01/workspacemanagedsqlserverdedicatedsqlminimaltlssettings/method_update.go new file mode 100644 index 00000000000..1f4f60f30be --- /dev/null +++ b/resource-manager/synapse/2021-06-01/workspacemanagedsqlserverdedicatedsqlminimaltlssettings/method_update.go @@ -0,0 +1,75 @@ +package workspacemanagedsqlserverdedicatedsqlminimaltlssettings + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type UpdateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *DedicatedSQLMinimalTLSSettings +} + +// Update ... +func (c WorkspaceManagedSqlServerDedicatedSQLminimalTlsSettingsClient) Update(ctx context.Context, id WorkspaceId, input DedicatedSQLMinimalTLSSettings) (result UpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: fmt.Sprintf("%s/dedicatedSQLMinimalTLSSettings/default", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// UpdateThenPoll performs Update then polls until it's completed +func (c WorkspaceManagedSqlServerDedicatedSQLminimalTlsSettingsClient) UpdateThenPoll(ctx context.Context, id WorkspaceId, input DedicatedSQLMinimalTLSSettings) error { + result, err := c.Update(ctx, id, input) + if err != nil { + return fmt.Errorf("performing Update: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after Update: %+v", err) + } + + return nil +} diff --git a/resource-manager/synapse/2021-06-01/workspacemanagedsqlserverdedicatedsqlminimaltlssettings/model_dedicatedsqlminimaltlssettings.go b/resource-manager/synapse/2021-06-01/workspacemanagedsqlserverdedicatedsqlminimaltlssettings/model_dedicatedsqlminimaltlssettings.go new file mode 100644 index 00000000000..bd3809c4ccf --- /dev/null +++ b/resource-manager/synapse/2021-06-01/workspacemanagedsqlserverdedicatedsqlminimaltlssettings/model_dedicatedsqlminimaltlssettings.go @@ -0,0 +1,12 @@ +package workspacemanagedsqlserverdedicatedsqlminimaltlssettings + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DedicatedSQLMinimalTLSSettings struct { + Id *string `json:"id,omitempty"` + Location *string `json:"location,omitempty"` + Name *string `json:"name,omitempty"` + Properties *DedicatedSQLminimalTlsSettingsProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/synapse/2021-06-01/workspacemanagedsqlserverdedicatedsqlminimaltlssettings/model_dedicatedsqlminimaltlssettingsproperties.go b/resource-manager/synapse/2021-06-01/workspacemanagedsqlserverdedicatedsqlminimaltlssettings/model_dedicatedsqlminimaltlssettingsproperties.go new file mode 100644 index 00000000000..651cfc3bfa3 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/workspacemanagedsqlserverdedicatedsqlminimaltlssettings/model_dedicatedsqlminimaltlssettingsproperties.go @@ -0,0 +1,8 @@ +package workspacemanagedsqlserverdedicatedsqlminimaltlssettings + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DedicatedSQLminimalTlsSettingsProperties struct { + MinimalTlsVersion *string `json:"minimalTlsVersion,omitempty"` +} diff --git a/resource-manager/synapse/2021-06-01/workspacemanagedsqlserverdedicatedsqlminimaltlssettings/predicates.go b/resource-manager/synapse/2021-06-01/workspacemanagedsqlserverdedicatedsqlminimaltlssettings/predicates.go new file mode 100644 index 00000000000..225666644fd --- /dev/null +++ b/resource-manager/synapse/2021-06-01/workspacemanagedsqlserverdedicatedsqlminimaltlssettings/predicates.go @@ -0,0 +1,32 @@ +package workspacemanagedsqlserverdedicatedsqlminimaltlssettings + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DedicatedSQLMinimalTLSSettingsOperationPredicate struct { + Id *string + Location *string + Name *string + Type *string +} + +func (p DedicatedSQLMinimalTLSSettingsOperationPredicate) Matches(input DedicatedSQLMinimalTLSSettings) bool { + + if p.Id != nil && (input.Id == nil || *p.Id != *input.Id) { + return false + } + + if p.Location != nil && (input.Location == nil || *p.Location != *input.Location) { + return false + } + + if p.Name != nil && (input.Name == nil || *p.Name != *input.Name) { + return false + } + + if p.Type != nil && (input.Type == nil || *p.Type != *input.Type) { + return false + } + + return true +} diff --git a/resource-manager/synapse/2021-06-01/workspacemanagedsqlserverdedicatedsqlminimaltlssettings/version.go b/resource-manager/synapse/2021-06-01/workspacemanagedsqlserverdedicatedsqlminimaltlssettings/version.go new file mode 100644 index 00000000000..9ea0aefe80d --- /dev/null +++ b/resource-manager/synapse/2021-06-01/workspacemanagedsqlserverdedicatedsqlminimaltlssettings/version.go @@ -0,0 +1,12 @@ +package workspacemanagedsqlserverdedicatedsqlminimaltlssettings + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2021-06-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/workspacemanagedsqlserverdedicatedsqlminimaltlssettings/%s", defaultApiVersion) +} diff --git a/resource-manager/synapse/2021-06-01/workspacemanagedsqlserversecurityalertpolicies/README.md b/resource-manager/synapse/2021-06-01/workspacemanagedsqlserversecurityalertpolicies/README.md new file mode 100644 index 00000000000..2a64fe66368 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/workspacemanagedsqlserversecurityalertpolicies/README.md @@ -0,0 +1,70 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/synapse/2021-06-01/workspacemanagedsqlserversecurityalertpolicies` Documentation + +The `workspacemanagedsqlserversecurityalertpolicies` SDK allows for interaction with the Azure Resource Manager Service `synapse` (API Version `2021-06-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/synapse/2021-06-01/workspacemanagedsqlserversecurityalertpolicies" +``` + + +### Client Initialization + +```go +client := workspacemanagedsqlserversecurityalertpolicies.NewWorkspaceManagedSqlServerSecurityAlertPoliciesClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `WorkspaceManagedSqlServerSecurityAlertPoliciesClient.WorkspaceManagedSqlServerSecurityAlertPolicyCreateOrUpdate` + +```go +ctx := context.TODO() +id := workspacemanagedsqlserversecurityalertpolicies.NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue") + +payload := workspacemanagedsqlserversecurityalertpolicies.ServerSecurityAlertPolicy{ + // ... +} + + +if err := client.WorkspaceManagedSqlServerSecurityAlertPolicyCreateOrUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `WorkspaceManagedSqlServerSecurityAlertPoliciesClient.WorkspaceManagedSqlServerSecurityAlertPolicyGet` + +```go +ctx := context.TODO() +id := workspacemanagedsqlserversecurityalertpolicies.NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue") + +read, err := client.WorkspaceManagedSqlServerSecurityAlertPolicyGet(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `WorkspaceManagedSqlServerSecurityAlertPoliciesClient.WorkspaceManagedSqlServerSecurityAlertPolicyList` + +```go +ctx := context.TODO() +id := workspacemanagedsqlserversecurityalertpolicies.NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue") + +// alternatively `client.WorkspaceManagedSqlServerSecurityAlertPolicyList(ctx, id)` can be used to do batched pagination +items, err := client.WorkspaceManagedSqlServerSecurityAlertPolicyListComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/synapse/2021-06-01/workspacemanagedsqlserversecurityalertpolicies/client.go b/resource-manager/synapse/2021-06-01/workspacemanagedsqlserversecurityalertpolicies/client.go new file mode 100644 index 00000000000..7c22d3ccc87 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/workspacemanagedsqlserversecurityalertpolicies/client.go @@ -0,0 +1,26 @@ +package workspacemanagedsqlserversecurityalertpolicies + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type WorkspaceManagedSqlServerSecurityAlertPoliciesClient struct { + Client *resourcemanager.Client +} + +func NewWorkspaceManagedSqlServerSecurityAlertPoliciesClientWithBaseURI(sdkApi sdkEnv.Api) (*WorkspaceManagedSqlServerSecurityAlertPoliciesClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "workspacemanagedsqlserversecurityalertpolicies", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating WorkspaceManagedSqlServerSecurityAlertPoliciesClient: %+v", err) + } + + return &WorkspaceManagedSqlServerSecurityAlertPoliciesClient{ + Client: client, + }, nil +} diff --git a/resource-manager/synapse/2021-06-01/workspacemanagedsqlserversecurityalertpolicies/constants.go b/resource-manager/synapse/2021-06-01/workspacemanagedsqlserversecurityalertpolicies/constants.go new file mode 100644 index 00000000000..337c2a4a506 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/workspacemanagedsqlserversecurityalertpolicies/constants.go @@ -0,0 +1,54 @@ +package workspacemanagedsqlserversecurityalertpolicies + +import ( + "encoding/json" + "fmt" + "strings" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SecurityAlertPolicyState string + +const ( + SecurityAlertPolicyStateDisabled SecurityAlertPolicyState = "Disabled" + SecurityAlertPolicyStateEnabled SecurityAlertPolicyState = "Enabled" + SecurityAlertPolicyStateNew SecurityAlertPolicyState = "New" +) + +func PossibleValuesForSecurityAlertPolicyState() []string { + return []string{ + string(SecurityAlertPolicyStateDisabled), + string(SecurityAlertPolicyStateEnabled), + string(SecurityAlertPolicyStateNew), + } +} + +func (s *SecurityAlertPolicyState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseSecurityAlertPolicyState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseSecurityAlertPolicyState(input string) (*SecurityAlertPolicyState, error) { + vals := map[string]SecurityAlertPolicyState{ + "disabled": SecurityAlertPolicyStateDisabled, + "enabled": SecurityAlertPolicyStateEnabled, + "new": SecurityAlertPolicyStateNew, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := SecurityAlertPolicyState(input) + return &out, nil +} diff --git a/resource-manager/synapse/2021-06-01/workspacemanagedsqlserversecurityalertpolicies/id_workspace.go b/resource-manager/synapse/2021-06-01/workspacemanagedsqlserversecurityalertpolicies/id_workspace.go new file mode 100644 index 00000000000..bbaf1aa9695 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/workspacemanagedsqlserversecurityalertpolicies/id_workspace.go @@ -0,0 +1,125 @@ +package workspacemanagedsqlserversecurityalertpolicies + +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 = &WorkspaceId{} + +// WorkspaceId is a struct representing the Resource ID for a Workspace +type WorkspaceId struct { + SubscriptionId string + ResourceGroupName string + WorkspaceName string +} + +// NewWorkspaceID returns a new WorkspaceId struct +func NewWorkspaceID(subscriptionId string, resourceGroupName string, workspaceName string) WorkspaceId { + return WorkspaceId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + WorkspaceName: workspaceName, + } +} + +// ParseWorkspaceID parses 'input' into a WorkspaceId +func ParseWorkspaceID(input string) (*WorkspaceId, error) { + parser := resourceids.NewParserFromResourceIdType(&WorkspaceId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := WorkspaceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseWorkspaceIDInsensitively parses 'input' case-insensitively into a WorkspaceId +// note: this method should only be used for API response data and not user input +func ParseWorkspaceIDInsensitively(input string) (*WorkspaceId, error) { + parser := resourceids.NewParserFromResourceIdType(&WorkspaceId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := WorkspaceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *WorkspaceId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.WorkspaceName, ok = input.Parsed["workspaceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "workspaceName", input) + } + + return nil +} + +// ValidateWorkspaceID checks that 'input' can be parsed as a Workspace ID +func ValidateWorkspaceID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseWorkspaceID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Workspace ID +func (id WorkspaceId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Synapse/workspaces/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.WorkspaceName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Workspace ID +func (id WorkspaceId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftSynapse", "Microsoft.Synapse", "Microsoft.Synapse"), + resourceids.StaticSegment("staticWorkspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceName", "workspaceValue"), + } +} + +// String returns a human-readable description of this Workspace ID +func (id WorkspaceId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Workspace Name: %q", id.WorkspaceName), + } + return fmt.Sprintf("Workspace (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/synapse/2021-06-01/workspacemanagedsqlserversecurityalertpolicies/id_workspace_test.go b/resource-manager/synapse/2021-06-01/workspacemanagedsqlserversecurityalertpolicies/id_workspace_test.go new file mode 100644 index 00000000000..7c6e891699f --- /dev/null +++ b/resource-manager/synapse/2021-06-01/workspacemanagedsqlserversecurityalertpolicies/id_workspace_test.go @@ -0,0 +1,282 @@ +package workspacemanagedsqlserversecurityalertpolicies + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &WorkspaceId{} + +func TestNewWorkspaceID(t *testing.T) { + id := NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.WorkspaceName != "workspaceValue" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceName'", id.WorkspaceName, "workspaceValue") + } +} + +func TestFormatWorkspaceID(t *testing.T) { + actual := NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseWorkspaceID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkspaceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue", + Expected: &WorkspaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkspaceID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + } +} + +func TestParseWorkspaceIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkspaceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue", + Expected: &WorkspaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE", + Expected: &WorkspaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + WorkspaceName: "wOrKsPaCeVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkspaceIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + } +} + +func TestSegmentsForWorkspaceId(t *testing.T) { + segments := WorkspaceId{}.Segments() + if len(segments) == 0 { + t.Fatalf("WorkspaceId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/synapse/2021-06-01/workspacemanagedsqlserversecurityalertpolicies/method_workspacemanagedsqlserversecurityalertpolicycreateorupdate.go b/resource-manager/synapse/2021-06-01/workspacemanagedsqlserversecurityalertpolicies/method_workspacemanagedsqlserversecurityalertpolicycreateorupdate.go new file mode 100644 index 00000000000..0327c32d06d --- /dev/null +++ b/resource-manager/synapse/2021-06-01/workspacemanagedsqlserversecurityalertpolicies/method_workspacemanagedsqlserversecurityalertpolicycreateorupdate.go @@ -0,0 +1,75 @@ +package workspacemanagedsqlserversecurityalertpolicies + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type WorkspaceManagedSqlServerSecurityAlertPolicyCreateOrUpdateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *ServerSecurityAlertPolicy +} + +// WorkspaceManagedSqlServerSecurityAlertPolicyCreateOrUpdate ... +func (c WorkspaceManagedSqlServerSecurityAlertPoliciesClient) WorkspaceManagedSqlServerSecurityAlertPolicyCreateOrUpdate(ctx context.Context, id WorkspaceId, input ServerSecurityAlertPolicy) (result WorkspaceManagedSqlServerSecurityAlertPolicyCreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: fmt.Sprintf("%s/securityAlertPolicies/default", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// WorkspaceManagedSqlServerSecurityAlertPolicyCreateOrUpdateThenPoll performs WorkspaceManagedSqlServerSecurityAlertPolicyCreateOrUpdate then polls until it's completed +func (c WorkspaceManagedSqlServerSecurityAlertPoliciesClient) WorkspaceManagedSqlServerSecurityAlertPolicyCreateOrUpdateThenPoll(ctx context.Context, id WorkspaceId, input ServerSecurityAlertPolicy) error { + result, err := c.WorkspaceManagedSqlServerSecurityAlertPolicyCreateOrUpdate(ctx, id, input) + if err != nil { + return fmt.Errorf("performing WorkspaceManagedSqlServerSecurityAlertPolicyCreateOrUpdate: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after WorkspaceManagedSqlServerSecurityAlertPolicyCreateOrUpdate: %+v", err) + } + + return nil +} diff --git a/resource-manager/synapse/2021-06-01/workspacemanagedsqlserversecurityalertpolicies/method_workspacemanagedsqlserversecurityalertpolicyget.go b/resource-manager/synapse/2021-06-01/workspacemanagedsqlserversecurityalertpolicies/method_workspacemanagedsqlserversecurityalertpolicyget.go new file mode 100644 index 00000000000..677a0f0e9a9 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/workspacemanagedsqlserversecurityalertpolicies/method_workspacemanagedsqlserversecurityalertpolicyget.go @@ -0,0 +1,52 @@ +package workspacemanagedsqlserversecurityalertpolicies + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type WorkspaceManagedSqlServerSecurityAlertPolicyGetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *ServerSecurityAlertPolicy +} + +// WorkspaceManagedSqlServerSecurityAlertPolicyGet ... +func (c WorkspaceManagedSqlServerSecurityAlertPoliciesClient) WorkspaceManagedSqlServerSecurityAlertPolicyGet(ctx context.Context, id WorkspaceId) (result WorkspaceManagedSqlServerSecurityAlertPolicyGetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/securityAlertPolicies/default", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/synapse/2021-06-01/workspacemanagedsqlserversecurityalertpolicies/method_workspacemanagedsqlserversecurityalertpolicylist.go b/resource-manager/synapse/2021-06-01/workspacemanagedsqlserversecurityalertpolicies/method_workspacemanagedsqlserversecurityalertpolicylist.go new file mode 100644 index 00000000000..c6f3e3c7b33 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/workspacemanagedsqlserversecurityalertpolicies/method_workspacemanagedsqlserversecurityalertpolicylist.go @@ -0,0 +1,91 @@ +package workspacemanagedsqlserversecurityalertpolicies + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type WorkspaceManagedSqlServerSecurityAlertPolicyListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]ServerSecurityAlertPolicy +} + +type WorkspaceManagedSqlServerSecurityAlertPolicyListCompleteResult struct { + LatestHttpResponse *http.Response + Items []ServerSecurityAlertPolicy +} + +// WorkspaceManagedSqlServerSecurityAlertPolicyList ... +func (c WorkspaceManagedSqlServerSecurityAlertPoliciesClient) WorkspaceManagedSqlServerSecurityAlertPolicyList(ctx context.Context, id WorkspaceId) (result WorkspaceManagedSqlServerSecurityAlertPolicyListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/securityAlertPolicies", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]ServerSecurityAlertPolicy `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// WorkspaceManagedSqlServerSecurityAlertPolicyListComplete retrieves all the results into a single object +func (c WorkspaceManagedSqlServerSecurityAlertPoliciesClient) WorkspaceManagedSqlServerSecurityAlertPolicyListComplete(ctx context.Context, id WorkspaceId) (WorkspaceManagedSqlServerSecurityAlertPolicyListCompleteResult, error) { + return c.WorkspaceManagedSqlServerSecurityAlertPolicyListCompleteMatchingPredicate(ctx, id, ServerSecurityAlertPolicyOperationPredicate{}) +} + +// WorkspaceManagedSqlServerSecurityAlertPolicyListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c WorkspaceManagedSqlServerSecurityAlertPoliciesClient) WorkspaceManagedSqlServerSecurityAlertPolicyListCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, predicate ServerSecurityAlertPolicyOperationPredicate) (result WorkspaceManagedSqlServerSecurityAlertPolicyListCompleteResult, err error) { + items := make([]ServerSecurityAlertPolicy, 0) + + resp, err := c.WorkspaceManagedSqlServerSecurityAlertPolicyList(ctx, id) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = WorkspaceManagedSqlServerSecurityAlertPolicyListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/synapse/2021-06-01/workspacemanagedsqlserversecurityalertpolicies/model_serversecurityalertpolicy.go b/resource-manager/synapse/2021-06-01/workspacemanagedsqlserversecurityalertpolicies/model_serversecurityalertpolicy.go new file mode 100644 index 00000000000..b6dbf2cb1f4 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/workspacemanagedsqlserversecurityalertpolicies/model_serversecurityalertpolicy.go @@ -0,0 +1,11 @@ +package workspacemanagedsqlserversecurityalertpolicies + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ServerSecurityAlertPolicy struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *ServerSecurityAlertPolicyProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/synapse/2021-06-01/workspacemanagedsqlserversecurityalertpolicies/model_serversecurityalertpolicyproperties.go b/resource-manager/synapse/2021-06-01/workspacemanagedsqlserversecurityalertpolicies/model_serversecurityalertpolicyproperties.go new file mode 100644 index 00000000000..7d303a462ca --- /dev/null +++ b/resource-manager/synapse/2021-06-01/workspacemanagedsqlserversecurityalertpolicies/model_serversecurityalertpolicyproperties.go @@ -0,0 +1,33 @@ +package workspacemanagedsqlserversecurityalertpolicies + +import ( + "time" + + "github.com/hashicorp/go-azure-helpers/lang/dates" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ServerSecurityAlertPolicyProperties struct { + CreationTime *string `json:"creationTime,omitempty"` + DisabledAlerts *[]string `json:"disabledAlerts,omitempty"` + EmailAccountAdmins *bool `json:"emailAccountAdmins,omitempty"` + EmailAddresses *[]string `json:"emailAddresses,omitempty"` + RetentionDays *int64 `json:"retentionDays,omitempty"` + State SecurityAlertPolicyState `json:"state"` + StorageAccountAccessKey *string `json:"storageAccountAccessKey,omitempty"` + StorageEndpoint *string `json:"storageEndpoint,omitempty"` +} + +func (o *ServerSecurityAlertPolicyProperties) GetCreationTimeAsTime() (*time.Time, error) { + if o.CreationTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.CreationTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *ServerSecurityAlertPolicyProperties) SetCreationTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.CreationTime = &formatted +} diff --git a/resource-manager/synapse/2021-06-01/workspacemanagedsqlserversecurityalertpolicies/predicates.go b/resource-manager/synapse/2021-06-01/workspacemanagedsqlserversecurityalertpolicies/predicates.go new file mode 100644 index 00000000000..5c9ac104392 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/workspacemanagedsqlserversecurityalertpolicies/predicates.go @@ -0,0 +1,27 @@ +package workspacemanagedsqlserversecurityalertpolicies + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ServerSecurityAlertPolicyOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p ServerSecurityAlertPolicyOperationPredicate) Matches(input ServerSecurityAlertPolicy) bool { + + if p.Id != nil && (input.Id == nil || *p.Id != *input.Id) { + return false + } + + if p.Name != nil && (input.Name == nil || *p.Name != *input.Name) { + return false + } + + if p.Type != nil && (input.Type == nil || *p.Type != *input.Type) { + return false + } + + return true +} diff --git a/resource-manager/synapse/2021-06-01/workspacemanagedsqlserversecurityalertpolicies/version.go b/resource-manager/synapse/2021-06-01/workspacemanagedsqlserversecurityalertpolicies/version.go new file mode 100644 index 00000000000..d2e943002a7 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/workspacemanagedsqlserversecurityalertpolicies/version.go @@ -0,0 +1,12 @@ +package workspacemanagedsqlserversecurityalertpolicies + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2021-06-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/workspacemanagedsqlserversecurityalertpolicies/%s", defaultApiVersion) +} diff --git a/resource-manager/synapse/2021-06-01/workspacemanagedsqlserverserverencryptionprotector/README.md b/resource-manager/synapse/2021-06-01/workspacemanagedsqlserverserverencryptionprotector/README.md new file mode 100644 index 00000000000..bfc0d186db1 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/workspacemanagedsqlserverserverencryptionprotector/README.md @@ -0,0 +1,82 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/synapse/2021-06-01/workspacemanagedsqlserverserverencryptionprotector` Documentation + +The `workspacemanagedsqlserverserverencryptionprotector` SDK allows for interaction with the Azure Resource Manager Service `synapse` (API Version `2021-06-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/synapse/2021-06-01/workspacemanagedsqlserverserverencryptionprotector" +``` + + +### Client Initialization + +```go +client := workspacemanagedsqlserverserverencryptionprotector.NewWorkspaceManagedSqlServerServerEncryptionProtectorClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `WorkspaceManagedSqlServerServerEncryptionProtectorClient.WorkspaceManagedSqlServerEncryptionProtectorCreateOrUpdate` + +```go +ctx := context.TODO() +id := workspacemanagedsqlserverserverencryptionprotector.NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue") + +payload := workspacemanagedsqlserverserverencryptionprotector.EncryptionProtector{ + // ... +} + + +if err := client.WorkspaceManagedSqlServerEncryptionProtectorCreateOrUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `WorkspaceManagedSqlServerServerEncryptionProtectorClient.WorkspaceManagedSqlServerEncryptionProtectorGet` + +```go +ctx := context.TODO() +id := workspacemanagedsqlserverserverencryptionprotector.NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue") + +read, err := client.WorkspaceManagedSqlServerEncryptionProtectorGet(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `WorkspaceManagedSqlServerServerEncryptionProtectorClient.WorkspaceManagedSqlServerEncryptionProtectorList` + +```go +ctx := context.TODO() +id := workspacemanagedsqlserverserverencryptionprotector.NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue") + +// alternatively `client.WorkspaceManagedSqlServerEncryptionProtectorList(ctx, id)` can be used to do batched pagination +items, err := client.WorkspaceManagedSqlServerEncryptionProtectorListComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `WorkspaceManagedSqlServerServerEncryptionProtectorClient.WorkspaceManagedSqlServerEncryptionProtectorRevalidate` + +```go +ctx := context.TODO() +id := workspacemanagedsqlserverserverencryptionprotector.NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue") + +if err := client.WorkspaceManagedSqlServerEncryptionProtectorRevalidateThenPoll(ctx, id); err != nil { + // handle the error +} +``` diff --git a/resource-manager/synapse/2021-06-01/workspacemanagedsqlserverserverencryptionprotector/client.go b/resource-manager/synapse/2021-06-01/workspacemanagedsqlserverserverencryptionprotector/client.go new file mode 100644 index 00000000000..308160de19b --- /dev/null +++ b/resource-manager/synapse/2021-06-01/workspacemanagedsqlserverserverencryptionprotector/client.go @@ -0,0 +1,26 @@ +package workspacemanagedsqlserverserverencryptionprotector + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type WorkspaceManagedSqlServerServerEncryptionProtectorClient struct { + Client *resourcemanager.Client +} + +func NewWorkspaceManagedSqlServerServerEncryptionProtectorClientWithBaseURI(sdkApi sdkEnv.Api) (*WorkspaceManagedSqlServerServerEncryptionProtectorClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "workspacemanagedsqlserverserverencryptionprotector", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating WorkspaceManagedSqlServerServerEncryptionProtectorClient: %+v", err) + } + + return &WorkspaceManagedSqlServerServerEncryptionProtectorClient{ + Client: client, + }, nil +} diff --git a/resource-manager/synapse/2021-06-01/workspacemanagedsqlserverserverencryptionprotector/constants.go b/resource-manager/synapse/2021-06-01/workspacemanagedsqlserverserverencryptionprotector/constants.go new file mode 100644 index 00000000000..4006cc7e3e8 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/workspacemanagedsqlserverserverencryptionprotector/constants.go @@ -0,0 +1,51 @@ +package workspacemanagedsqlserverserverencryptionprotector + +import ( + "encoding/json" + "fmt" + "strings" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ServerKeyType string + +const ( + ServerKeyTypeAzureKeyVault ServerKeyType = "AzureKeyVault" + ServerKeyTypeServiceManaged ServerKeyType = "ServiceManaged" +) + +func PossibleValuesForServerKeyType() []string { + return []string{ + string(ServerKeyTypeAzureKeyVault), + string(ServerKeyTypeServiceManaged), + } +} + +func (s *ServerKeyType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseServerKeyType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseServerKeyType(input string) (*ServerKeyType, error) { + vals := map[string]ServerKeyType{ + "azurekeyvault": ServerKeyTypeAzureKeyVault, + "servicemanaged": ServerKeyTypeServiceManaged, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ServerKeyType(input) + return &out, nil +} diff --git a/resource-manager/synapse/2021-06-01/workspacemanagedsqlserverserverencryptionprotector/id_workspace.go b/resource-manager/synapse/2021-06-01/workspacemanagedsqlserverserverencryptionprotector/id_workspace.go new file mode 100644 index 00000000000..4fae6e6ce40 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/workspacemanagedsqlserverserverencryptionprotector/id_workspace.go @@ -0,0 +1,125 @@ +package workspacemanagedsqlserverserverencryptionprotector + +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 = &WorkspaceId{} + +// WorkspaceId is a struct representing the Resource ID for a Workspace +type WorkspaceId struct { + SubscriptionId string + ResourceGroupName string + WorkspaceName string +} + +// NewWorkspaceID returns a new WorkspaceId struct +func NewWorkspaceID(subscriptionId string, resourceGroupName string, workspaceName string) WorkspaceId { + return WorkspaceId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + WorkspaceName: workspaceName, + } +} + +// ParseWorkspaceID parses 'input' into a WorkspaceId +func ParseWorkspaceID(input string) (*WorkspaceId, error) { + parser := resourceids.NewParserFromResourceIdType(&WorkspaceId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := WorkspaceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseWorkspaceIDInsensitively parses 'input' case-insensitively into a WorkspaceId +// note: this method should only be used for API response data and not user input +func ParseWorkspaceIDInsensitively(input string) (*WorkspaceId, error) { + parser := resourceids.NewParserFromResourceIdType(&WorkspaceId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := WorkspaceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *WorkspaceId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.WorkspaceName, ok = input.Parsed["workspaceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "workspaceName", input) + } + + return nil +} + +// ValidateWorkspaceID checks that 'input' can be parsed as a Workspace ID +func ValidateWorkspaceID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseWorkspaceID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Workspace ID +func (id WorkspaceId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Synapse/workspaces/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.WorkspaceName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Workspace ID +func (id WorkspaceId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftSynapse", "Microsoft.Synapse", "Microsoft.Synapse"), + resourceids.StaticSegment("staticWorkspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceName", "workspaceValue"), + } +} + +// String returns a human-readable description of this Workspace ID +func (id WorkspaceId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Workspace Name: %q", id.WorkspaceName), + } + return fmt.Sprintf("Workspace (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/synapse/2021-06-01/workspacemanagedsqlserverserverencryptionprotector/id_workspace_test.go b/resource-manager/synapse/2021-06-01/workspacemanagedsqlserverserverencryptionprotector/id_workspace_test.go new file mode 100644 index 00000000000..1b88409b454 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/workspacemanagedsqlserverserverencryptionprotector/id_workspace_test.go @@ -0,0 +1,282 @@ +package workspacemanagedsqlserverserverencryptionprotector + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &WorkspaceId{} + +func TestNewWorkspaceID(t *testing.T) { + id := NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.WorkspaceName != "workspaceValue" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceName'", id.WorkspaceName, "workspaceValue") + } +} + +func TestFormatWorkspaceID(t *testing.T) { + actual := NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseWorkspaceID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkspaceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue", + Expected: &WorkspaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkspaceID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + } +} + +func TestParseWorkspaceIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkspaceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue", + Expected: &WorkspaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE", + Expected: &WorkspaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + WorkspaceName: "wOrKsPaCeVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkspaceIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + } +} + +func TestSegmentsForWorkspaceId(t *testing.T) { + segments := WorkspaceId{}.Segments() + if len(segments) == 0 { + t.Fatalf("WorkspaceId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/synapse/2021-06-01/workspacemanagedsqlserverserverencryptionprotector/method_workspacemanagedsqlserverencryptionprotectorcreateorupdate.go b/resource-manager/synapse/2021-06-01/workspacemanagedsqlserverserverencryptionprotector/method_workspacemanagedsqlserverencryptionprotectorcreateorupdate.go new file mode 100644 index 00000000000..17bfcc9d3fe --- /dev/null +++ b/resource-manager/synapse/2021-06-01/workspacemanagedsqlserverserverencryptionprotector/method_workspacemanagedsqlserverencryptionprotectorcreateorupdate.go @@ -0,0 +1,75 @@ +package workspacemanagedsqlserverserverencryptionprotector + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type WorkspaceManagedSqlServerEncryptionProtectorCreateOrUpdateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *EncryptionProtector +} + +// WorkspaceManagedSqlServerEncryptionProtectorCreateOrUpdate ... +func (c WorkspaceManagedSqlServerServerEncryptionProtectorClient) WorkspaceManagedSqlServerEncryptionProtectorCreateOrUpdate(ctx context.Context, id WorkspaceId, input EncryptionProtector) (result WorkspaceManagedSqlServerEncryptionProtectorCreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: fmt.Sprintf("%s/encryptionProtector/current", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// WorkspaceManagedSqlServerEncryptionProtectorCreateOrUpdateThenPoll performs WorkspaceManagedSqlServerEncryptionProtectorCreateOrUpdate then polls until it's completed +func (c WorkspaceManagedSqlServerServerEncryptionProtectorClient) WorkspaceManagedSqlServerEncryptionProtectorCreateOrUpdateThenPoll(ctx context.Context, id WorkspaceId, input EncryptionProtector) error { + result, err := c.WorkspaceManagedSqlServerEncryptionProtectorCreateOrUpdate(ctx, id, input) + if err != nil { + return fmt.Errorf("performing WorkspaceManagedSqlServerEncryptionProtectorCreateOrUpdate: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after WorkspaceManagedSqlServerEncryptionProtectorCreateOrUpdate: %+v", err) + } + + return nil +} diff --git a/resource-manager/synapse/2021-06-01/workspacemanagedsqlserverserverencryptionprotector/method_workspacemanagedsqlserverencryptionprotectorget.go b/resource-manager/synapse/2021-06-01/workspacemanagedsqlserverserverencryptionprotector/method_workspacemanagedsqlserverencryptionprotectorget.go new file mode 100644 index 00000000000..04ea9026fb3 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/workspacemanagedsqlserverserverencryptionprotector/method_workspacemanagedsqlserverencryptionprotectorget.go @@ -0,0 +1,52 @@ +package workspacemanagedsqlserverserverencryptionprotector + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type WorkspaceManagedSqlServerEncryptionProtectorGetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *EncryptionProtector +} + +// WorkspaceManagedSqlServerEncryptionProtectorGet ... +func (c WorkspaceManagedSqlServerServerEncryptionProtectorClient) WorkspaceManagedSqlServerEncryptionProtectorGet(ctx context.Context, id WorkspaceId) (result WorkspaceManagedSqlServerEncryptionProtectorGetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/encryptionProtector/current", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/synapse/2021-06-01/workspacemanagedsqlserverserverencryptionprotector/method_workspacemanagedsqlserverencryptionprotectorlist.go b/resource-manager/synapse/2021-06-01/workspacemanagedsqlserverserverencryptionprotector/method_workspacemanagedsqlserverencryptionprotectorlist.go new file mode 100644 index 00000000000..4d9138ac681 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/workspacemanagedsqlserverserverencryptionprotector/method_workspacemanagedsqlserverencryptionprotectorlist.go @@ -0,0 +1,91 @@ +package workspacemanagedsqlserverserverencryptionprotector + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type WorkspaceManagedSqlServerEncryptionProtectorListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]EncryptionProtector +} + +type WorkspaceManagedSqlServerEncryptionProtectorListCompleteResult struct { + LatestHttpResponse *http.Response + Items []EncryptionProtector +} + +// WorkspaceManagedSqlServerEncryptionProtectorList ... +func (c WorkspaceManagedSqlServerServerEncryptionProtectorClient) WorkspaceManagedSqlServerEncryptionProtectorList(ctx context.Context, id WorkspaceId) (result WorkspaceManagedSqlServerEncryptionProtectorListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/encryptionProtector", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]EncryptionProtector `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// WorkspaceManagedSqlServerEncryptionProtectorListComplete retrieves all the results into a single object +func (c WorkspaceManagedSqlServerServerEncryptionProtectorClient) WorkspaceManagedSqlServerEncryptionProtectorListComplete(ctx context.Context, id WorkspaceId) (WorkspaceManagedSqlServerEncryptionProtectorListCompleteResult, error) { + return c.WorkspaceManagedSqlServerEncryptionProtectorListCompleteMatchingPredicate(ctx, id, EncryptionProtectorOperationPredicate{}) +} + +// WorkspaceManagedSqlServerEncryptionProtectorListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c WorkspaceManagedSqlServerServerEncryptionProtectorClient) WorkspaceManagedSqlServerEncryptionProtectorListCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, predicate EncryptionProtectorOperationPredicate) (result WorkspaceManagedSqlServerEncryptionProtectorListCompleteResult, err error) { + items := make([]EncryptionProtector, 0) + + resp, err := c.WorkspaceManagedSqlServerEncryptionProtectorList(ctx, id) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = WorkspaceManagedSqlServerEncryptionProtectorListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/synapse/2021-06-01/workspacemanagedsqlserverserverencryptionprotector/method_workspacemanagedsqlserverencryptionprotectorrevalidate.go b/resource-manager/synapse/2021-06-01/workspacemanagedsqlserverserverencryptionprotector/method_workspacemanagedsqlserverencryptionprotectorrevalidate.go new file mode 100644 index 00000000000..8bcdfe3d568 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/workspacemanagedsqlserverserverencryptionprotector/method_workspacemanagedsqlserverencryptionprotectorrevalidate.go @@ -0,0 +1,70 @@ +package workspacemanagedsqlserverserverencryptionprotector + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type WorkspaceManagedSqlServerEncryptionProtectorRevalidateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// WorkspaceManagedSqlServerEncryptionProtectorRevalidate ... +func (c WorkspaceManagedSqlServerServerEncryptionProtectorClient) WorkspaceManagedSqlServerEncryptionProtectorRevalidate(ctx context.Context, id WorkspaceId) (result WorkspaceManagedSqlServerEncryptionProtectorRevalidateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/encryptionProtector/current/revalidate", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// WorkspaceManagedSqlServerEncryptionProtectorRevalidateThenPoll performs WorkspaceManagedSqlServerEncryptionProtectorRevalidate then polls until it's completed +func (c WorkspaceManagedSqlServerServerEncryptionProtectorClient) WorkspaceManagedSqlServerEncryptionProtectorRevalidateThenPoll(ctx context.Context, id WorkspaceId) error { + result, err := c.WorkspaceManagedSqlServerEncryptionProtectorRevalidate(ctx, id) + if err != nil { + return fmt.Errorf("performing WorkspaceManagedSqlServerEncryptionProtectorRevalidate: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after WorkspaceManagedSqlServerEncryptionProtectorRevalidate: %+v", err) + } + + return nil +} diff --git a/resource-manager/synapse/2021-06-01/workspacemanagedsqlserverserverencryptionprotector/model_encryptionprotector.go b/resource-manager/synapse/2021-06-01/workspacemanagedsqlserverserverencryptionprotector/model_encryptionprotector.go new file mode 100644 index 00000000000..4e244cc8727 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/workspacemanagedsqlserverserverencryptionprotector/model_encryptionprotector.go @@ -0,0 +1,13 @@ +package workspacemanagedsqlserverserverencryptionprotector + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type EncryptionProtector struct { + Id *string `json:"id,omitempty"` + Kind *string `json:"kind,omitempty"` + Location *string `json:"location,omitempty"` + Name *string `json:"name,omitempty"` + Properties *EncryptionProtectorProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/synapse/2021-06-01/workspacemanagedsqlserverserverencryptionprotector/model_encryptionprotectorproperties.go b/resource-manager/synapse/2021-06-01/workspacemanagedsqlserverserverencryptionprotector/model_encryptionprotectorproperties.go new file mode 100644 index 00000000000..d91be3d0ca5 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/workspacemanagedsqlserverserverencryptionprotector/model_encryptionprotectorproperties.go @@ -0,0 +1,12 @@ +package workspacemanagedsqlserverserverencryptionprotector + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type EncryptionProtectorProperties struct { + ServerKeyName *string `json:"serverKeyName,omitempty"` + ServerKeyType ServerKeyType `json:"serverKeyType"` + Subregion *string `json:"subregion,omitempty"` + Thumbprint *string `json:"thumbprint,omitempty"` + Uri *string `json:"uri,omitempty"` +} diff --git a/resource-manager/synapse/2021-06-01/workspacemanagedsqlserverserverencryptionprotector/predicates.go b/resource-manager/synapse/2021-06-01/workspacemanagedsqlserverserverencryptionprotector/predicates.go new file mode 100644 index 00000000000..05bab38ec96 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/workspacemanagedsqlserverserverencryptionprotector/predicates.go @@ -0,0 +1,37 @@ +package workspacemanagedsqlserverserverencryptionprotector + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type EncryptionProtectorOperationPredicate struct { + Id *string + Kind *string + Location *string + Name *string + Type *string +} + +func (p EncryptionProtectorOperationPredicate) Matches(input EncryptionProtector) bool { + + if p.Id != nil && (input.Id == nil || *p.Id != *input.Id) { + return false + } + + if p.Kind != nil && (input.Kind == nil || *p.Kind != *input.Kind) { + return false + } + + if p.Location != nil && (input.Location == nil || *p.Location != *input.Location) { + return false + } + + if p.Name != nil && (input.Name == nil || *p.Name != *input.Name) { + return false + } + + if p.Type != nil && (input.Type == nil || *p.Type != *input.Type) { + return false + } + + return true +} diff --git a/resource-manager/synapse/2021-06-01/workspacemanagedsqlserverserverencryptionprotector/version.go b/resource-manager/synapse/2021-06-01/workspacemanagedsqlserverserverencryptionprotector/version.go new file mode 100644 index 00000000000..b7bb2cfb085 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/workspacemanagedsqlserverserverencryptionprotector/version.go @@ -0,0 +1,12 @@ +package workspacemanagedsqlserverserverencryptionprotector + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2021-06-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/workspacemanagedsqlserverserverencryptionprotector/%s", defaultApiVersion) +} diff --git a/resource-manager/synapse/2021-06-01/workspacemanagedsqlserverservervulnerabilityassessments/README.md b/resource-manager/synapse/2021-06-01/workspacemanagedsqlserverservervulnerabilityassessments/README.md new file mode 100644 index 00000000000..6552d2eed70 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/workspacemanagedsqlserverservervulnerabilityassessments/README.md @@ -0,0 +1,90 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/synapse/2021-06-01/workspacemanagedsqlserverservervulnerabilityassessments` Documentation + +The `workspacemanagedsqlserverservervulnerabilityassessments` SDK allows for interaction with the Azure Resource Manager Service `synapse` (API Version `2021-06-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/synapse/2021-06-01/workspacemanagedsqlserverservervulnerabilityassessments" +``` + + +### Client Initialization + +```go +client := workspacemanagedsqlserverservervulnerabilityassessments.NewWorkspaceManagedSqlServerServerVulnerabilityAssessmentsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `WorkspaceManagedSqlServerServerVulnerabilityAssessmentsClient.WorkspaceManagedSqlServerVulnerabilityAssessmentsCreateOrUpdate` + +```go +ctx := context.TODO() +id := workspacemanagedsqlserverservervulnerabilityassessments.NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue") + +payload := workspacemanagedsqlserverservervulnerabilityassessments.ServerVulnerabilityAssessment{ + // ... +} + + +read, err := client.WorkspaceManagedSqlServerVulnerabilityAssessmentsCreateOrUpdate(ctx, id, payload) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `WorkspaceManagedSqlServerServerVulnerabilityAssessmentsClient.WorkspaceManagedSqlServerVulnerabilityAssessmentsDelete` + +```go +ctx := context.TODO() +id := workspacemanagedsqlserverservervulnerabilityassessments.NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue") + +read, err := client.WorkspaceManagedSqlServerVulnerabilityAssessmentsDelete(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `WorkspaceManagedSqlServerServerVulnerabilityAssessmentsClient.WorkspaceManagedSqlServerVulnerabilityAssessmentsGet` + +```go +ctx := context.TODO() +id := workspacemanagedsqlserverservervulnerabilityassessments.NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue") + +read, err := client.WorkspaceManagedSqlServerVulnerabilityAssessmentsGet(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `WorkspaceManagedSqlServerServerVulnerabilityAssessmentsClient.WorkspaceManagedSqlServerVulnerabilityAssessmentsList` + +```go +ctx := context.TODO() +id := workspacemanagedsqlserverservervulnerabilityassessments.NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue") + +// alternatively `client.WorkspaceManagedSqlServerVulnerabilityAssessmentsList(ctx, id)` can be used to do batched pagination +items, err := client.WorkspaceManagedSqlServerVulnerabilityAssessmentsListComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/synapse/2021-06-01/workspacemanagedsqlserverservervulnerabilityassessments/client.go b/resource-manager/synapse/2021-06-01/workspacemanagedsqlserverservervulnerabilityassessments/client.go new file mode 100644 index 00000000000..79b8e8b285a --- /dev/null +++ b/resource-manager/synapse/2021-06-01/workspacemanagedsqlserverservervulnerabilityassessments/client.go @@ -0,0 +1,26 @@ +package workspacemanagedsqlserverservervulnerabilityassessments + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type WorkspaceManagedSqlServerServerVulnerabilityAssessmentsClient struct { + Client *resourcemanager.Client +} + +func NewWorkspaceManagedSqlServerServerVulnerabilityAssessmentsClientWithBaseURI(sdkApi sdkEnv.Api) (*WorkspaceManagedSqlServerServerVulnerabilityAssessmentsClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "workspacemanagedsqlserverservervulnerabilityassessments", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating WorkspaceManagedSqlServerServerVulnerabilityAssessmentsClient: %+v", err) + } + + return &WorkspaceManagedSqlServerServerVulnerabilityAssessmentsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/synapse/2021-06-01/workspacemanagedsqlserverservervulnerabilityassessments/id_workspace.go b/resource-manager/synapse/2021-06-01/workspacemanagedsqlserverservervulnerabilityassessments/id_workspace.go new file mode 100644 index 00000000000..f8ca72cddb9 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/workspacemanagedsqlserverservervulnerabilityassessments/id_workspace.go @@ -0,0 +1,125 @@ +package workspacemanagedsqlserverservervulnerabilityassessments + +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 = &WorkspaceId{} + +// WorkspaceId is a struct representing the Resource ID for a Workspace +type WorkspaceId struct { + SubscriptionId string + ResourceGroupName string + WorkspaceName string +} + +// NewWorkspaceID returns a new WorkspaceId struct +func NewWorkspaceID(subscriptionId string, resourceGroupName string, workspaceName string) WorkspaceId { + return WorkspaceId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + WorkspaceName: workspaceName, + } +} + +// ParseWorkspaceID parses 'input' into a WorkspaceId +func ParseWorkspaceID(input string) (*WorkspaceId, error) { + parser := resourceids.NewParserFromResourceIdType(&WorkspaceId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := WorkspaceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseWorkspaceIDInsensitively parses 'input' case-insensitively into a WorkspaceId +// note: this method should only be used for API response data and not user input +func ParseWorkspaceIDInsensitively(input string) (*WorkspaceId, error) { + parser := resourceids.NewParserFromResourceIdType(&WorkspaceId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := WorkspaceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *WorkspaceId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.WorkspaceName, ok = input.Parsed["workspaceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "workspaceName", input) + } + + return nil +} + +// ValidateWorkspaceID checks that 'input' can be parsed as a Workspace ID +func ValidateWorkspaceID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseWorkspaceID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Workspace ID +func (id WorkspaceId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Synapse/workspaces/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.WorkspaceName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Workspace ID +func (id WorkspaceId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftSynapse", "Microsoft.Synapse", "Microsoft.Synapse"), + resourceids.StaticSegment("staticWorkspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceName", "workspaceValue"), + } +} + +// String returns a human-readable description of this Workspace ID +func (id WorkspaceId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Workspace Name: %q", id.WorkspaceName), + } + return fmt.Sprintf("Workspace (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/synapse/2021-06-01/workspacemanagedsqlserverservervulnerabilityassessments/id_workspace_test.go b/resource-manager/synapse/2021-06-01/workspacemanagedsqlserverservervulnerabilityassessments/id_workspace_test.go new file mode 100644 index 00000000000..ae163964ff3 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/workspacemanagedsqlserverservervulnerabilityassessments/id_workspace_test.go @@ -0,0 +1,282 @@ +package workspacemanagedsqlserverservervulnerabilityassessments + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &WorkspaceId{} + +func TestNewWorkspaceID(t *testing.T) { + id := NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.WorkspaceName != "workspaceValue" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceName'", id.WorkspaceName, "workspaceValue") + } +} + +func TestFormatWorkspaceID(t *testing.T) { + actual := NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseWorkspaceID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkspaceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue", + Expected: &WorkspaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkspaceID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + } +} + +func TestParseWorkspaceIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkspaceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue", + Expected: &WorkspaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE", + Expected: &WorkspaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + WorkspaceName: "wOrKsPaCeVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkspaceIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + } +} + +func TestSegmentsForWorkspaceId(t *testing.T) { + segments := WorkspaceId{}.Segments() + if len(segments) == 0 { + t.Fatalf("WorkspaceId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/synapse/2021-06-01/workspacemanagedsqlserverservervulnerabilityassessments/method_workspacemanagedsqlservervulnerabilityassessmentscreateorupdate.go b/resource-manager/synapse/2021-06-01/workspacemanagedsqlserverservervulnerabilityassessments/method_workspacemanagedsqlservervulnerabilityassessmentscreateorupdate.go new file mode 100644 index 00000000000..7d5c149dd82 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/workspacemanagedsqlserverservervulnerabilityassessments/method_workspacemanagedsqlservervulnerabilityassessmentscreateorupdate.go @@ -0,0 +1,57 @@ +package workspacemanagedsqlserverservervulnerabilityassessments + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type WorkspaceManagedSqlServerVulnerabilityAssessmentsCreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *ServerVulnerabilityAssessment +} + +// WorkspaceManagedSqlServerVulnerabilityAssessmentsCreateOrUpdate ... +func (c WorkspaceManagedSqlServerServerVulnerabilityAssessmentsClient) WorkspaceManagedSqlServerVulnerabilityAssessmentsCreateOrUpdate(ctx context.Context, id WorkspaceId, input ServerVulnerabilityAssessment) (result WorkspaceManagedSqlServerVulnerabilityAssessmentsCreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: fmt.Sprintf("%s/vulnerabilityAssessments/default", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/synapse/2021-06-01/workspacemanagedsqlserverservervulnerabilityassessments/method_workspacemanagedsqlservervulnerabilityassessmentsdelete.go b/resource-manager/synapse/2021-06-01/workspacemanagedsqlserverservervulnerabilityassessments/method_workspacemanagedsqlservervulnerabilityassessmentsdelete.go new file mode 100644 index 00000000000..0064d30020d --- /dev/null +++ b/resource-manager/synapse/2021-06-01/workspacemanagedsqlserverservervulnerabilityassessments/method_workspacemanagedsqlservervulnerabilityassessmentsdelete.go @@ -0,0 +1,48 @@ +package workspacemanagedsqlserverservervulnerabilityassessments + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type WorkspaceManagedSqlServerVulnerabilityAssessmentsDeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// WorkspaceManagedSqlServerVulnerabilityAssessmentsDelete ... +func (c WorkspaceManagedSqlServerServerVulnerabilityAssessmentsClient) WorkspaceManagedSqlServerVulnerabilityAssessmentsDelete(ctx context.Context, id WorkspaceId) (result WorkspaceManagedSqlServerVulnerabilityAssessmentsDeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: fmt.Sprintf("%s/vulnerabilityAssessments/default", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/synapse/2021-06-01/workspacemanagedsqlserverservervulnerabilityassessments/method_workspacemanagedsqlservervulnerabilityassessmentsget.go b/resource-manager/synapse/2021-06-01/workspacemanagedsqlserverservervulnerabilityassessments/method_workspacemanagedsqlservervulnerabilityassessmentsget.go new file mode 100644 index 00000000000..384f5405b2d --- /dev/null +++ b/resource-manager/synapse/2021-06-01/workspacemanagedsqlserverservervulnerabilityassessments/method_workspacemanagedsqlservervulnerabilityassessmentsget.go @@ -0,0 +1,52 @@ +package workspacemanagedsqlserverservervulnerabilityassessments + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type WorkspaceManagedSqlServerVulnerabilityAssessmentsGetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *ServerVulnerabilityAssessment +} + +// WorkspaceManagedSqlServerVulnerabilityAssessmentsGet ... +func (c WorkspaceManagedSqlServerServerVulnerabilityAssessmentsClient) WorkspaceManagedSqlServerVulnerabilityAssessmentsGet(ctx context.Context, id WorkspaceId) (result WorkspaceManagedSqlServerVulnerabilityAssessmentsGetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/vulnerabilityAssessments/default", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/synapse/2021-06-01/workspacemanagedsqlserverservervulnerabilityassessments/method_workspacemanagedsqlservervulnerabilityassessmentslist.go b/resource-manager/synapse/2021-06-01/workspacemanagedsqlserverservervulnerabilityassessments/method_workspacemanagedsqlservervulnerabilityassessmentslist.go new file mode 100644 index 00000000000..a8b50d34f0a --- /dev/null +++ b/resource-manager/synapse/2021-06-01/workspacemanagedsqlserverservervulnerabilityassessments/method_workspacemanagedsqlservervulnerabilityassessmentslist.go @@ -0,0 +1,91 @@ +package workspacemanagedsqlserverservervulnerabilityassessments + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type WorkspaceManagedSqlServerVulnerabilityAssessmentsListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]ServerVulnerabilityAssessment +} + +type WorkspaceManagedSqlServerVulnerabilityAssessmentsListCompleteResult struct { + LatestHttpResponse *http.Response + Items []ServerVulnerabilityAssessment +} + +// WorkspaceManagedSqlServerVulnerabilityAssessmentsList ... +func (c WorkspaceManagedSqlServerServerVulnerabilityAssessmentsClient) WorkspaceManagedSqlServerVulnerabilityAssessmentsList(ctx context.Context, id WorkspaceId) (result WorkspaceManagedSqlServerVulnerabilityAssessmentsListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/vulnerabilityAssessments", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]ServerVulnerabilityAssessment `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// WorkspaceManagedSqlServerVulnerabilityAssessmentsListComplete retrieves all the results into a single object +func (c WorkspaceManagedSqlServerServerVulnerabilityAssessmentsClient) WorkspaceManagedSqlServerVulnerabilityAssessmentsListComplete(ctx context.Context, id WorkspaceId) (WorkspaceManagedSqlServerVulnerabilityAssessmentsListCompleteResult, error) { + return c.WorkspaceManagedSqlServerVulnerabilityAssessmentsListCompleteMatchingPredicate(ctx, id, ServerVulnerabilityAssessmentOperationPredicate{}) +} + +// WorkspaceManagedSqlServerVulnerabilityAssessmentsListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c WorkspaceManagedSqlServerServerVulnerabilityAssessmentsClient) WorkspaceManagedSqlServerVulnerabilityAssessmentsListCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, predicate ServerVulnerabilityAssessmentOperationPredicate) (result WorkspaceManagedSqlServerVulnerabilityAssessmentsListCompleteResult, err error) { + items := make([]ServerVulnerabilityAssessment, 0) + + resp, err := c.WorkspaceManagedSqlServerVulnerabilityAssessmentsList(ctx, id) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = WorkspaceManagedSqlServerVulnerabilityAssessmentsListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/synapse/2021-06-01/workspacemanagedsqlserverservervulnerabilityassessments/model_servervulnerabilityassessment.go b/resource-manager/synapse/2021-06-01/workspacemanagedsqlserverservervulnerabilityassessments/model_servervulnerabilityassessment.go new file mode 100644 index 00000000000..a9599a1b795 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/workspacemanagedsqlserverservervulnerabilityassessments/model_servervulnerabilityassessment.go @@ -0,0 +1,11 @@ +package workspacemanagedsqlserverservervulnerabilityassessments + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ServerVulnerabilityAssessment struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *ServerVulnerabilityAssessmentProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/synapse/2021-06-01/workspacemanagedsqlserverservervulnerabilityassessments/model_servervulnerabilityassessmentproperties.go b/resource-manager/synapse/2021-06-01/workspacemanagedsqlserverservervulnerabilityassessments/model_servervulnerabilityassessmentproperties.go new file mode 100644 index 00000000000..ba35d94e747 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/workspacemanagedsqlserverservervulnerabilityassessments/model_servervulnerabilityassessmentproperties.go @@ -0,0 +1,11 @@ +package workspacemanagedsqlserverservervulnerabilityassessments + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ServerVulnerabilityAssessmentProperties struct { + RecurringScans *VulnerabilityAssessmentRecurringScansProperties `json:"recurringScans,omitempty"` + StorageAccountAccessKey *string `json:"storageAccountAccessKey,omitempty"` + StorageContainerPath string `json:"storageContainerPath"` + StorageContainerSasKey *string `json:"storageContainerSasKey,omitempty"` +} diff --git a/resource-manager/synapse/2021-06-01/workspacemanagedsqlserverservervulnerabilityassessments/model_vulnerabilityassessmentrecurringscansproperties.go b/resource-manager/synapse/2021-06-01/workspacemanagedsqlserverservervulnerabilityassessments/model_vulnerabilityassessmentrecurringscansproperties.go new file mode 100644 index 00000000000..0dfc8c519f0 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/workspacemanagedsqlserverservervulnerabilityassessments/model_vulnerabilityassessmentrecurringscansproperties.go @@ -0,0 +1,10 @@ +package workspacemanagedsqlserverservervulnerabilityassessments + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type VulnerabilityAssessmentRecurringScansProperties struct { + EmailSubscriptionAdmins *bool `json:"emailSubscriptionAdmins,omitempty"` + Emails *[]string `json:"emails,omitempty"` + IsEnabled *bool `json:"isEnabled,omitempty"` +} diff --git a/resource-manager/synapse/2021-06-01/workspacemanagedsqlserverservervulnerabilityassessments/predicates.go b/resource-manager/synapse/2021-06-01/workspacemanagedsqlserverservervulnerabilityassessments/predicates.go new file mode 100644 index 00000000000..12c1c6f882d --- /dev/null +++ b/resource-manager/synapse/2021-06-01/workspacemanagedsqlserverservervulnerabilityassessments/predicates.go @@ -0,0 +1,27 @@ +package workspacemanagedsqlserverservervulnerabilityassessments + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ServerVulnerabilityAssessmentOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p ServerVulnerabilityAssessmentOperationPredicate) Matches(input ServerVulnerabilityAssessment) bool { + + if p.Id != nil && (input.Id == nil || *p.Id != *input.Id) { + return false + } + + if p.Name != nil && (input.Name == nil || *p.Name != *input.Name) { + return false + } + + if p.Type != nil && (input.Type == nil || *p.Type != *input.Type) { + return false + } + + return true +} diff --git a/resource-manager/synapse/2021-06-01/workspacemanagedsqlserverservervulnerabilityassessments/version.go b/resource-manager/synapse/2021-06-01/workspacemanagedsqlserverservervulnerabilityassessments/version.go new file mode 100644 index 00000000000..da16c776f57 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/workspacemanagedsqlserverservervulnerabilityassessments/version.go @@ -0,0 +1,12 @@ +package workspacemanagedsqlserverservervulnerabilityassessments + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2021-06-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/workspacemanagedsqlserverservervulnerabilityassessments/%s", defaultApiVersion) +} diff --git a/resource-manager/synapse/2021-06-01/workspacemanagedsqlserversqlusages/README.md b/resource-manager/synapse/2021-06-01/workspacemanagedsqlserversqlusages/README.md new file mode 100644 index 00000000000..2d7d19ad5e9 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/workspacemanagedsqlserversqlusages/README.md @@ -0,0 +1,37 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/synapse/2021-06-01/workspacemanagedsqlserversqlusages` Documentation + +The `workspacemanagedsqlserversqlusages` SDK allows for interaction with the Azure Resource Manager Service `synapse` (API Version `2021-06-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/synapse/2021-06-01/workspacemanagedsqlserversqlusages" +``` + + +### Client Initialization + +```go +client := workspacemanagedsqlserversqlusages.NewWorkspaceManagedSqlServerSqlUsagesClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `WorkspaceManagedSqlServerSqlUsagesClient.WorkspaceManagedSqlServerUsagesList` + +```go +ctx := context.TODO() +id := workspacemanagedsqlserversqlusages.NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue") + +// alternatively `client.WorkspaceManagedSqlServerUsagesList(ctx, id)` can be used to do batched pagination +items, err := client.WorkspaceManagedSqlServerUsagesListComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/synapse/2021-06-01/workspacemanagedsqlserversqlusages/client.go b/resource-manager/synapse/2021-06-01/workspacemanagedsqlserversqlusages/client.go new file mode 100644 index 00000000000..942304efcee --- /dev/null +++ b/resource-manager/synapse/2021-06-01/workspacemanagedsqlserversqlusages/client.go @@ -0,0 +1,26 @@ +package workspacemanagedsqlserversqlusages + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type WorkspaceManagedSqlServerSqlUsagesClient struct { + Client *resourcemanager.Client +} + +func NewWorkspaceManagedSqlServerSqlUsagesClientWithBaseURI(sdkApi sdkEnv.Api) (*WorkspaceManagedSqlServerSqlUsagesClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "workspacemanagedsqlserversqlusages", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating WorkspaceManagedSqlServerSqlUsagesClient: %+v", err) + } + + return &WorkspaceManagedSqlServerSqlUsagesClient{ + Client: client, + }, nil +} diff --git a/resource-manager/synapse/2021-06-01/workspacemanagedsqlserversqlusages/id_workspace.go b/resource-manager/synapse/2021-06-01/workspacemanagedsqlserversqlusages/id_workspace.go new file mode 100644 index 00000000000..3fdfd8a5d05 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/workspacemanagedsqlserversqlusages/id_workspace.go @@ -0,0 +1,125 @@ +package workspacemanagedsqlserversqlusages + +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 = &WorkspaceId{} + +// WorkspaceId is a struct representing the Resource ID for a Workspace +type WorkspaceId struct { + SubscriptionId string + ResourceGroupName string + WorkspaceName string +} + +// NewWorkspaceID returns a new WorkspaceId struct +func NewWorkspaceID(subscriptionId string, resourceGroupName string, workspaceName string) WorkspaceId { + return WorkspaceId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + WorkspaceName: workspaceName, + } +} + +// ParseWorkspaceID parses 'input' into a WorkspaceId +func ParseWorkspaceID(input string) (*WorkspaceId, error) { + parser := resourceids.NewParserFromResourceIdType(&WorkspaceId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := WorkspaceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseWorkspaceIDInsensitively parses 'input' case-insensitively into a WorkspaceId +// note: this method should only be used for API response data and not user input +func ParseWorkspaceIDInsensitively(input string) (*WorkspaceId, error) { + parser := resourceids.NewParserFromResourceIdType(&WorkspaceId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := WorkspaceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *WorkspaceId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.WorkspaceName, ok = input.Parsed["workspaceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "workspaceName", input) + } + + return nil +} + +// ValidateWorkspaceID checks that 'input' can be parsed as a Workspace ID +func ValidateWorkspaceID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseWorkspaceID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Workspace ID +func (id WorkspaceId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Synapse/workspaces/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.WorkspaceName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Workspace ID +func (id WorkspaceId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftSynapse", "Microsoft.Synapse", "Microsoft.Synapse"), + resourceids.StaticSegment("staticWorkspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceName", "workspaceValue"), + } +} + +// String returns a human-readable description of this Workspace ID +func (id WorkspaceId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Workspace Name: %q", id.WorkspaceName), + } + return fmt.Sprintf("Workspace (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/synapse/2021-06-01/workspacemanagedsqlserversqlusages/id_workspace_test.go b/resource-manager/synapse/2021-06-01/workspacemanagedsqlserversqlusages/id_workspace_test.go new file mode 100644 index 00000000000..9f353cbf0d2 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/workspacemanagedsqlserversqlusages/id_workspace_test.go @@ -0,0 +1,282 @@ +package workspacemanagedsqlserversqlusages + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &WorkspaceId{} + +func TestNewWorkspaceID(t *testing.T) { + id := NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.WorkspaceName != "workspaceValue" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceName'", id.WorkspaceName, "workspaceValue") + } +} + +func TestFormatWorkspaceID(t *testing.T) { + actual := NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseWorkspaceID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkspaceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue", + Expected: &WorkspaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkspaceID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + } +} + +func TestParseWorkspaceIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkspaceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue", + Expected: &WorkspaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE", + Expected: &WorkspaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + WorkspaceName: "wOrKsPaCeVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkspaceIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + } +} + +func TestSegmentsForWorkspaceId(t *testing.T) { + segments := WorkspaceId{}.Segments() + if len(segments) == 0 { + t.Fatalf("WorkspaceId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/synapse/2021-06-01/workspacemanagedsqlserversqlusages/method_workspacemanagedsqlserverusageslist.go b/resource-manager/synapse/2021-06-01/workspacemanagedsqlserversqlusages/method_workspacemanagedsqlserverusageslist.go new file mode 100644 index 00000000000..f11a95b5c4f --- /dev/null +++ b/resource-manager/synapse/2021-06-01/workspacemanagedsqlserversqlusages/method_workspacemanagedsqlserverusageslist.go @@ -0,0 +1,91 @@ +package workspacemanagedsqlserversqlusages + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type WorkspaceManagedSqlServerUsagesListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]ServerUsage +} + +type WorkspaceManagedSqlServerUsagesListCompleteResult struct { + LatestHttpResponse *http.Response + Items []ServerUsage +} + +// WorkspaceManagedSqlServerUsagesList ... +func (c WorkspaceManagedSqlServerSqlUsagesClient) WorkspaceManagedSqlServerUsagesList(ctx context.Context, id WorkspaceId) (result WorkspaceManagedSqlServerUsagesListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/sqlUsages", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]ServerUsage `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// WorkspaceManagedSqlServerUsagesListComplete retrieves all the results into a single object +func (c WorkspaceManagedSqlServerSqlUsagesClient) WorkspaceManagedSqlServerUsagesListComplete(ctx context.Context, id WorkspaceId) (WorkspaceManagedSqlServerUsagesListCompleteResult, error) { + return c.WorkspaceManagedSqlServerUsagesListCompleteMatchingPredicate(ctx, id, ServerUsageOperationPredicate{}) +} + +// WorkspaceManagedSqlServerUsagesListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c WorkspaceManagedSqlServerSqlUsagesClient) WorkspaceManagedSqlServerUsagesListCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, predicate ServerUsageOperationPredicate) (result WorkspaceManagedSqlServerUsagesListCompleteResult, err error) { + items := make([]ServerUsage, 0) + + resp, err := c.WorkspaceManagedSqlServerUsagesList(ctx, id) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = WorkspaceManagedSqlServerUsagesListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/synapse/2021-06-01/workspacemanagedsqlserversqlusages/model_serverusage.go b/resource-manager/synapse/2021-06-01/workspacemanagedsqlserversqlusages/model_serverusage.go new file mode 100644 index 00000000000..e39cc8a7774 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/workspacemanagedsqlserversqlusages/model_serverusage.go @@ -0,0 +1,32 @@ +package workspacemanagedsqlserversqlusages + +import ( + "time" + + "github.com/hashicorp/go-azure-helpers/lang/dates" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ServerUsage struct { + CurrentValue *float64 `json:"currentValue,omitempty"` + DisplayName *string `json:"displayName,omitempty"` + Limit *float64 `json:"limit,omitempty"` + Name *string `json:"name,omitempty"` + NextResetTime *string `json:"nextResetTime,omitempty"` + ResourceName *string `json:"resourceName,omitempty"` + Unit *string `json:"unit,omitempty"` +} + +func (o *ServerUsage) GetNextResetTimeAsTime() (*time.Time, error) { + if o.NextResetTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.NextResetTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *ServerUsage) SetNextResetTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.NextResetTime = &formatted +} diff --git a/resource-manager/synapse/2021-06-01/workspacemanagedsqlserversqlusages/predicates.go b/resource-manager/synapse/2021-06-01/workspacemanagedsqlserversqlusages/predicates.go new file mode 100644 index 00000000000..e56f7706684 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/workspacemanagedsqlserversqlusages/predicates.go @@ -0,0 +1,47 @@ +package workspacemanagedsqlserversqlusages + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ServerUsageOperationPredicate struct { + CurrentValue *float64 + DisplayName *string + Limit *float64 + Name *string + NextResetTime *string + ResourceName *string + Unit *string +} + +func (p ServerUsageOperationPredicate) Matches(input ServerUsage) bool { + + if p.CurrentValue != nil && (input.CurrentValue == nil || *p.CurrentValue != *input.CurrentValue) { + return false + } + + if p.DisplayName != nil && (input.DisplayName == nil || *p.DisplayName != *input.DisplayName) { + return false + } + + if p.Limit != nil && (input.Limit == nil || *p.Limit != *input.Limit) { + return false + } + + if p.Name != nil && (input.Name == nil || *p.Name != *input.Name) { + return false + } + + if p.NextResetTime != nil && (input.NextResetTime == nil || *p.NextResetTime != *input.NextResetTime) { + return false + } + + if p.ResourceName != nil && (input.ResourceName == nil || *p.ResourceName != *input.ResourceName) { + return false + } + + if p.Unit != nil && (input.Unit == nil || *p.Unit != *input.Unit) { + return false + } + + return true +} diff --git a/resource-manager/synapse/2021-06-01/workspacemanagedsqlserversqlusages/version.go b/resource-manager/synapse/2021-06-01/workspacemanagedsqlserversqlusages/version.go new file mode 100644 index 00000000000..c7d6d0bbfc3 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/workspacemanagedsqlserversqlusages/version.go @@ -0,0 +1,12 @@ +package workspacemanagedsqlserversqlusages + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2021-06-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/workspacemanagedsqlserversqlusages/%s", defaultApiVersion) +} diff --git a/resource-manager/synapse/2021-06-01/workspaces/README.md b/resource-manager/synapse/2021-06-01/workspaces/README.md new file mode 100644 index 00000000000..67ddae314c8 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/workspaces/README.md @@ -0,0 +1,239 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/synapse/2021-06-01/workspaces` Documentation + +The `workspaces` SDK allows for interaction with the Azure Resource Manager Service `synapse` (API Version `2021-06-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/synapse/2021-06-01/workspaces" +``` + + +### Client Initialization + +```go +client := workspaces.NewWorkspacesClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `WorkspacesClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := workspaces.NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue") + +payload := workspaces.Workspace{ + // ... +} + + +if err := client.CreateOrUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `WorkspacesClient.Delete` + +```go +ctx := context.TODO() +id := workspaces.NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue") + +if err := client.DeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `WorkspacesClient.Get` + +```go +ctx := context.TODO() +id := workspaces.NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue") + +read, err := client.Get(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `WorkspacesClient.List` + +```go +ctx := context.TODO() +id := workspaces.NewSubscriptionID("12345678-1234-9876-4563-123456789012") + +// alternatively `client.List(ctx, id)` can be used to do batched pagination +items, err := client.ListComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `WorkspacesClient.ListByResourceGroup` + +```go +ctx := context.TODO() +id := workspaces.NewResourceGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group") + +// alternatively `client.ListByResourceGroup(ctx, id)` can be used to do batched pagination +items, err := client.ListByResourceGroupComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `WorkspacesClient.QlAadAdminsCreateOrUpdate` + +```go +ctx := context.TODO() +id := workspaces.NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue") + +payload := workspaces.WorkspaceAadAdminInfo{ + // ... +} + + +if err := client.QlAadAdminsCreateOrUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `WorkspacesClient.QlAadAdminsDelete` + +```go +ctx := context.TODO() +id := workspaces.NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue") + +if err := client.QlAadAdminsDeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `WorkspacesClient.QlAadAdminsGet` + +```go +ctx := context.TODO() +id := workspaces.NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue") + +read, err := client.QlAadAdminsGet(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `WorkspacesClient.Update` + +```go +ctx := context.TODO() +id := workspaces.NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue") + +payload := workspaces.WorkspacePatchInfo{ + // ... +} + + +if err := client.UpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `WorkspacesClient.WorkspaceAadAdminsCreateOrUpdate` + +```go +ctx := context.TODO() +id := workspaces.NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue") + +payload := workspaces.WorkspaceAadAdminInfo{ + // ... +} + + +if err := client.WorkspaceAadAdminsCreateOrUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `WorkspacesClient.WorkspaceAadAdminsDelete` + +```go +ctx := context.TODO() +id := workspaces.NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue") + +if err := client.WorkspaceAadAdminsDeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `WorkspacesClient.WorkspaceAadAdminsGet` + +```go +ctx := context.TODO() +id := workspaces.NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue") + +read, err := client.WorkspaceAadAdminsGet(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `WorkspacesClient.WorkspaceManagedIdentitySqlControlSettingsCreateOrUpdate` + +```go +ctx := context.TODO() +id := workspaces.NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue") + +payload := workspaces.ManagedIdentitySqlControlSettingsModel{ + // ... +} + + +if err := client.WorkspaceManagedIdentitySqlControlSettingsCreateOrUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `WorkspacesClient.WorkspaceManagedIdentitySqlControlSettingsGet` + +```go +ctx := context.TODO() +id := workspaces.NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue") + +read, err := client.WorkspaceManagedIdentitySqlControlSettingsGet(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` diff --git a/resource-manager/synapse/2021-06-01/workspaces/client.go b/resource-manager/synapse/2021-06-01/workspaces/client.go new file mode 100644 index 00000000000..d599252c05c --- /dev/null +++ b/resource-manager/synapse/2021-06-01/workspaces/client.go @@ -0,0 +1,26 @@ +package workspaces + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type WorkspacesClient struct { + Client *resourcemanager.Client +} + +func NewWorkspacesClientWithBaseURI(sdkApi sdkEnv.Api) (*WorkspacesClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "workspaces", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating WorkspacesClient: %+v", err) + } + + return &WorkspacesClient{ + Client: client, + }, nil +} diff --git a/resource-manager/synapse/2021-06-01/workspaces/constants.go b/resource-manager/synapse/2021-06-01/workspaces/constants.go new file mode 100644 index 00000000000..5f37e50dbc2 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/workspaces/constants.go @@ -0,0 +1,186 @@ +package workspaces + +import ( + "encoding/json" + "fmt" + "strings" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ActualState string + +const ( + ActualStateDisabled ActualState = "Disabled" + ActualStateDisabling ActualState = "Disabling" + ActualStateEnabled ActualState = "Enabled" + ActualStateEnabling ActualState = "Enabling" + ActualStateUnknown ActualState = "Unknown" +) + +func PossibleValuesForActualState() []string { + return []string{ + string(ActualStateDisabled), + string(ActualStateDisabling), + string(ActualStateEnabled), + string(ActualStateEnabling), + string(ActualStateUnknown), + } +} + +func (s *ActualState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseActualState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseActualState(input string) (*ActualState, error) { + vals := map[string]ActualState{ + "disabled": ActualStateDisabled, + "disabling": ActualStateDisabling, + "enabled": ActualStateEnabled, + "enabling": ActualStateEnabling, + "unknown": ActualStateUnknown, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ActualState(input) + return &out, nil +} + +type DesiredState string + +const ( + DesiredStateDisabled DesiredState = "Disabled" + DesiredStateEnabled DesiredState = "Enabled" +) + +func PossibleValuesForDesiredState() []string { + return []string{ + string(DesiredStateDisabled), + string(DesiredStateEnabled), + } +} + +func (s *DesiredState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseDesiredState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseDesiredState(input string) (*DesiredState, error) { + vals := map[string]DesiredState{ + "disabled": DesiredStateDisabled, + "enabled": DesiredStateEnabled, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := DesiredState(input) + return &out, nil +} + +type ResourceIdentityType string + +const ( + ResourceIdentityTypeNone ResourceIdentityType = "None" + ResourceIdentityTypeSystemAssigned ResourceIdentityType = "SystemAssigned" + ResourceIdentityTypeSystemAssignedUserAssigned ResourceIdentityType = "SystemAssigned,UserAssigned" +) + +func PossibleValuesForResourceIdentityType() []string { + return []string{ + string(ResourceIdentityTypeNone), + string(ResourceIdentityTypeSystemAssigned), + string(ResourceIdentityTypeSystemAssignedUserAssigned), + } +} + +func (s *ResourceIdentityType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseResourceIdentityType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseResourceIdentityType(input string) (*ResourceIdentityType, error) { + vals := map[string]ResourceIdentityType{ + "none": ResourceIdentityTypeNone, + "systemassigned": ResourceIdentityTypeSystemAssigned, + "systemassigned,userassigned": ResourceIdentityTypeSystemAssignedUserAssigned, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ResourceIdentityType(input) + return &out, nil +} + +type WorkspacePublicNetworkAccess string + +const ( + WorkspacePublicNetworkAccessDisabled WorkspacePublicNetworkAccess = "Disabled" + WorkspacePublicNetworkAccessEnabled WorkspacePublicNetworkAccess = "Enabled" +) + +func PossibleValuesForWorkspacePublicNetworkAccess() []string { + return []string{ + string(WorkspacePublicNetworkAccessDisabled), + string(WorkspacePublicNetworkAccessEnabled), + } +} + +func (s *WorkspacePublicNetworkAccess) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseWorkspacePublicNetworkAccess(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseWorkspacePublicNetworkAccess(input string) (*WorkspacePublicNetworkAccess, error) { + vals := map[string]WorkspacePublicNetworkAccess{ + "disabled": WorkspacePublicNetworkAccessDisabled, + "enabled": WorkspacePublicNetworkAccessEnabled, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := WorkspacePublicNetworkAccess(input) + return &out, nil +} diff --git a/resource-manager/synapse/2021-06-01/workspaces/id_workspace.go b/resource-manager/synapse/2021-06-01/workspaces/id_workspace.go new file mode 100644 index 00000000000..a67f9ad1cda --- /dev/null +++ b/resource-manager/synapse/2021-06-01/workspaces/id_workspace.go @@ -0,0 +1,125 @@ +package workspaces + +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 = &WorkspaceId{} + +// WorkspaceId is a struct representing the Resource ID for a Workspace +type WorkspaceId struct { + SubscriptionId string + ResourceGroupName string + WorkspaceName string +} + +// NewWorkspaceID returns a new WorkspaceId struct +func NewWorkspaceID(subscriptionId string, resourceGroupName string, workspaceName string) WorkspaceId { + return WorkspaceId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + WorkspaceName: workspaceName, + } +} + +// ParseWorkspaceID parses 'input' into a WorkspaceId +func ParseWorkspaceID(input string) (*WorkspaceId, error) { + parser := resourceids.NewParserFromResourceIdType(&WorkspaceId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := WorkspaceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseWorkspaceIDInsensitively parses 'input' case-insensitively into a WorkspaceId +// note: this method should only be used for API response data and not user input +func ParseWorkspaceIDInsensitively(input string) (*WorkspaceId, error) { + parser := resourceids.NewParserFromResourceIdType(&WorkspaceId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := WorkspaceId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *WorkspaceId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.WorkspaceName, ok = input.Parsed["workspaceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "workspaceName", input) + } + + return nil +} + +// ValidateWorkspaceID checks that 'input' can be parsed as a Workspace ID +func ValidateWorkspaceID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseWorkspaceID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Workspace ID +func (id WorkspaceId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Synapse/workspaces/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.WorkspaceName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Workspace ID +func (id WorkspaceId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftSynapse", "Microsoft.Synapse", "Microsoft.Synapse"), + resourceids.StaticSegment("staticWorkspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceName", "workspaceValue"), + } +} + +// String returns a human-readable description of this Workspace ID +func (id WorkspaceId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Workspace Name: %q", id.WorkspaceName), + } + return fmt.Sprintf("Workspace (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/synapse/2021-06-01/workspaces/id_workspace_test.go b/resource-manager/synapse/2021-06-01/workspaces/id_workspace_test.go new file mode 100644 index 00000000000..6f8b99026bf --- /dev/null +++ b/resource-manager/synapse/2021-06-01/workspaces/id_workspace_test.go @@ -0,0 +1,282 @@ +package workspaces + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &WorkspaceId{} + +func TestNewWorkspaceID(t *testing.T) { + id := NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.WorkspaceName != "workspaceValue" { + t.Fatalf("Expected %q but got %q for Segment 'WorkspaceName'", id.WorkspaceName, "workspaceValue") + } +} + +func TestFormatWorkspaceID(t *testing.T) { + actual := NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseWorkspaceID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkspaceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue", + Expected: &WorkspaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkspaceID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + } +} + +func TestParseWorkspaceIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WorkspaceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue", + Expected: &WorkspaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + WorkspaceName: "workspaceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Synapse/workspaces/workspaceValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE", + Expected: &WorkspaceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + WorkspaceName: "wOrKsPaCeVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sYnApSe/wOrKsPaCeS/wOrKsPaCeVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWorkspaceIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.WorkspaceName != v.Expected.WorkspaceName { + t.Fatalf("Expected %q but got %q for WorkspaceName", v.Expected.WorkspaceName, actual.WorkspaceName) + } + + } +} + +func TestSegmentsForWorkspaceId(t *testing.T) { + segments := WorkspaceId{}.Segments() + if len(segments) == 0 { + t.Fatalf("WorkspaceId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/synapse/2021-06-01/workspaces/method_createorupdate.go b/resource-manager/synapse/2021-06-01/workspaces/method_createorupdate.go new file mode 100644 index 00000000000..cc4deaa2566 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/workspaces/method_createorupdate.go @@ -0,0 +1,75 @@ +package workspaces + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOrUpdateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *Workspace +} + +// CreateOrUpdate ... +func (c WorkspacesClient) CreateOrUpdate(ctx context.Context, id WorkspaceId, input Workspace) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// CreateOrUpdateThenPoll performs CreateOrUpdate then polls until it's completed +func (c WorkspacesClient) CreateOrUpdateThenPoll(ctx context.Context, id WorkspaceId, input Workspace) error { + result, err := c.CreateOrUpdate(ctx, id, input) + if err != nil { + return fmt.Errorf("performing CreateOrUpdate: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after CreateOrUpdate: %+v", err) + } + + return nil +} diff --git a/resource-manager/synapse/2021-06-01/workspaces/method_delete.go b/resource-manager/synapse/2021-06-01/workspaces/method_delete.go new file mode 100644 index 00000000000..761c3bc5b31 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/workspaces/method_delete.go @@ -0,0 +1,72 @@ +package workspaces + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *Workspace +} + +// Delete ... +func (c WorkspacesClient) Delete(ctx context.Context, id WorkspaceId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// DeleteThenPoll performs Delete then polls until it's completed +func (c WorkspacesClient) DeleteThenPoll(ctx context.Context, id WorkspaceId) error { + result, err := c.Delete(ctx, id) + if err != nil { + return fmt.Errorf("performing Delete: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after Delete: %+v", err) + } + + return nil +} diff --git a/resource-manager/synapse/2021-06-01/workspaces/method_get.go b/resource-manager/synapse/2021-06-01/workspaces/method_get.go new file mode 100644 index 00000000000..9c154cb9621 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/workspaces/method_get.go @@ -0,0 +1,51 @@ +package workspaces + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *Workspace +} + +// Get ... +func (c WorkspacesClient) Get(ctx context.Context, id WorkspaceId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/synapse/2021-06-01/workspaces/method_list.go b/resource-manager/synapse/2021-06-01/workspaces/method_list.go new file mode 100644 index 00000000000..e9283d262bf --- /dev/null +++ b/resource-manager/synapse/2021-06-01/workspaces/method_list.go @@ -0,0 +1,92 @@ +package workspaces + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]Workspace +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []Workspace +} + +// List ... +func (c WorkspacesClient) List(ctx context.Context, id commonids.SubscriptionId) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/providers/Microsoft.Synapse/workspaces", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]Workspace `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListComplete retrieves all the results into a single object +func (c WorkspacesClient) ListComplete(ctx context.Context, id commonids.SubscriptionId) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, WorkspaceOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c WorkspacesClient) ListCompleteMatchingPredicate(ctx context.Context, id commonids.SubscriptionId, predicate WorkspaceOperationPredicate) (result ListCompleteResult, err error) { + items := make([]Workspace, 0) + + resp, err := c.List(ctx, id) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/synapse/2021-06-01/workspaces/method_listbyresourcegroup.go b/resource-manager/synapse/2021-06-01/workspaces/method_listbyresourcegroup.go new file mode 100644 index 00000000000..a70362546ed --- /dev/null +++ b/resource-manager/synapse/2021-06-01/workspaces/method_listbyresourcegroup.go @@ -0,0 +1,92 @@ +package workspaces + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListByResourceGroupOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]Workspace +} + +type ListByResourceGroupCompleteResult struct { + LatestHttpResponse *http.Response + Items []Workspace +} + +// ListByResourceGroup ... +func (c WorkspacesClient) ListByResourceGroup(ctx context.Context, id commonids.ResourceGroupId) (result ListByResourceGroupOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/providers/Microsoft.Synapse/workspaces", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]Workspace `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByResourceGroupComplete retrieves all the results into a single object +func (c WorkspacesClient) ListByResourceGroupComplete(ctx context.Context, id commonids.ResourceGroupId) (ListByResourceGroupCompleteResult, error) { + return c.ListByResourceGroupCompleteMatchingPredicate(ctx, id, WorkspaceOperationPredicate{}) +} + +// ListByResourceGroupCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c WorkspacesClient) ListByResourceGroupCompleteMatchingPredicate(ctx context.Context, id commonids.ResourceGroupId, predicate WorkspaceOperationPredicate) (result ListByResourceGroupCompleteResult, err error) { + items := make([]Workspace, 0) + + resp, err := c.ListByResourceGroup(ctx, id) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByResourceGroupCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/synapse/2021-06-01/workspaces/method_qlaadadminscreateorupdate.go b/resource-manager/synapse/2021-06-01/workspaces/method_qlaadadminscreateorupdate.go new file mode 100644 index 00000000000..af84ab9be79 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/workspaces/method_qlaadadminscreateorupdate.go @@ -0,0 +1,75 @@ +package workspaces + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type QlAadAdminsCreateOrUpdateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *WorkspaceAadAdminInfo +} + +// QlAadAdminsCreateOrUpdate ... +func (c WorkspacesClient) QlAadAdminsCreateOrUpdate(ctx context.Context, id WorkspaceId, input WorkspaceAadAdminInfo) (result QlAadAdminsCreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: fmt.Sprintf("%s/sqlAdministrators/activeDirectory", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// QlAadAdminsCreateOrUpdateThenPoll performs QlAadAdminsCreateOrUpdate then polls until it's completed +func (c WorkspacesClient) QlAadAdminsCreateOrUpdateThenPoll(ctx context.Context, id WorkspaceId, input WorkspaceAadAdminInfo) error { + result, err := c.QlAadAdminsCreateOrUpdate(ctx, id, input) + if err != nil { + return fmt.Errorf("performing QlAadAdminsCreateOrUpdate: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after QlAadAdminsCreateOrUpdate: %+v", err) + } + + return nil +} diff --git a/resource-manager/synapse/2021-06-01/workspaces/method_qlaadadminsdelete.go b/resource-manager/synapse/2021-06-01/workspaces/method_qlaadadminsdelete.go new file mode 100644 index 00000000000..26310b88542 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/workspaces/method_qlaadadminsdelete.go @@ -0,0 +1,71 @@ +package workspaces + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type QlAadAdminsDeleteOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// QlAadAdminsDelete ... +func (c WorkspacesClient) QlAadAdminsDelete(ctx context.Context, id WorkspaceId) (result QlAadAdminsDeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: fmt.Sprintf("%s/sqlAdministrators/activeDirectory", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// QlAadAdminsDeleteThenPoll performs QlAadAdminsDelete then polls until it's completed +func (c WorkspacesClient) QlAadAdminsDeleteThenPoll(ctx context.Context, id WorkspaceId) error { + result, err := c.QlAadAdminsDelete(ctx, id) + if err != nil { + return fmt.Errorf("performing QlAadAdminsDelete: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after QlAadAdminsDelete: %+v", err) + } + + return nil +} diff --git a/resource-manager/synapse/2021-06-01/workspaces/method_qlaadadminsget.go b/resource-manager/synapse/2021-06-01/workspaces/method_qlaadadminsget.go new file mode 100644 index 00000000000..f3de4e7263c --- /dev/null +++ b/resource-manager/synapse/2021-06-01/workspaces/method_qlaadadminsget.go @@ -0,0 +1,52 @@ +package workspaces + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type QlAadAdminsGetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *WorkspaceAadAdminInfo +} + +// QlAadAdminsGet ... +func (c WorkspacesClient) QlAadAdminsGet(ctx context.Context, id WorkspaceId) (result QlAadAdminsGetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/sqlAdministrators/activeDirectory", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/synapse/2021-06-01/workspaces/method_update.go b/resource-manager/synapse/2021-06-01/workspaces/method_update.go new file mode 100644 index 00000000000..1ab15e1bc9b --- /dev/null +++ b/resource-manager/synapse/2021-06-01/workspaces/method_update.go @@ -0,0 +1,75 @@ +package workspaces + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type UpdateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *Workspace +} + +// Update ... +func (c WorkspacesClient) Update(ctx context.Context, id WorkspaceId, input WorkspacePatchInfo) (result UpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPatch, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// UpdateThenPoll performs Update then polls until it's completed +func (c WorkspacesClient) UpdateThenPoll(ctx context.Context, id WorkspaceId, input WorkspacePatchInfo) error { + result, err := c.Update(ctx, id, input) + if err != nil { + return fmt.Errorf("performing Update: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after Update: %+v", err) + } + + return nil +} diff --git a/resource-manager/synapse/2021-06-01/workspaces/method_workspaceaadadminscreateorupdate.go b/resource-manager/synapse/2021-06-01/workspaces/method_workspaceaadadminscreateorupdate.go new file mode 100644 index 00000000000..f42de48963d --- /dev/null +++ b/resource-manager/synapse/2021-06-01/workspaces/method_workspaceaadadminscreateorupdate.go @@ -0,0 +1,75 @@ +package workspaces + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type WorkspaceAadAdminsCreateOrUpdateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *WorkspaceAadAdminInfo +} + +// WorkspaceAadAdminsCreateOrUpdate ... +func (c WorkspacesClient) WorkspaceAadAdminsCreateOrUpdate(ctx context.Context, id WorkspaceId, input WorkspaceAadAdminInfo) (result WorkspaceAadAdminsCreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: fmt.Sprintf("%s/administrators/activeDirectory", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// WorkspaceAadAdminsCreateOrUpdateThenPoll performs WorkspaceAadAdminsCreateOrUpdate then polls until it's completed +func (c WorkspacesClient) WorkspaceAadAdminsCreateOrUpdateThenPoll(ctx context.Context, id WorkspaceId, input WorkspaceAadAdminInfo) error { + result, err := c.WorkspaceAadAdminsCreateOrUpdate(ctx, id, input) + if err != nil { + return fmt.Errorf("performing WorkspaceAadAdminsCreateOrUpdate: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after WorkspaceAadAdminsCreateOrUpdate: %+v", err) + } + + return nil +} diff --git a/resource-manager/synapse/2021-06-01/workspaces/method_workspaceaadadminsdelete.go b/resource-manager/synapse/2021-06-01/workspaces/method_workspaceaadadminsdelete.go new file mode 100644 index 00000000000..72efba009a6 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/workspaces/method_workspaceaadadminsdelete.go @@ -0,0 +1,71 @@ +package workspaces + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type WorkspaceAadAdminsDeleteOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// WorkspaceAadAdminsDelete ... +func (c WorkspacesClient) WorkspaceAadAdminsDelete(ctx context.Context, id WorkspaceId) (result WorkspaceAadAdminsDeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: fmt.Sprintf("%s/administrators/activeDirectory", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// WorkspaceAadAdminsDeleteThenPoll performs WorkspaceAadAdminsDelete then polls until it's completed +func (c WorkspacesClient) WorkspaceAadAdminsDeleteThenPoll(ctx context.Context, id WorkspaceId) error { + result, err := c.WorkspaceAadAdminsDelete(ctx, id) + if err != nil { + return fmt.Errorf("performing WorkspaceAadAdminsDelete: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after WorkspaceAadAdminsDelete: %+v", err) + } + + return nil +} diff --git a/resource-manager/synapse/2021-06-01/workspaces/method_workspaceaadadminsget.go b/resource-manager/synapse/2021-06-01/workspaces/method_workspaceaadadminsget.go new file mode 100644 index 00000000000..3bd20436a29 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/workspaces/method_workspaceaadadminsget.go @@ -0,0 +1,52 @@ +package workspaces + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type WorkspaceAadAdminsGetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *WorkspaceAadAdminInfo +} + +// WorkspaceAadAdminsGet ... +func (c WorkspacesClient) WorkspaceAadAdminsGet(ctx context.Context, id WorkspaceId) (result WorkspaceAadAdminsGetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/administrators/activeDirectory", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/synapse/2021-06-01/workspaces/method_workspacemanagedidentitysqlcontrolsettingscreateorupdate.go b/resource-manager/synapse/2021-06-01/workspaces/method_workspacemanagedidentitysqlcontrolsettingscreateorupdate.go new file mode 100644 index 00000000000..686f3ed7abd --- /dev/null +++ b/resource-manager/synapse/2021-06-01/workspaces/method_workspacemanagedidentitysqlcontrolsettingscreateorupdate.go @@ -0,0 +1,75 @@ +package workspaces + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type WorkspaceManagedIdentitySqlControlSettingsCreateOrUpdateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *ManagedIdentitySqlControlSettingsModel +} + +// WorkspaceManagedIdentitySqlControlSettingsCreateOrUpdate ... +func (c WorkspacesClient) WorkspaceManagedIdentitySqlControlSettingsCreateOrUpdate(ctx context.Context, id WorkspaceId, input ManagedIdentitySqlControlSettingsModel) (result WorkspaceManagedIdentitySqlControlSettingsCreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: fmt.Sprintf("%s/managedIdentitySqlControlSettings/default", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// WorkspaceManagedIdentitySqlControlSettingsCreateOrUpdateThenPoll performs WorkspaceManagedIdentitySqlControlSettingsCreateOrUpdate then polls until it's completed +func (c WorkspacesClient) WorkspaceManagedIdentitySqlControlSettingsCreateOrUpdateThenPoll(ctx context.Context, id WorkspaceId, input ManagedIdentitySqlControlSettingsModel) error { + result, err := c.WorkspaceManagedIdentitySqlControlSettingsCreateOrUpdate(ctx, id, input) + if err != nil { + return fmt.Errorf("performing WorkspaceManagedIdentitySqlControlSettingsCreateOrUpdate: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after WorkspaceManagedIdentitySqlControlSettingsCreateOrUpdate: %+v", err) + } + + return nil +} diff --git a/resource-manager/synapse/2021-06-01/workspaces/method_workspacemanagedidentitysqlcontrolsettingsget.go b/resource-manager/synapse/2021-06-01/workspaces/method_workspacemanagedidentitysqlcontrolsettingsget.go new file mode 100644 index 00000000000..f0655bb0671 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/workspaces/method_workspacemanagedidentitysqlcontrolsettingsget.go @@ -0,0 +1,52 @@ +package workspaces + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type WorkspaceManagedIdentitySqlControlSettingsGetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *ManagedIdentitySqlControlSettingsModel +} + +// WorkspaceManagedIdentitySqlControlSettingsGet ... +func (c WorkspacesClient) WorkspaceManagedIdentitySqlControlSettingsGet(ctx context.Context, id WorkspaceId) (result WorkspaceManagedIdentitySqlControlSettingsGetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/managedIdentitySqlControlSettings/default", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/synapse/2021-06-01/workspaces/model_aadadminproperties.go b/resource-manager/synapse/2021-06-01/workspaces/model_aadadminproperties.go new file mode 100644 index 00000000000..089c0fced8c --- /dev/null +++ b/resource-manager/synapse/2021-06-01/workspaces/model_aadadminproperties.go @@ -0,0 +1,11 @@ +package workspaces + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AadAdminProperties struct { + AdministratorType *string `json:"administratorType,omitempty"` + Login *string `json:"login,omitempty"` + Sid *string `json:"sid,omitempty"` + TenantId *string `json:"tenantId,omitempty"` +} diff --git a/resource-manager/synapse/2021-06-01/workspaces/model_cspworkspaceadminproperties.go b/resource-manager/synapse/2021-06-01/workspaces/model_cspworkspaceadminproperties.go new file mode 100644 index 00000000000..2752362c331 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/workspaces/model_cspworkspaceadminproperties.go @@ -0,0 +1,8 @@ +package workspaces + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CspWorkspaceAdminProperties struct { + InitialWorkspaceAdminObjectId *string `json:"initialWorkspaceAdminObjectId,omitempty"` +} diff --git a/resource-manager/synapse/2021-06-01/workspaces/model_customermanagedkeydetails.go b/resource-manager/synapse/2021-06-01/workspaces/model_customermanagedkeydetails.go new file mode 100644 index 00000000000..ce537086511 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/workspaces/model_customermanagedkeydetails.go @@ -0,0 +1,10 @@ +package workspaces + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CustomerManagedKeyDetails struct { + KekIdentity *KekIdentityProperties `json:"kekIdentity,omitempty"` + Key *WorkspaceKeyDetails `json:"key,omitempty"` + Status *string `json:"status,omitempty"` +} diff --git a/resource-manager/synapse/2021-06-01/workspaces/model_datalakestorageaccountdetails.go b/resource-manager/synapse/2021-06-01/workspaces/model_datalakestorageaccountdetails.go new file mode 100644 index 00000000000..2e986cadb83 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/workspaces/model_datalakestorageaccountdetails.go @@ -0,0 +1,11 @@ +package workspaces + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DataLakeStorageAccountDetails struct { + AccountUrl *string `json:"accountUrl,omitempty"` + CreateManagedPrivateEndpoint *bool `json:"createManagedPrivateEndpoint,omitempty"` + Filesystem *string `json:"filesystem,omitempty"` + ResourceId *string `json:"resourceId,omitempty"` +} diff --git a/resource-manager/synapse/2021-06-01/workspaces/model_encryptiondetails.go b/resource-manager/synapse/2021-06-01/workspaces/model_encryptiondetails.go new file mode 100644 index 00000000000..ed5e313b258 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/workspaces/model_encryptiondetails.go @@ -0,0 +1,9 @@ +package workspaces + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type EncryptionDetails struct { + Cmk *CustomerManagedKeyDetails `json:"cmk,omitempty"` + DoubleEncryptionEnabled *bool `json:"doubleEncryptionEnabled,omitempty"` +} diff --git a/resource-manager/synapse/2021-06-01/workspaces/model_kekidentityproperties.go b/resource-manager/synapse/2021-06-01/workspaces/model_kekidentityproperties.go new file mode 100644 index 00000000000..ecf35e19eb9 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/workspaces/model_kekidentityproperties.go @@ -0,0 +1,9 @@ +package workspaces + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type KekIdentityProperties struct { + UseSystemAssignedIdentity *interface{} `json:"useSystemAssignedIdentity,omitempty"` + UserAssignedIdentity *string `json:"userAssignedIdentity,omitempty"` +} diff --git a/resource-manager/synapse/2021-06-01/workspaces/model_managedidentity.go b/resource-manager/synapse/2021-06-01/workspaces/model_managedidentity.go new file mode 100644 index 00000000000..746ed4a76e9 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/workspaces/model_managedidentity.go @@ -0,0 +1,11 @@ +package workspaces + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ManagedIdentity struct { + PrincipalId *string `json:"principalId,omitempty"` + TenantId *string `json:"tenantId,omitempty"` + Type *ResourceIdentityType `json:"type,omitempty"` + UserAssignedIdentities *map[string]UserAssignedManagedIdentity `json:"userAssignedIdentities,omitempty"` +} diff --git a/resource-manager/synapse/2021-06-01/workspaces/model_managedidentitysqlcontrolsettingsmodel.go b/resource-manager/synapse/2021-06-01/workspaces/model_managedidentitysqlcontrolsettingsmodel.go new file mode 100644 index 00000000000..c6251111a3b --- /dev/null +++ b/resource-manager/synapse/2021-06-01/workspaces/model_managedidentitysqlcontrolsettingsmodel.go @@ -0,0 +1,11 @@ +package workspaces + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ManagedIdentitySqlControlSettingsModel struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *ManagedIdentitySqlControlSettingsModelProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/synapse/2021-06-01/workspaces/model_managedidentitysqlcontrolsettingsmodelproperties.go b/resource-manager/synapse/2021-06-01/workspaces/model_managedidentitysqlcontrolsettingsmodelproperties.go new file mode 100644 index 00000000000..4113a906e55 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/workspaces/model_managedidentitysqlcontrolsettingsmodelproperties.go @@ -0,0 +1,8 @@ +package workspaces + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ManagedIdentitySqlControlSettingsModelProperties struct { + GrantSqlControlToManagedIdentity *ManagedIdentitySqlControlSettingsModelPropertiesGrantSqlControlToManagedIdentity `json:"grantSqlControlToManagedIdentity,omitempty"` +} diff --git a/resource-manager/synapse/2021-06-01/workspaces/model_managedidentitysqlcontrolsettingsmodelpropertiesgrantsqlcontroltomanagedidentity.go b/resource-manager/synapse/2021-06-01/workspaces/model_managedidentitysqlcontrolsettingsmodelpropertiesgrantsqlcontroltomanagedidentity.go new file mode 100644 index 00000000000..a449deb774b --- /dev/null +++ b/resource-manager/synapse/2021-06-01/workspaces/model_managedidentitysqlcontrolsettingsmodelpropertiesgrantsqlcontroltomanagedidentity.go @@ -0,0 +1,9 @@ +package workspaces + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ManagedIdentitySqlControlSettingsModelPropertiesGrantSqlControlToManagedIdentity struct { + ActualState *ActualState `json:"actualState,omitempty"` + DesiredState *DesiredState `json:"desiredState,omitempty"` +} diff --git a/resource-manager/synapse/2021-06-01/workspaces/model_managedvirtualnetworksettings.go b/resource-manager/synapse/2021-06-01/workspaces/model_managedvirtualnetworksettings.go new file mode 100644 index 00000000000..b9a3b617cb6 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/workspaces/model_managedvirtualnetworksettings.go @@ -0,0 +1,10 @@ +package workspaces + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ManagedVirtualNetworkSettings struct { + AllowedAadTenantIdsForLinking *[]string `json:"allowedAadTenantIdsForLinking,omitempty"` + LinkedAccessCheckOnTargetResource *bool `json:"linkedAccessCheckOnTargetResource,omitempty"` + PreventDataExfiltration *bool `json:"preventDataExfiltration,omitempty"` +} diff --git a/resource-manager/synapse/2021-06-01/workspaces/model_privateendpoint.go b/resource-manager/synapse/2021-06-01/workspaces/model_privateendpoint.go new file mode 100644 index 00000000000..9f81ff8b836 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/workspaces/model_privateendpoint.go @@ -0,0 +1,8 @@ +package workspaces + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateEndpoint struct { + Id *string `json:"id,omitempty"` +} diff --git a/resource-manager/synapse/2021-06-01/workspaces/model_privateendpointconnection.go b/resource-manager/synapse/2021-06-01/workspaces/model_privateendpointconnection.go new file mode 100644 index 00000000000..351458f382f --- /dev/null +++ b/resource-manager/synapse/2021-06-01/workspaces/model_privateendpointconnection.go @@ -0,0 +1,11 @@ +package workspaces + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateEndpointConnection struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *PrivateEndpointConnectionProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/synapse/2021-06-01/workspaces/model_privateendpointconnectionproperties.go b/resource-manager/synapse/2021-06-01/workspaces/model_privateendpointconnectionproperties.go new file mode 100644 index 00000000000..d5514343224 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/workspaces/model_privateendpointconnectionproperties.go @@ -0,0 +1,10 @@ +package workspaces + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateEndpointConnectionProperties struct { + PrivateEndpoint *PrivateEndpoint `json:"privateEndpoint,omitempty"` + PrivateLinkServiceConnectionState *PrivateLinkServiceConnectionState `json:"privateLinkServiceConnectionState,omitempty"` + ProvisioningState *string `json:"provisioningState,omitempty"` +} diff --git a/resource-manager/synapse/2021-06-01/workspaces/model_privatelinkserviceconnectionstate.go b/resource-manager/synapse/2021-06-01/workspaces/model_privatelinkserviceconnectionstate.go new file mode 100644 index 00000000000..bebbbb4dd41 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/workspaces/model_privatelinkserviceconnectionstate.go @@ -0,0 +1,10 @@ +package workspaces + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateLinkServiceConnectionState struct { + ActionsRequired *string `json:"actionsRequired,omitempty"` + Description *string `json:"description,omitempty"` + Status *string `json:"status,omitempty"` +} diff --git a/resource-manager/synapse/2021-06-01/workspaces/model_purviewconfiguration.go b/resource-manager/synapse/2021-06-01/workspaces/model_purviewconfiguration.go new file mode 100644 index 00000000000..004eba85d2a --- /dev/null +++ b/resource-manager/synapse/2021-06-01/workspaces/model_purviewconfiguration.go @@ -0,0 +1,8 @@ +package workspaces + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PurviewConfiguration struct { + PurviewResourceId *string `json:"purviewResourceId,omitempty"` +} diff --git a/resource-manager/synapse/2021-06-01/workspaces/model_userassignedmanagedidentity.go b/resource-manager/synapse/2021-06-01/workspaces/model_userassignedmanagedidentity.go new file mode 100644 index 00000000000..b819e76e042 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/workspaces/model_userassignedmanagedidentity.go @@ -0,0 +1,9 @@ +package workspaces + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type UserAssignedManagedIdentity struct { + ClientId *string `json:"clientId,omitempty"` + PrincipalId *string `json:"principalId,omitempty"` +} diff --git a/resource-manager/synapse/2021-06-01/workspaces/model_virtualnetworkprofile.go b/resource-manager/synapse/2021-06-01/workspaces/model_virtualnetworkprofile.go new file mode 100644 index 00000000000..d07b2f32e01 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/workspaces/model_virtualnetworkprofile.go @@ -0,0 +1,8 @@ +package workspaces + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type VirtualNetworkProfile struct { + ComputeSubnetId *string `json:"computeSubnetId,omitempty"` +} diff --git a/resource-manager/synapse/2021-06-01/workspaces/model_workspace.go b/resource-manager/synapse/2021-06-01/workspaces/model_workspace.go new file mode 100644 index 00000000000..b4860adb8f9 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/workspaces/model_workspace.go @@ -0,0 +1,14 @@ +package workspaces + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Workspace struct { + Id *string `json:"id,omitempty"` + Identity *ManagedIdentity `json:"identity,omitempty"` + Location string `json:"location"` + Name *string `json:"name,omitempty"` + Properties *WorkspaceProperties `json:"properties,omitempty"` + Tags *map[string]string `json:"tags,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/synapse/2021-06-01/workspaces/model_workspaceaadadmininfo.go b/resource-manager/synapse/2021-06-01/workspaces/model_workspaceaadadmininfo.go new file mode 100644 index 00000000000..248784d4a94 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/workspaces/model_workspaceaadadmininfo.go @@ -0,0 +1,11 @@ +package workspaces + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type WorkspaceAadAdminInfo struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *AadAdminProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/synapse/2021-06-01/workspaces/model_workspacekeydetails.go b/resource-manager/synapse/2021-06-01/workspaces/model_workspacekeydetails.go new file mode 100644 index 00000000000..991c15f69c9 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/workspaces/model_workspacekeydetails.go @@ -0,0 +1,9 @@ +package workspaces + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type WorkspaceKeyDetails struct { + KeyVaultUrl *string `json:"keyVaultUrl,omitempty"` + Name *string `json:"name,omitempty"` +} diff --git a/resource-manager/synapse/2021-06-01/workspaces/model_workspacepatchinfo.go b/resource-manager/synapse/2021-06-01/workspaces/model_workspacepatchinfo.go new file mode 100644 index 00000000000..201d8dcedcb --- /dev/null +++ b/resource-manager/synapse/2021-06-01/workspaces/model_workspacepatchinfo.go @@ -0,0 +1,10 @@ +package workspaces + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type WorkspacePatchInfo struct { + Identity *ManagedIdentity `json:"identity,omitempty"` + Properties *WorkspacePatchProperties `json:"properties,omitempty"` + Tags *map[string]string `json:"tags,omitempty"` +} diff --git a/resource-manager/synapse/2021-06-01/workspaces/model_workspacepatchproperties.go b/resource-manager/synapse/2021-06-01/workspaces/model_workspacepatchproperties.go new file mode 100644 index 00000000000..4f92c02994d --- /dev/null +++ b/resource-manager/synapse/2021-06-01/workspaces/model_workspacepatchproperties.go @@ -0,0 +1,14 @@ +package workspaces + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type WorkspacePatchProperties struct { + Encryption *EncryptionDetails `json:"encryption,omitempty"` + ManagedVirtualNetworkSettings *ManagedVirtualNetworkSettings `json:"managedVirtualNetworkSettings,omitempty"` + ProvisioningState *string `json:"provisioningState,omitempty"` + PublicNetworkAccess *WorkspacePublicNetworkAccess `json:"publicNetworkAccess,omitempty"` + PurviewConfiguration *PurviewConfiguration `json:"purviewConfiguration,omitempty"` + SqlAdministratorLoginPassword *string `json:"sqlAdministratorLoginPassword,omitempty"` + WorkspaceRepositoryConfiguration *WorkspaceRepositoryConfiguration `json:"workspaceRepositoryConfiguration,omitempty"` +} diff --git a/resource-manager/synapse/2021-06-01/workspaces/model_workspaceproperties.go b/resource-manager/synapse/2021-06-01/workspaces/model_workspaceproperties.go new file mode 100644 index 00000000000..9c6f1f794a2 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/workspaces/model_workspaceproperties.go @@ -0,0 +1,28 @@ +package workspaces + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type WorkspaceProperties struct { + AdlaResourceId *string `json:"adlaResourceId,omitempty"` + AzureADOnlyAuthentication *bool `json:"azureADOnlyAuthentication,omitempty"` + ConnectivityEndpoints *map[string]string `json:"connectivityEndpoints,omitempty"` + CspWorkspaceAdminProperties *CspWorkspaceAdminProperties `json:"cspWorkspaceAdminProperties,omitempty"` + DefaultDataLakeStorage *DataLakeStorageAccountDetails `json:"defaultDataLakeStorage,omitempty"` + Encryption *EncryptionDetails `json:"encryption,omitempty"` + ExtraProperties *interface{} `json:"extraProperties,omitempty"` + ManagedResourceGroupName *string `json:"managedResourceGroupName,omitempty"` + ManagedVirtualNetwork *string `json:"managedVirtualNetwork,omitempty"` + ManagedVirtualNetworkSettings *ManagedVirtualNetworkSettings `json:"managedVirtualNetworkSettings,omitempty"` + PrivateEndpointConnections *[]PrivateEndpointConnection `json:"privateEndpointConnections,omitempty"` + ProvisioningState *string `json:"provisioningState,omitempty"` + PublicNetworkAccess *WorkspacePublicNetworkAccess `json:"publicNetworkAccess,omitempty"` + PurviewConfiguration *PurviewConfiguration `json:"purviewConfiguration,omitempty"` + Settings *map[string]interface{} `json:"settings,omitempty"` + SqlAdministratorLogin *string `json:"sqlAdministratorLogin,omitempty"` + SqlAdministratorLoginPassword *string `json:"sqlAdministratorLoginPassword,omitempty"` + TrustedServiceBypassEnabled *bool `json:"trustedServiceBypassEnabled,omitempty"` + VirtualNetworkProfile *VirtualNetworkProfile `json:"virtualNetworkProfile,omitempty"` + WorkspaceRepositoryConfiguration *WorkspaceRepositoryConfiguration `json:"workspaceRepositoryConfiguration,omitempty"` + WorkspaceUID *string `json:"workspaceUID,omitempty"` +} diff --git a/resource-manager/synapse/2021-06-01/workspaces/model_workspacerepositoryconfiguration.go b/resource-manager/synapse/2021-06-01/workspaces/model_workspacerepositoryconfiguration.go new file mode 100644 index 00000000000..5e895a63b0b --- /dev/null +++ b/resource-manager/synapse/2021-06-01/workspaces/model_workspacerepositoryconfiguration.go @@ -0,0 +1,16 @@ +package workspaces + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type WorkspaceRepositoryConfiguration struct { + AccountName *string `json:"accountName,omitempty"` + CollaborationBranch *string `json:"collaborationBranch,omitempty"` + HostName *string `json:"hostName,omitempty"` + LastCommitId *string `json:"lastCommitId,omitempty"` + ProjectName *string `json:"projectName,omitempty"` + RepositoryName *string `json:"repositoryName,omitempty"` + RootFolder *string `json:"rootFolder,omitempty"` + TenantId *string `json:"tenantId,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/synapse/2021-06-01/workspaces/predicates.go b/resource-manager/synapse/2021-06-01/workspaces/predicates.go new file mode 100644 index 00000000000..487159d40b2 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/workspaces/predicates.go @@ -0,0 +1,32 @@ +package workspaces + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type WorkspaceOperationPredicate struct { + Id *string + Location *string + Name *string + Type *string +} + +func (p WorkspaceOperationPredicate) Matches(input Workspace) bool { + + if p.Id != nil && (input.Id == nil || *p.Id != *input.Id) { + return false + } + + if p.Location != nil && *p.Location != input.Location { + return false + } + + if p.Name != nil && (input.Name == nil || *p.Name != *input.Name) { + return false + } + + if p.Type != nil && (input.Type == nil || *p.Type != *input.Type) { + return false + } + + return true +} diff --git a/resource-manager/synapse/2021-06-01/workspaces/version.go b/resource-manager/synapse/2021-06-01/workspaces/version.go new file mode 100644 index 00000000000..c34ac6065c2 --- /dev/null +++ b/resource-manager/synapse/2021-06-01/workspaces/version.go @@ -0,0 +1,12 @@ +package workspaces + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2021-06-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/workspaces/%s", defaultApiVersion) +}