diff --git a/resource-manager/datafactory/2018-06-01/datasets/model_lakehousetabledatasettypeproperties.go b/resource-manager/datafactory/2018-06-01/datasets/model_lakehousetabledatasettypeproperties.go index 2dca10a473f..6e22afc3f1f 100644 --- a/resource-manager/datafactory/2018-06-01/datasets/model_lakehousetabledatasettypeproperties.go +++ b/resource-manager/datafactory/2018-06-01/datasets/model_lakehousetabledatasettypeproperties.go @@ -4,5 +4,6 @@ package datasets // Licensed under the MIT License. See NOTICE.txt in the project root for license information. type LakeHouseTableDatasetTypeProperties struct { - Table *interface{} `json:"table,omitempty"` + Schema *interface{} `json:"schema,omitempty"` + Table *interface{} `json:"table,omitempty"` } diff --git a/resource-manager/resources/2015-11-01/client.go b/resource-manager/resources/2015-11-01/client.go new file mode 100644 index 00000000000..bda041932db --- /dev/null +++ b/resource-manager/resources/2015-11-01/client.go @@ -0,0 +1,109 @@ +package v2015_11_01 + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/resource-manager/resources/2015-11-01/deploymentoperations" + "github.com/hashicorp/go-azure-sdk/resource-manager/resources/2015-11-01/deployments" + "github.com/hashicorp/go-azure-sdk/resource-manager/resources/2015-11-01/policyassignments" + "github.com/hashicorp/go-azure-sdk/resource-manager/resources/2015-11-01/policydefinitions" + "github.com/hashicorp/go-azure-sdk/resource-manager/resources/2015-11-01/providers" + "github.com/hashicorp/go-azure-sdk/resource-manager/resources/2015-11-01/resourcegroups" + "github.com/hashicorp/go-azure-sdk/resource-manager/resources/2015-11-01/resources" + "github.com/hashicorp/go-azure-sdk/resource-manager/resources/2015-11-01/subscriptions" + "github.com/hashicorp/go-azure-sdk/resource-manager/resources/2015-11-01/tags" + "github.com/hashicorp/go-azure-sdk/resource-manager/resources/2015-11-01/tenants" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +type Client struct { + DeploymentOperations *deploymentoperations.DeploymentOperationsClient + Deployments *deployments.DeploymentsClient + PolicyAssignments *policyassignments.PolicyAssignmentsClient + PolicyDefinitions *policydefinitions.PolicyDefinitionsClient + Providers *providers.ProvidersClient + ResourceGroups *resourcegroups.ResourceGroupsClient + Resources *resources.ResourcesClient + Subscriptions *subscriptions.SubscriptionsClient + Tags *tags.TagsClient + Tenants *tenants.TenantsClient +} + +func NewClientWithBaseURI(sdkApi sdkEnv.Api, configureFunc func(c *resourcemanager.Client)) (*Client, error) { + deploymentOperationsClient, err := deploymentoperations.NewDeploymentOperationsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building DeploymentOperations client: %+v", err) + } + configureFunc(deploymentOperationsClient.Client) + + deploymentsClient, err := deployments.NewDeploymentsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building Deployments client: %+v", err) + } + configureFunc(deploymentsClient.Client) + + policyAssignmentsClient, err := policyassignments.NewPolicyAssignmentsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building PolicyAssignments client: %+v", err) + } + configureFunc(policyAssignmentsClient.Client) + + policyDefinitionsClient, err := policydefinitions.NewPolicyDefinitionsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building PolicyDefinitions client: %+v", err) + } + configureFunc(policyDefinitionsClient.Client) + + providersClient, err := providers.NewProvidersClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building Providers client: %+v", err) + } + configureFunc(providersClient.Client) + + resourceGroupsClient, err := resourcegroups.NewResourceGroupsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building ResourceGroups client: %+v", err) + } + configureFunc(resourceGroupsClient.Client) + + resourcesClient, err := resources.NewResourcesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building Resources client: %+v", err) + } + configureFunc(resourcesClient.Client) + + subscriptionsClient, err := subscriptions.NewSubscriptionsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building Subscriptions client: %+v", err) + } + configureFunc(subscriptionsClient.Client) + + tagsClient, err := tags.NewTagsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building Tags client: %+v", err) + } + configureFunc(tagsClient.Client) + + tenantsClient, err := tenants.NewTenantsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building Tenants client: %+v", err) + } + configureFunc(tenantsClient.Client) + + return &Client{ + DeploymentOperations: deploymentOperationsClient, + Deployments: deploymentsClient, + PolicyAssignments: policyAssignmentsClient, + PolicyDefinitions: policyDefinitionsClient, + Providers: providersClient, + ResourceGroups: resourceGroupsClient, + Resources: resourcesClient, + Subscriptions: subscriptionsClient, + Tags: tagsClient, + Tenants: tenantsClient, + }, nil +} diff --git a/resource-manager/resources/2015-11-01/deploymentoperations/README.md b/resource-manager/resources/2015-11-01/deploymentoperations/README.md new file mode 100644 index 00000000000..6f22dc0725e --- /dev/null +++ b/resource-manager/resources/2015-11-01/deploymentoperations/README.md @@ -0,0 +1,53 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/resources/2015-11-01/deploymentoperations` Documentation + +The `deploymentoperations` SDK allows for interaction with the Azure Resource Manager Service `resources` (API Version `2015-11-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/resources/2015-11-01/deploymentoperations" +``` + + +### Client Initialization + +```go +client := deploymentoperations.NewDeploymentOperationsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `DeploymentOperationsClient.Get` + +```go +ctx := context.TODO() +id := deploymentoperations.NewOperationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "deploymentValue", "operationIdValue") + +read, err := client.Get(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `DeploymentOperationsClient.List` + +```go +ctx := context.TODO() +id := deploymentoperations.NewDeploymentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "deploymentValue") + +// alternatively `client.List(ctx, id, deploymentoperations.DefaultListOperationOptions())` can be used to do batched pagination +items, err := client.ListComplete(ctx, id, deploymentoperations.DefaultListOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/resources/2015-11-01/deploymentoperations/client.go b/resource-manager/resources/2015-11-01/deploymentoperations/client.go new file mode 100644 index 00000000000..c31a3e02609 --- /dev/null +++ b/resource-manager/resources/2015-11-01/deploymentoperations/client.go @@ -0,0 +1,26 @@ +package deploymentoperations + +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 DeploymentOperationsClient struct { + Client *resourcemanager.Client +} + +func NewDeploymentOperationsClientWithBaseURI(sdkApi sdkEnv.Api) (*DeploymentOperationsClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "deploymentoperations", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating DeploymentOperationsClient: %+v", err) + } + + return &DeploymentOperationsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/resources/2015-11-01/deploymentoperations/id_deployment.go b/resource-manager/resources/2015-11-01/deploymentoperations/id_deployment.go new file mode 100644 index 00000000000..1502240c295 --- /dev/null +++ b/resource-manager/resources/2015-11-01/deploymentoperations/id_deployment.go @@ -0,0 +1,128 @@ +package deploymentoperations + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&DeploymentId{}) +} + +var _ resourceids.ResourceId = &DeploymentId{} + +// DeploymentId is a struct representing the Resource ID for a Deployment +type DeploymentId struct { + SubscriptionId string + ResourceGroupName string + DeploymentName string +} + +// NewDeploymentID returns a new DeploymentId struct +func NewDeploymentID(subscriptionId string, resourceGroupName string, deploymentName string) DeploymentId { + return DeploymentId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + DeploymentName: deploymentName, + } +} + +// ParseDeploymentID parses 'input' into a DeploymentId +func ParseDeploymentID(input string) (*DeploymentId, error) { + parser := resourceids.NewParserFromResourceIdType(&DeploymentId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := DeploymentId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseDeploymentIDInsensitively parses 'input' case-insensitively into a DeploymentId +// note: this method should only be used for API response data and not user input +func ParseDeploymentIDInsensitively(input string) (*DeploymentId, error) { + parser := resourceids.NewParserFromResourceIdType(&DeploymentId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := DeploymentId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *DeploymentId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.DeploymentName, ok = input.Parsed["deploymentName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "deploymentName", input) + } + + return nil +} + +// ValidateDeploymentID checks that 'input' can be parsed as a Deployment ID +func ValidateDeploymentID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseDeploymentID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Deployment ID +func (id DeploymentId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/deployments/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.DeploymentName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Deployment ID +func (id DeploymentId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticDeployments", "deployments", "deployments"), + resourceids.UserSpecifiedSegment("deploymentName", "deploymentValue"), + } +} + +// String returns a human-readable description of this Deployment ID +func (id DeploymentId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Deployment Name: %q", id.DeploymentName), + } + return fmt.Sprintf("Deployment (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/resources/2015-11-01/deploymentoperations/id_deployment_test.go b/resource-manager/resources/2015-11-01/deploymentoperations/id_deployment_test.go new file mode 100644 index 00000000000..d6edd8dfe06 --- /dev/null +++ b/resource-manager/resources/2015-11-01/deploymentoperations/id_deployment_test.go @@ -0,0 +1,252 @@ +package deploymentoperations + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &DeploymentId{} + +func TestNewDeploymentID(t *testing.T) { + id := NewDeploymentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "deploymentValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.DeploymentName != "deploymentValue" { + t.Fatalf("Expected %q but got %q for Segment 'DeploymentName'", id.DeploymentName, "deploymentValue") + } +} + +func TestFormatDeploymentID(t *testing.T) { + actual := NewDeploymentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "deploymentValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/deployments/deploymentValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseDeploymentID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *DeploymentId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/deployments", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/deployments/deploymentValue", + Expected: &DeploymentId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + DeploymentName: "deploymentValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/deployments/deploymentValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseDeploymentID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.DeploymentName != v.Expected.DeploymentName { + t.Fatalf("Expected %q but got %q for DeploymentName", v.Expected.DeploymentName, actual.DeploymentName) + } + + } +} + +func TestParseDeploymentIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *DeploymentId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/deployments", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/dEpLoYmEnTs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/deployments/deploymentValue", + Expected: &DeploymentId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + DeploymentName: "deploymentValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/deployments/deploymentValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/dEpLoYmEnTs/dEpLoYmEnTvAlUe", + Expected: &DeploymentId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + DeploymentName: "dEpLoYmEnTvAlUe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/dEpLoYmEnTs/dEpLoYmEnTvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseDeploymentIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.DeploymentName != v.Expected.DeploymentName { + t.Fatalf("Expected %q but got %q for DeploymentName", v.Expected.DeploymentName, actual.DeploymentName) + } + + } +} + +func TestSegmentsForDeploymentId(t *testing.T) { + segments := DeploymentId{}.Segments() + if len(segments) == 0 { + t.Fatalf("DeploymentId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/resources/2015-11-01/deploymentoperations/id_operation.go b/resource-manager/resources/2015-11-01/deploymentoperations/id_operation.go new file mode 100644 index 00000000000..bcc4bcce130 --- /dev/null +++ b/resource-manager/resources/2015-11-01/deploymentoperations/id_operation.go @@ -0,0 +1,137 @@ +package deploymentoperations + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&OperationId{}) +} + +var _ resourceids.ResourceId = &OperationId{} + +// OperationId is a struct representing the Resource ID for a Operation +type OperationId struct { + SubscriptionId string + ResourceGroupName string + DeploymentName string + OperationId string +} + +// NewOperationID returns a new OperationId struct +func NewOperationID(subscriptionId string, resourceGroupName string, deploymentName string, operationId string) OperationId { + return OperationId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + DeploymentName: deploymentName, + OperationId: operationId, + } +} + +// ParseOperationID parses 'input' into a OperationId +func ParseOperationID(input string) (*OperationId, error) { + parser := resourceids.NewParserFromResourceIdType(&OperationId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := OperationId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseOperationIDInsensitively parses 'input' case-insensitively into a OperationId +// note: this method should only be used for API response data and not user input +func ParseOperationIDInsensitively(input string) (*OperationId, error) { + parser := resourceids.NewParserFromResourceIdType(&OperationId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := OperationId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *OperationId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.DeploymentName, ok = input.Parsed["deploymentName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "deploymentName", input) + } + + if id.OperationId, ok = input.Parsed["operationId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "operationId", input) + } + + return nil +} + +// ValidateOperationID checks that 'input' can be parsed as a Operation ID +func ValidateOperationID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseOperationID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Operation ID +func (id OperationId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/deployments/%s/operations/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.DeploymentName, id.OperationId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Operation ID +func (id OperationId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticDeployments", "deployments", "deployments"), + resourceids.UserSpecifiedSegment("deploymentName", "deploymentValue"), + resourceids.StaticSegment("staticOperations", "operations", "operations"), + resourceids.UserSpecifiedSegment("operationId", "operationIdValue"), + } +} + +// String returns a human-readable description of this Operation ID +func (id OperationId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Deployment Name: %q", id.DeploymentName), + fmt.Sprintf("Operation: %q", id.OperationId), + } + return fmt.Sprintf("Operation (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/resources/2015-11-01/deploymentoperations/id_operation_test.go b/resource-manager/resources/2015-11-01/deploymentoperations/id_operation_test.go new file mode 100644 index 00000000000..a5c593a8af1 --- /dev/null +++ b/resource-manager/resources/2015-11-01/deploymentoperations/id_operation_test.go @@ -0,0 +1,297 @@ +package deploymentoperations + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &OperationId{} + +func TestNewOperationID(t *testing.T) { + id := NewOperationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "deploymentValue", "operationIdValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.DeploymentName != "deploymentValue" { + t.Fatalf("Expected %q but got %q for Segment 'DeploymentName'", id.DeploymentName, "deploymentValue") + } + + if id.OperationId != "operationIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'OperationId'", id.OperationId, "operationIdValue") + } +} + +func TestFormatOperationID(t *testing.T) { + actual := NewOperationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "deploymentValue", "operationIdValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/deployments/deploymentValue/operations/operationIdValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseOperationID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *OperationId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/deployments", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/deployments/deploymentValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/deployments/deploymentValue/operations", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/deployments/deploymentValue/operations/operationIdValue", + Expected: &OperationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + DeploymentName: "deploymentValue", + OperationId: "operationIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/deployments/deploymentValue/operations/operationIdValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseOperationID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.DeploymentName != v.Expected.DeploymentName { + t.Fatalf("Expected %q but got %q for DeploymentName", v.Expected.DeploymentName, actual.DeploymentName) + } + + if actual.OperationId != v.Expected.OperationId { + t.Fatalf("Expected %q but got %q for OperationId", v.Expected.OperationId, actual.OperationId) + } + + } +} + +func TestParseOperationIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *OperationId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/deployments", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/dEpLoYmEnTs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/deployments/deploymentValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/dEpLoYmEnTs/dEpLoYmEnTvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/deployments/deploymentValue/operations", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/dEpLoYmEnTs/dEpLoYmEnTvAlUe/oPeRaTiOnS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/deployments/deploymentValue/operations/operationIdValue", + Expected: &OperationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + DeploymentName: "deploymentValue", + OperationId: "operationIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/deployments/deploymentValue/operations/operationIdValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/dEpLoYmEnTs/dEpLoYmEnTvAlUe/oPeRaTiOnS/oPeRaTiOnIdVaLuE", + Expected: &OperationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + DeploymentName: "dEpLoYmEnTvAlUe", + OperationId: "oPeRaTiOnIdVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/dEpLoYmEnTs/dEpLoYmEnTvAlUe/oPeRaTiOnS/oPeRaTiOnIdVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseOperationIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.DeploymentName != v.Expected.DeploymentName { + t.Fatalf("Expected %q but got %q for DeploymentName", v.Expected.DeploymentName, actual.DeploymentName) + } + + if actual.OperationId != v.Expected.OperationId { + t.Fatalf("Expected %q but got %q for OperationId", v.Expected.OperationId, actual.OperationId) + } + + } +} + +func TestSegmentsForOperationId(t *testing.T) { + segments := OperationId{}.Segments() + if len(segments) == 0 { + t.Fatalf("OperationId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/resources/2015-11-01/deploymentoperations/method_get.go b/resource-manager/resources/2015-11-01/deploymentoperations/method_get.go new file mode 100644 index 00000000000..2b719ca0185 --- /dev/null +++ b/resource-manager/resources/2015-11-01/deploymentoperations/method_get.go @@ -0,0 +1,54 @@ +package deploymentoperations + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/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 *DeploymentOperation +} + +// Get ... +func (c DeploymentOperationsClient) Get(ctx context.Context, id OperationId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model DeploymentOperation + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/resources/2015-11-01/deploymentoperations/method_list.go b/resource-manager/resources/2015-11-01/deploymentoperations/method_list.go new file mode 100644 index 00000000000..99f430d5fd6 --- /dev/null +++ b/resource-manager/resources/2015-11-01/deploymentoperations/method_list.go @@ -0,0 +1,119 @@ +package deploymentoperations + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/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 *[]DeploymentOperation +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []DeploymentOperation +} + +type ListOperationOptions struct { + Top *int64 +} + +func DefaultListOperationOptions() ListOperationOptions { + return ListOperationOptions{} +} + +func (o ListOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o ListOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +// List ... +func (c DeploymentOperationsClient) List(ctx context.Context, id DeploymentId, options ListOperationOptions) (result ListOperationResponse, 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()), + 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 *[]DeploymentOperation `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 DeploymentOperationsClient) ListComplete(ctx context.Context, id DeploymentId, options ListOperationOptions) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, options, DeploymentOperationOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c DeploymentOperationsClient) ListCompleteMatchingPredicate(ctx context.Context, id DeploymentId, options ListOperationOptions, predicate DeploymentOperationOperationPredicate) (result ListCompleteResult, err error) { + items := make([]DeploymentOperation, 0) + + resp, err := c.List(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 = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/resources/2015-11-01/deploymentoperations/model_deploymentoperation.go b/resource-manager/resources/2015-11-01/deploymentoperations/model_deploymentoperation.go new file mode 100644 index 00000000000..14a37660832 --- /dev/null +++ b/resource-manager/resources/2015-11-01/deploymentoperations/model_deploymentoperation.go @@ -0,0 +1,10 @@ +package deploymentoperations + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeploymentOperation struct { + Id *string `json:"id,omitempty"` + OperationId *string `json:"operationId,omitempty"` + Properties *DeploymentOperationProperties `json:"properties,omitempty"` +} diff --git a/resource-manager/resources/2015-11-01/deploymentoperations/model_deploymentoperationproperties.go b/resource-manager/resources/2015-11-01/deploymentoperations/model_deploymentoperationproperties.go new file mode 100644 index 00000000000..83a693bc39a --- /dev/null +++ b/resource-manager/resources/2015-11-01/deploymentoperations/model_deploymentoperationproperties.go @@ -0,0 +1,30 @@ +package deploymentoperations + +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 DeploymentOperationProperties struct { + ProvisioningState *string `json:"provisioningState,omitempty"` + StatusCode *string `json:"statusCode,omitempty"` + StatusMessage *interface{} `json:"statusMessage,omitempty"` + TargetResource *TargetResource `json:"targetResource,omitempty"` + Timestamp *string `json:"timestamp,omitempty"` +} + +func (o *DeploymentOperationProperties) GetTimestampAsTime() (*time.Time, error) { + if o.Timestamp == nil { + return nil, nil + } + return dates.ParseAsFormat(o.Timestamp, "2006-01-02T15:04:05Z07:00") +} + +func (o *DeploymentOperationProperties) SetTimestampAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.Timestamp = &formatted +} diff --git a/resource-manager/resources/2015-11-01/deploymentoperations/model_targetresource.go b/resource-manager/resources/2015-11-01/deploymentoperations/model_targetresource.go new file mode 100644 index 00000000000..ffd4767b362 --- /dev/null +++ b/resource-manager/resources/2015-11-01/deploymentoperations/model_targetresource.go @@ -0,0 +1,10 @@ +package deploymentoperations + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type TargetResource struct { + Id *string `json:"id,omitempty"` + ResourceName *string `json:"resourceName,omitempty"` + ResourceType *string `json:"resourceType,omitempty"` +} diff --git a/resource-manager/resources/2015-11-01/deploymentoperations/predicates.go b/resource-manager/resources/2015-11-01/deploymentoperations/predicates.go new file mode 100644 index 00000000000..8481a87fa68 --- /dev/null +++ b/resource-manager/resources/2015-11-01/deploymentoperations/predicates.go @@ -0,0 +1,22 @@ +package deploymentoperations + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeploymentOperationOperationPredicate struct { + Id *string + OperationId *string +} + +func (p DeploymentOperationOperationPredicate) Matches(input DeploymentOperation) bool { + + if p.Id != nil && (input.Id == nil || *p.Id != *input.Id) { + return false + } + + if p.OperationId != nil && (input.OperationId == nil || *p.OperationId != *input.OperationId) { + return false + } + + return true +} diff --git a/resource-manager/resources/2015-11-01/deploymentoperations/version.go b/resource-manager/resources/2015-11-01/deploymentoperations/version.go new file mode 100644 index 00000000000..8a4eac8b834 --- /dev/null +++ b/resource-manager/resources/2015-11-01/deploymentoperations/version.go @@ -0,0 +1,12 @@ +package deploymentoperations + +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 = "2015-11-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/deploymentoperations/%s", defaultApiVersion) +} diff --git a/resource-manager/resources/2015-11-01/deployments/README.md b/resource-manager/resources/2015-11-01/deployments/README.md new file mode 100644 index 00000000000..dad03e6e9c1 --- /dev/null +++ b/resource-manager/resources/2015-11-01/deployments/README.md @@ -0,0 +1,152 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/resources/2015-11-01/deployments` Documentation + +The `deployments` SDK allows for interaction with the Azure Resource Manager Service `resources` (API Version `2015-11-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +import "github.com/hashicorp/go-azure-sdk/resource-manager/resources/2015-11-01/deployments" +``` + + +### Client Initialization + +```go +client := deployments.NewDeploymentsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `DeploymentsClient.CalculateTemplateHash` + +```go +ctx := context.TODO() +var payload interface{} + +read, err := client.CalculateTemplateHash(ctx, payload) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `DeploymentsClient.Cancel` + +```go +ctx := context.TODO() +id := deployments.NewProviderDeploymentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "deploymentValue") + +read, err := client.Cancel(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `DeploymentsClient.CheckExistence` + +```go +ctx := context.TODO() +id := deployments.NewProviderDeploymentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "deploymentValue") + +read, err := client.CheckExistence(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `DeploymentsClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := deployments.NewProviderDeploymentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "deploymentValue") + +payload := deployments.Deployment{ + // ... +} + + +if err := client.CreateOrUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `DeploymentsClient.Delete` + +```go +ctx := context.TODO() +id := deployments.NewProviderDeploymentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "deploymentValue") + +if err := client.DeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `DeploymentsClient.Get` + +```go +ctx := context.TODO() +id := deployments.NewProviderDeploymentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "deploymentValue") + +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: `DeploymentsClient.List` + +```go +ctx := context.TODO() +id := commonids.NewResourceGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group") + +// alternatively `client.List(ctx, id, deployments.DefaultListOperationOptions())` can be used to do batched pagination +items, err := client.ListComplete(ctx, id, deployments.DefaultListOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `DeploymentsClient.Validate` + +```go +ctx := context.TODO() +id := deployments.NewProviderDeploymentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "deploymentValue") + +payload := deployments.Deployment{ + // ... +} + + +read, err := client.Validate(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/resources/2015-11-01/deployments/client.go b/resource-manager/resources/2015-11-01/deployments/client.go new file mode 100644 index 00000000000..50a604559bd --- /dev/null +++ b/resource-manager/resources/2015-11-01/deployments/client.go @@ -0,0 +1,26 @@ +package deployments + +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 DeploymentsClient struct { + Client *resourcemanager.Client +} + +func NewDeploymentsClientWithBaseURI(sdkApi sdkEnv.Api) (*DeploymentsClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "deployments", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating DeploymentsClient: %+v", err) + } + + return &DeploymentsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/resources/2015-11-01/deployments/constants.go b/resource-manager/resources/2015-11-01/deployments/constants.go new file mode 100644 index 00000000000..f91b7a0ac9c --- /dev/null +++ b/resource-manager/resources/2015-11-01/deployments/constants.go @@ -0,0 +1,51 @@ +package deployments + +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 DeploymentMode string + +const ( + DeploymentModeComplete DeploymentMode = "Complete" + DeploymentModeIncremental DeploymentMode = "Incremental" +) + +func PossibleValuesForDeploymentMode() []string { + return []string{ + string(DeploymentModeComplete), + string(DeploymentModeIncremental), + } +} + +func (s *DeploymentMode) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseDeploymentMode(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseDeploymentMode(input string) (*DeploymentMode, error) { + vals := map[string]DeploymentMode{ + "complete": DeploymentModeComplete, + "incremental": DeploymentModeIncremental, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := DeploymentMode(input) + return &out, nil +} diff --git a/resource-manager/resources/2015-11-01/deployments/id_providerdeployment.go b/resource-manager/resources/2015-11-01/deployments/id_providerdeployment.go new file mode 100644 index 00000000000..e9f98a04a58 --- /dev/null +++ b/resource-manager/resources/2015-11-01/deployments/id_providerdeployment.go @@ -0,0 +1,130 @@ +package deployments + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ProviderDeploymentId{}) +} + +var _ resourceids.ResourceId = &ProviderDeploymentId{} + +// ProviderDeploymentId is a struct representing the Resource ID for a Provider Deployment +type ProviderDeploymentId struct { + SubscriptionId string + ResourceGroupName string + DeploymentName string +} + +// NewProviderDeploymentID returns a new ProviderDeploymentId struct +func NewProviderDeploymentID(subscriptionId string, resourceGroupName string, deploymentName string) ProviderDeploymentId { + return ProviderDeploymentId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + DeploymentName: deploymentName, + } +} + +// ParseProviderDeploymentID parses 'input' into a ProviderDeploymentId +func ParseProviderDeploymentID(input string) (*ProviderDeploymentId, error) { + parser := resourceids.NewParserFromResourceIdType(&ProviderDeploymentId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ProviderDeploymentId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseProviderDeploymentIDInsensitively parses 'input' case-insensitively into a ProviderDeploymentId +// note: this method should only be used for API response data and not user input +func ParseProviderDeploymentIDInsensitively(input string) (*ProviderDeploymentId, error) { + parser := resourceids.NewParserFromResourceIdType(&ProviderDeploymentId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ProviderDeploymentId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ProviderDeploymentId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.DeploymentName, ok = input.Parsed["deploymentName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "deploymentName", input) + } + + return nil +} + +// ValidateProviderDeploymentID checks that 'input' can be parsed as a Provider Deployment ID +func ValidateProviderDeploymentID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseProviderDeploymentID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Provider Deployment ID +func (id ProviderDeploymentId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Resources/deployments/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.DeploymentName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Provider Deployment ID +func (id ProviderDeploymentId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftResources", "Microsoft.Resources", "Microsoft.Resources"), + resourceids.StaticSegment("staticDeployments", "deployments", "deployments"), + resourceids.UserSpecifiedSegment("deploymentName", "deploymentValue"), + } +} + +// String returns a human-readable description of this Provider Deployment ID +func (id ProviderDeploymentId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Deployment Name: %q", id.DeploymentName), + } + return fmt.Sprintf("Provider Deployment (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/resources/2015-11-01/deployments/id_providerdeployment_test.go b/resource-manager/resources/2015-11-01/deployments/id_providerdeployment_test.go new file mode 100644 index 00000000000..2efbda19af1 --- /dev/null +++ b/resource-manager/resources/2015-11-01/deployments/id_providerdeployment_test.go @@ -0,0 +1,282 @@ +package deployments + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &ProviderDeploymentId{} + +func TestNewProviderDeploymentID(t *testing.T) { + id := NewProviderDeploymentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "deploymentValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.DeploymentName != "deploymentValue" { + t.Fatalf("Expected %q but got %q for Segment 'DeploymentName'", id.DeploymentName, "deploymentValue") + } +} + +func TestFormatProviderDeploymentID(t *testing.T) { + actual := NewProviderDeploymentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "deploymentValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Resources/deployments/deploymentValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseProviderDeploymentID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ProviderDeploymentId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Resources", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Resources/deployments", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Resources/deployments/deploymentValue", + Expected: &ProviderDeploymentId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + DeploymentName: "deploymentValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Resources/deployments/deploymentValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseProviderDeploymentID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.DeploymentName != v.Expected.DeploymentName { + t.Fatalf("Expected %q but got %q for DeploymentName", v.Expected.DeploymentName, actual.DeploymentName) + } + + } +} + +func TestParseProviderDeploymentIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ProviderDeploymentId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Resources", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEsOuRcEs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Resources/deployments", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEsOuRcEs/dEpLoYmEnTs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Resources/deployments/deploymentValue", + Expected: &ProviderDeploymentId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + DeploymentName: "deploymentValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Resources/deployments/deploymentValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEsOuRcEs/dEpLoYmEnTs/dEpLoYmEnTvAlUe", + Expected: &ProviderDeploymentId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + DeploymentName: "dEpLoYmEnTvAlUe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.rEsOuRcEs/dEpLoYmEnTs/dEpLoYmEnTvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseProviderDeploymentIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.DeploymentName != v.Expected.DeploymentName { + t.Fatalf("Expected %q but got %q for DeploymentName", v.Expected.DeploymentName, actual.DeploymentName) + } + + } +} + +func TestSegmentsForProviderDeploymentId(t *testing.T) { + segments := ProviderDeploymentId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ProviderDeploymentId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/resources/2015-11-01/deployments/method_calculatetemplatehash.go b/resource-manager/resources/2015-11-01/deployments/method_calculatetemplatehash.go new file mode 100644 index 00000000000..3f692d3f3f8 --- /dev/null +++ b/resource-manager/resources/2015-11-01/deployments/method_calculatetemplatehash.go @@ -0,0 +1,58 @@ +package deployments + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CalculateTemplateHashOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *TemplateHashResult +} + +// CalculateTemplateHash ... +func (c DeploymentsClient) CalculateTemplateHash(ctx context.Context, input interface{}) (result CalculateTemplateHashOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: "/providers/Microsoft.Resources/calculateTemplateHash", + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model TemplateHashResult + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/resources/2015-11-01/deployments/method_cancel.go b/resource-manager/resources/2015-11-01/deployments/method_cancel.go new file mode 100644 index 00000000000..807120d0923 --- /dev/null +++ b/resource-manager/resources/2015-11-01/deployments/method_cancel.go @@ -0,0 +1,47 @@ +package deployments + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CancelOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// Cancel ... +func (c DeploymentsClient) Cancel(ctx context.Context, id ProviderDeploymentId) (result CancelOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/cancel", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + 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/resources/2015-11-01/deployments/method_checkexistence.go b/resource-manager/resources/2015-11-01/deployments/method_checkexistence.go new file mode 100644 index 00000000000..d1a2429e66d --- /dev/null +++ b/resource-manager/resources/2015-11-01/deployments/method_checkexistence.go @@ -0,0 +1,46 @@ +package deployments + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CheckExistenceOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// CheckExistence ... +func (c DeploymentsClient) CheckExistence(ctx context.Context, id ProviderDeploymentId) (result CheckExistenceOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + }, + HttpMethod: http.MethodHead, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/resources/2015-11-01/deployments/method_createorupdate.go b/resource-manager/resources/2015-11-01/deployments/method_createorupdate.go new file mode 100644 index 00000000000..7ae988ffb12 --- /dev/null +++ b/resource-manager/resources/2015-11-01/deployments/method_createorupdate.go @@ -0,0 +1,75 @@ +package deployments + +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 *DeploymentExtended +} + +// CreateOrUpdate ... +func (c DeploymentsClient) CreateOrUpdate(ctx context.Context, id ProviderDeploymentId, input Deployment) (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 DeploymentsClient) CreateOrUpdateThenPoll(ctx context.Context, id ProviderDeploymentId, input Deployment) 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/resources/2015-11-01/deployments/method_delete.go b/resource-manager/resources/2015-11-01/deployments/method_delete.go new file mode 100644 index 00000000000..ef5c9f587c0 --- /dev/null +++ b/resource-manager/resources/2015-11-01/deployments/method_delete.go @@ -0,0 +1,70 @@ +package deployments + +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 DeploymentsClient) Delete(ctx context.Context, id ProviderDeploymentId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusNoContent, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// DeleteThenPoll performs Delete then polls until it's completed +func (c DeploymentsClient) DeleteThenPoll(ctx context.Context, id ProviderDeploymentId) 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/resources/2015-11-01/deployments/method_get.go b/resource-manager/resources/2015-11-01/deployments/method_get.go new file mode 100644 index 00000000000..ea261c3fa8c --- /dev/null +++ b/resource-manager/resources/2015-11-01/deployments/method_get.go @@ -0,0 +1,54 @@ +package deployments + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/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 *DeploymentExtended +} + +// Get ... +func (c DeploymentsClient) Get(ctx context.Context, id ProviderDeploymentId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model DeploymentExtended + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/resources/2015-11-01/deployments/method_list.go b/resource-manager/resources/2015-11-01/deployments/method_list.go new file mode 100644 index 00000000000..ee60fdb146a --- /dev/null +++ b/resource-manager/resources/2015-11-01/deployments/method_list.go @@ -0,0 +1,124 @@ +package deployments + +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 *[]DeploymentExtended +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []DeploymentExtended +} + +type ListOperationOptions struct { + Filter *string + Top *int64 +} + +func DefaultListOperationOptions() ListOperationOptions { + return ListOperationOptions{} +} + +func (o ListOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o ListOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +// List ... +func (c DeploymentsClient) List(ctx context.Context, id commonids.ResourceGroupId, options ListOperationOptions) (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.Resources/deployments", 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 *[]DeploymentExtended `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 DeploymentsClient) ListComplete(ctx context.Context, id commonids.ResourceGroupId, options ListOperationOptions) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, options, DeploymentExtendedOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c DeploymentsClient) ListCompleteMatchingPredicate(ctx context.Context, id commonids.ResourceGroupId, options ListOperationOptions, predicate DeploymentExtendedOperationPredicate) (result ListCompleteResult, err error) { + items := make([]DeploymentExtended, 0) + + resp, err := c.List(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 = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/resources/2015-11-01/deployments/method_validate.go b/resource-manager/resources/2015-11-01/deployments/method_validate.go new file mode 100644 index 00000000000..a31aae3d827 --- /dev/null +++ b/resource-manager/resources/2015-11-01/deployments/method_validate.go @@ -0,0 +1,59 @@ +package deployments + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ValidateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *DeploymentValidateResult +} + +// Validate ... +func (c DeploymentsClient) Validate(ctx context.Context, id ProviderDeploymentId, input Deployment) (result ValidateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/validate", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model DeploymentValidateResult + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/resources/2015-11-01/deployments/model_basicdependency.go b/resource-manager/resources/2015-11-01/deployments/model_basicdependency.go new file mode 100644 index 00000000000..151f1c0247c --- /dev/null +++ b/resource-manager/resources/2015-11-01/deployments/model_basicdependency.go @@ -0,0 +1,10 @@ +package deployments + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type BasicDependency struct { + Id *string `json:"id,omitempty"` + ResourceName *string `json:"resourceName,omitempty"` + ResourceType *string `json:"resourceType,omitempty"` +} diff --git a/resource-manager/resources/2015-11-01/deployments/model_dependency.go b/resource-manager/resources/2015-11-01/deployments/model_dependency.go new file mode 100644 index 00000000000..e700824cc96 --- /dev/null +++ b/resource-manager/resources/2015-11-01/deployments/model_dependency.go @@ -0,0 +1,11 @@ +package deployments + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Dependency struct { + DependsOn *[]BasicDependency `json:"dependsOn,omitempty"` + Id *string `json:"id,omitempty"` + ResourceName *string `json:"resourceName,omitempty"` + ResourceType *string `json:"resourceType,omitempty"` +} diff --git a/resource-manager/resources/2015-11-01/deployments/model_deployment.go b/resource-manager/resources/2015-11-01/deployments/model_deployment.go new file mode 100644 index 00000000000..f5ed4c320a5 --- /dev/null +++ b/resource-manager/resources/2015-11-01/deployments/model_deployment.go @@ -0,0 +1,8 @@ +package deployments + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Deployment struct { + Properties *DeploymentProperties `json:"properties,omitempty"` +} diff --git a/resource-manager/resources/2015-11-01/deployments/model_deploymentextended.go b/resource-manager/resources/2015-11-01/deployments/model_deploymentextended.go new file mode 100644 index 00000000000..8b9e5ab98ba --- /dev/null +++ b/resource-manager/resources/2015-11-01/deployments/model_deploymentextended.go @@ -0,0 +1,10 @@ +package deployments + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeploymentExtended struct { + Id *string `json:"id,omitempty"` + Name string `json:"name"` + Properties *DeploymentPropertiesExtended `json:"properties,omitempty"` +} diff --git a/resource-manager/resources/2015-11-01/deployments/model_deploymentproperties.go b/resource-manager/resources/2015-11-01/deployments/model_deploymentproperties.go new file mode 100644 index 00000000000..647f1ecb553 --- /dev/null +++ b/resource-manager/resources/2015-11-01/deployments/model_deploymentproperties.go @@ -0,0 +1,12 @@ +package deployments + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeploymentProperties struct { + Mode *DeploymentMode `json:"mode,omitempty"` + Parameters *interface{} `json:"parameters,omitempty"` + ParametersLink *ParametersLink `json:"parametersLink,omitempty"` + Template *interface{} `json:"template,omitempty"` + TemplateLink *TemplateLink `json:"templateLink,omitempty"` +} diff --git a/resource-manager/resources/2015-11-01/deployments/model_deploymentpropertiesextended.go b/resource-manager/resources/2015-11-01/deployments/model_deploymentpropertiesextended.go new file mode 100644 index 00000000000..554a8962271 --- /dev/null +++ b/resource-manager/resources/2015-11-01/deployments/model_deploymentpropertiesextended.go @@ -0,0 +1,37 @@ +package deployments + +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 DeploymentPropertiesExtended struct { + CorrelationId *string `json:"correlationId,omitempty"` + Dependencies *[]Dependency `json:"dependencies,omitempty"` + Error *ErrorResponse `json:"error,omitempty"` + Mode *DeploymentMode `json:"mode,omitempty"` + Outputs *interface{} `json:"outputs,omitempty"` + Parameters *interface{} `json:"parameters,omitempty"` + ParametersLink *ParametersLink `json:"parametersLink,omitempty"` + Providers *[]Provider `json:"providers,omitempty"` + ProvisioningState *string `json:"provisioningState,omitempty"` + Template *interface{} `json:"template,omitempty"` + TemplateLink *TemplateLink `json:"templateLink,omitempty"` + Timestamp *string `json:"timestamp,omitempty"` +} + +func (o *DeploymentPropertiesExtended) GetTimestampAsTime() (*time.Time, error) { + if o.Timestamp == nil { + return nil, nil + } + return dates.ParseAsFormat(o.Timestamp, "2006-01-02T15:04:05Z07:00") +} + +func (o *DeploymentPropertiesExtended) SetTimestampAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.Timestamp = &formatted +} diff --git a/resource-manager/resources/2015-11-01/deployments/model_deploymentvalidateresult.go b/resource-manager/resources/2015-11-01/deployments/model_deploymentvalidateresult.go new file mode 100644 index 00000000000..cae551d26ac --- /dev/null +++ b/resource-manager/resources/2015-11-01/deployments/model_deploymentvalidateresult.go @@ -0,0 +1,9 @@ +package deployments + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeploymentValidateResult struct { + Error *ResourceManagementErrorWithDetails `json:"error,omitempty"` + Properties *DeploymentPropertiesExtended `json:"properties,omitempty"` +} diff --git a/resource-manager/resources/2015-11-01/deployments/model_erroradditionalinfo.go b/resource-manager/resources/2015-11-01/deployments/model_erroradditionalinfo.go new file mode 100644 index 00000000000..79931ec15fa --- /dev/null +++ b/resource-manager/resources/2015-11-01/deployments/model_erroradditionalinfo.go @@ -0,0 +1,9 @@ +package deployments + +// 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/resources/2015-11-01/deployments/model_errorresponse.go b/resource-manager/resources/2015-11-01/deployments/model_errorresponse.go new file mode 100644 index 00000000000..138e7832440 --- /dev/null +++ b/resource-manager/resources/2015-11-01/deployments/model_errorresponse.go @@ -0,0 +1,12 @@ +package deployments + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ErrorResponse struct { + AdditionalInfo *[]ErrorAdditionalInfo `json:"additionalInfo,omitempty"` + Code *string `json:"code,omitempty"` + Details *[]ErrorResponse `json:"details,omitempty"` + Message *string `json:"message,omitempty"` + Target *string `json:"target,omitempty"` +} diff --git a/resource-manager/resources/2015-11-01/deployments/model_parameterslink.go b/resource-manager/resources/2015-11-01/deployments/model_parameterslink.go new file mode 100644 index 00000000000..a17ec8eadcc --- /dev/null +++ b/resource-manager/resources/2015-11-01/deployments/model_parameterslink.go @@ -0,0 +1,9 @@ +package deployments + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ParametersLink struct { + ContentVersion *string `json:"contentVersion,omitempty"` + Uri string `json:"uri"` +} diff --git a/resource-manager/resources/2015-11-01/deployments/model_provider.go b/resource-manager/resources/2015-11-01/deployments/model_provider.go new file mode 100644 index 00000000000..e5a5fa0dfdb --- /dev/null +++ b/resource-manager/resources/2015-11-01/deployments/model_provider.go @@ -0,0 +1,11 @@ +package deployments + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Provider struct { + Id *string `json:"id,omitempty"` + Namespace *string `json:"namespace,omitempty"` + RegistrationState *string `json:"registrationState,omitempty"` + ResourceTypes *[]ProviderResourceType `json:"resourceTypes,omitempty"` +} diff --git a/resource-manager/resources/2015-11-01/deployments/model_providerresourcetype.go b/resource-manager/resources/2015-11-01/deployments/model_providerresourcetype.go new file mode 100644 index 00000000000..0a300d70c7d --- /dev/null +++ b/resource-manager/resources/2015-11-01/deployments/model_providerresourcetype.go @@ -0,0 +1,11 @@ +package deployments + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ProviderResourceType struct { + ApiVersions *[]string `json:"apiVersions,omitempty"` + Locations *[]string `json:"locations,omitempty"` + Properties *map[string]string `json:"properties,omitempty"` + ResourceType *string `json:"resourceType,omitempty"` +} diff --git a/resource-manager/resources/2015-11-01/deployments/model_resourcemanagementerror.go b/resource-manager/resources/2015-11-01/deployments/model_resourcemanagementerror.go new file mode 100644 index 00000000000..55372e8e8cc --- /dev/null +++ b/resource-manager/resources/2015-11-01/deployments/model_resourcemanagementerror.go @@ -0,0 +1,10 @@ +package deployments + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ResourceManagementError struct { + Code string `json:"code"` + Message string `json:"message"` + Target *string `json:"target,omitempty"` +} diff --git a/resource-manager/resources/2015-11-01/deployments/model_resourcemanagementerrorwithdetails.go b/resource-manager/resources/2015-11-01/deployments/model_resourcemanagementerrorwithdetails.go new file mode 100644 index 00000000000..5ea43207b8a --- /dev/null +++ b/resource-manager/resources/2015-11-01/deployments/model_resourcemanagementerrorwithdetails.go @@ -0,0 +1,11 @@ +package deployments + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ResourceManagementErrorWithDetails struct { + Code string `json:"code"` + Details *[]ResourceManagementError `json:"details,omitempty"` + Message string `json:"message"` + Target *string `json:"target,omitempty"` +} diff --git a/resource-manager/resources/2015-11-01/deployments/model_templatehashresult.go b/resource-manager/resources/2015-11-01/deployments/model_templatehashresult.go new file mode 100644 index 00000000000..baebdeb77e3 --- /dev/null +++ b/resource-manager/resources/2015-11-01/deployments/model_templatehashresult.go @@ -0,0 +1,9 @@ +package deployments + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type TemplateHashResult struct { + MinifiedTemplate *string `json:"minifiedTemplate,omitempty"` + TemplateHash *string `json:"templateHash,omitempty"` +} diff --git a/resource-manager/resources/2015-11-01/deployments/model_templatelink.go b/resource-manager/resources/2015-11-01/deployments/model_templatelink.go new file mode 100644 index 00000000000..7fa4e4b35de --- /dev/null +++ b/resource-manager/resources/2015-11-01/deployments/model_templatelink.go @@ -0,0 +1,9 @@ +package deployments + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type TemplateLink struct { + ContentVersion *string `json:"contentVersion,omitempty"` + Uri string `json:"uri"` +} diff --git a/resource-manager/resources/2015-11-01/deployments/predicates.go b/resource-manager/resources/2015-11-01/deployments/predicates.go new file mode 100644 index 00000000000..c25441f911e --- /dev/null +++ b/resource-manager/resources/2015-11-01/deployments/predicates.go @@ -0,0 +1,22 @@ +package deployments + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeploymentExtendedOperationPredicate struct { + Id *string + Name *string +} + +func (p DeploymentExtendedOperationPredicate) Matches(input DeploymentExtended) bool { + + if p.Id != nil && (input.Id == nil || *p.Id != *input.Id) { + return false + } + + if p.Name != nil && *p.Name != input.Name { + return false + } + + return true +} diff --git a/resource-manager/resources/2015-11-01/deployments/version.go b/resource-manager/resources/2015-11-01/deployments/version.go new file mode 100644 index 00000000000..f9ff922f50b --- /dev/null +++ b/resource-manager/resources/2015-11-01/deployments/version.go @@ -0,0 +1,12 @@ +package deployments + +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 = "2015-11-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/deployments/%s", defaultApiVersion) +} diff --git a/resource-manager/resources/2015-11-01/policyassignments/README.md b/resource-manager/resources/2015-11-01/policyassignments/README.md new file mode 100644 index 00000000000..24c1713edb3 --- /dev/null +++ b/resource-manager/resources/2015-11-01/policyassignments/README.md @@ -0,0 +1,195 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/resources/2015-11-01/policyassignments` Documentation + +The `policyassignments` SDK allows for interaction with the Azure Resource Manager Service `resources` (API Version `2015-11-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +import "github.com/hashicorp/go-azure-sdk/resource-manager/resources/2015-11-01/policyassignments" +``` + + +### Client Initialization + +```go +client := policyassignments.NewPolicyAssignmentsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `PolicyAssignmentsClient.Create` + +```go +ctx := context.TODO() +id := policyassignments.NewScopedPolicyAssignmentID("/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", "policyAssignmentValue") + +payload := policyassignments.PolicyAssignment{ + // ... +} + + +read, err := client.Create(ctx, id, payload) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `PolicyAssignmentsClient.CreateById` + +```go +ctx := context.TODO() +id := policyassignments.NewPolicyAssignmentIdID("policyAssignmentIdValue") + +payload := policyassignments.PolicyAssignment{ + // ... +} + + +read, err := client.CreateById(ctx, id, payload) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `PolicyAssignmentsClient.Delete` + +```go +ctx := context.TODO() +id := policyassignments.NewScopedPolicyAssignmentID("/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", "policyAssignmentValue") + +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: `PolicyAssignmentsClient.DeleteById` + +```go +ctx := context.TODO() +id := policyassignments.NewPolicyAssignmentIdID("policyAssignmentIdValue") + +read, err := client.DeleteById(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `PolicyAssignmentsClient.Get` + +```go +ctx := context.TODO() +id := policyassignments.NewScopedPolicyAssignmentID("/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", "policyAssignmentValue") + +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: `PolicyAssignmentsClient.GetById` + +```go +ctx := context.TODO() +id := policyassignments.NewPolicyAssignmentIdID("policyAssignmentIdValue") + +read, err := client.GetById(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `PolicyAssignmentsClient.List` + +```go +ctx := context.TODO() +id := commonids.NewSubscriptionID("12345678-1234-9876-4563-123456789012") + +// alternatively `client.List(ctx, id, policyassignments.DefaultListOperationOptions())` can be used to do batched pagination +items, err := client.ListComplete(ctx, id, policyassignments.DefaultListOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `PolicyAssignmentsClient.ListForResource` + +```go +ctx := context.TODO() +id := commonids.NewScopeID("/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group") + +// alternatively `client.ListForResource(ctx, id, policyassignments.DefaultListForResourceOperationOptions())` can be used to do batched pagination +items, err := client.ListForResourceComplete(ctx, id, policyassignments.DefaultListForResourceOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `PolicyAssignmentsClient.ListForResourceGroup` + +```go +ctx := context.TODO() +id := commonids.NewResourceGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group") + +// alternatively `client.ListForResourceGroup(ctx, id, policyassignments.DefaultListForResourceGroupOperationOptions())` can be used to do batched pagination +items, err := client.ListForResourceGroupComplete(ctx, id, policyassignments.DefaultListForResourceGroupOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `PolicyAssignmentsClient.ListForScope` + +```go +ctx := context.TODO() +id := commonids.NewScopeID("/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group") + +// alternatively `client.ListForScope(ctx, id, policyassignments.DefaultListForScopeOperationOptions())` can be used to do batched pagination +items, err := client.ListForScopeComplete(ctx, id, policyassignments.DefaultListForScopeOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/resources/2015-11-01/policyassignments/client.go b/resource-manager/resources/2015-11-01/policyassignments/client.go new file mode 100644 index 00000000000..8e17cddc4c7 --- /dev/null +++ b/resource-manager/resources/2015-11-01/policyassignments/client.go @@ -0,0 +1,26 @@ +package policyassignments + +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 PolicyAssignmentsClient struct { + Client *resourcemanager.Client +} + +func NewPolicyAssignmentsClientWithBaseURI(sdkApi sdkEnv.Api) (*PolicyAssignmentsClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "policyassignments", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating PolicyAssignmentsClient: %+v", err) + } + + return &PolicyAssignmentsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/resources/2015-11-01/policyassignments/id_policyassignmentid.go b/resource-manager/resources/2015-11-01/policyassignments/id_policyassignmentid.go new file mode 100644 index 00000000000..dd4c7ddf9b7 --- /dev/null +++ b/resource-manager/resources/2015-11-01/policyassignments/id_policyassignmentid.go @@ -0,0 +1,109 @@ +package policyassignments + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&PolicyAssignmentIdId{}) +} + +var _ resourceids.ResourceId = &PolicyAssignmentIdId{} + +// PolicyAssignmentIdId is a struct representing the Resource ID for a Policy Assignment Id +type PolicyAssignmentIdId struct { + PolicyAssignmentId string +} + +// NewPolicyAssignmentIdID returns a new PolicyAssignmentIdId struct +func NewPolicyAssignmentIdID(policyAssignmentId string) PolicyAssignmentIdId { + return PolicyAssignmentIdId{ + PolicyAssignmentId: policyAssignmentId, + } +} + +// ParsePolicyAssignmentIdID parses 'input' into a PolicyAssignmentIdId +func ParsePolicyAssignmentIdID(input string) (*PolicyAssignmentIdId, error) { + parser := resourceids.NewParserFromResourceIdType(&PolicyAssignmentIdId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := PolicyAssignmentIdId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParsePolicyAssignmentIdIDInsensitively parses 'input' case-insensitively into a PolicyAssignmentIdId +// note: this method should only be used for API response data and not user input +func ParsePolicyAssignmentIdIDInsensitively(input string) (*PolicyAssignmentIdId, error) { + parser := resourceids.NewParserFromResourceIdType(&PolicyAssignmentIdId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := PolicyAssignmentIdId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *PolicyAssignmentIdId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.PolicyAssignmentId, ok = input.Parsed["policyAssignmentId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "policyAssignmentId", input) + } + + return nil +} + +// ValidatePolicyAssignmentIdID checks that 'input' can be parsed as a Policy Assignment Id ID +func ValidatePolicyAssignmentIdID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParsePolicyAssignmentIdID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Policy Assignment Id ID +func (id PolicyAssignmentIdId) ID() string { + fmtString := "/%s" + return fmt.Sprintf(fmtString, id.PolicyAssignmentId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Policy Assignment Id ID +func (id PolicyAssignmentIdId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.UserSpecifiedSegment("policyAssignmentId", "policyAssignmentIdValue"), + } +} + +// String returns a human-readable description of this Policy Assignment Id ID +func (id PolicyAssignmentIdId) String() string { + components := []string{ + fmt.Sprintf("Policy Assignment: %q", id.PolicyAssignmentId), + } + return fmt.Sprintf("Policy Assignment Id (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/resources/2015-11-01/policyassignments/id_policyassignmentid_test.go b/resource-manager/resources/2015-11-01/policyassignments/id_policyassignmentid_test.go new file mode 100644 index 00000000000..604fe6149ad --- /dev/null +++ b/resource-manager/resources/2015-11-01/policyassignments/id_policyassignmentid_test.go @@ -0,0 +1,147 @@ +package policyassignments + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &PolicyAssignmentIdId{} + +func TestNewPolicyAssignmentIdID(t *testing.T) { + id := NewPolicyAssignmentIdID("policyAssignmentIdValue") + + if id.PolicyAssignmentId != "policyAssignmentIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'PolicyAssignmentId'", id.PolicyAssignmentId, "policyAssignmentIdValue") + } +} + +func TestFormatPolicyAssignmentIdID(t *testing.T) { + actual := NewPolicyAssignmentIdID("policyAssignmentIdValue").ID() + expected := "/policyAssignmentIdValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParsePolicyAssignmentIdID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *PolicyAssignmentIdId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Valid URI + Input: "/policyAssignmentIdValue", + Expected: &PolicyAssignmentIdId{ + PolicyAssignmentId: "policyAssignmentIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/policyAssignmentIdValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParsePolicyAssignmentIdID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.PolicyAssignmentId != v.Expected.PolicyAssignmentId { + t.Fatalf("Expected %q but got %q for PolicyAssignmentId", v.Expected.PolicyAssignmentId, actual.PolicyAssignmentId) + } + + } +} + +func TestParsePolicyAssignmentIdIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *PolicyAssignmentIdId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Valid URI + Input: "/policyAssignmentIdValue", + Expected: &PolicyAssignmentIdId{ + PolicyAssignmentId: "policyAssignmentIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/policyAssignmentIdValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/pOlIcYaSsIgNmEnTiDvAlUe", + Expected: &PolicyAssignmentIdId{ + PolicyAssignmentId: "pOlIcYaSsIgNmEnTiDvAlUe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/pOlIcYaSsIgNmEnTiDvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParsePolicyAssignmentIdIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.PolicyAssignmentId != v.Expected.PolicyAssignmentId { + t.Fatalf("Expected %q but got %q for PolicyAssignmentId", v.Expected.PolicyAssignmentId, actual.PolicyAssignmentId) + } + + } +} + +func TestSegmentsForPolicyAssignmentIdId(t *testing.T) { + segments := PolicyAssignmentIdId{}.Segments() + if len(segments) == 0 { + t.Fatalf("PolicyAssignmentIdId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/resources/2015-11-01/policyassignments/id_scopedpolicyassignment.go b/resource-manager/resources/2015-11-01/policyassignments/id_scopedpolicyassignment.go new file mode 100644 index 00000000000..2ed810504d2 --- /dev/null +++ b/resource-manager/resources/2015-11-01/policyassignments/id_scopedpolicyassignment.go @@ -0,0 +1,120 @@ +package policyassignments + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ScopedPolicyAssignmentId{}) +} + +var _ resourceids.ResourceId = &ScopedPolicyAssignmentId{} + +// ScopedPolicyAssignmentId is a struct representing the Resource ID for a Scoped Policy Assignment +type ScopedPolicyAssignmentId struct { + Scope string + PolicyAssignmentName string +} + +// NewScopedPolicyAssignmentID returns a new ScopedPolicyAssignmentId struct +func NewScopedPolicyAssignmentID(scope string, policyAssignmentName string) ScopedPolicyAssignmentId { + return ScopedPolicyAssignmentId{ + Scope: scope, + PolicyAssignmentName: policyAssignmentName, + } +} + +// ParseScopedPolicyAssignmentID parses 'input' into a ScopedPolicyAssignmentId +func ParseScopedPolicyAssignmentID(input string) (*ScopedPolicyAssignmentId, error) { + parser := resourceids.NewParserFromResourceIdType(&ScopedPolicyAssignmentId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ScopedPolicyAssignmentId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseScopedPolicyAssignmentIDInsensitively parses 'input' case-insensitively into a ScopedPolicyAssignmentId +// note: this method should only be used for API response data and not user input +func ParseScopedPolicyAssignmentIDInsensitively(input string) (*ScopedPolicyAssignmentId, error) { + parser := resourceids.NewParserFromResourceIdType(&ScopedPolicyAssignmentId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ScopedPolicyAssignmentId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ScopedPolicyAssignmentId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.Scope, ok = input.Parsed["scope"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "scope", input) + } + + if id.PolicyAssignmentName, ok = input.Parsed["policyAssignmentName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "policyAssignmentName", input) + } + + return nil +} + +// ValidateScopedPolicyAssignmentID checks that 'input' can be parsed as a Scoped Policy Assignment ID +func ValidateScopedPolicyAssignmentID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseScopedPolicyAssignmentID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Scoped Policy Assignment ID +func (id ScopedPolicyAssignmentId) ID() string { + fmtString := "/%s/providers/Microsoft.Authorization/policyAssignments/%s" + return fmt.Sprintf(fmtString, strings.TrimPrefix(id.Scope, "/"), id.PolicyAssignmentName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Scoped Policy Assignment ID +func (id ScopedPolicyAssignmentId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.ScopeSegment("scope", "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftAuthorization", "Microsoft.Authorization", "Microsoft.Authorization"), + resourceids.StaticSegment("staticPolicyAssignments", "policyAssignments", "policyAssignments"), + resourceids.UserSpecifiedSegment("policyAssignmentName", "policyAssignmentValue"), + } +} + +// String returns a human-readable description of this Scoped Policy Assignment ID +func (id ScopedPolicyAssignmentId) String() string { + components := []string{ + fmt.Sprintf("Scope: %q", id.Scope), + fmt.Sprintf("Policy Assignment Name: %q", id.PolicyAssignmentName), + } + return fmt.Sprintf("Scoped Policy Assignment (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/resources/2015-11-01/policyassignments/id_scopedpolicyassignment_test.go b/resource-manager/resources/2015-11-01/policyassignments/id_scopedpolicyassignment_test.go new file mode 100644 index 00000000000..30d20edc8cc --- /dev/null +++ b/resource-manager/resources/2015-11-01/policyassignments/id_scopedpolicyassignment_test.go @@ -0,0 +1,222 @@ +package policyassignments + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &ScopedPolicyAssignmentId{} + +func TestNewScopedPolicyAssignmentID(t *testing.T) { + id := NewScopedPolicyAssignmentID("/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", "policyAssignmentValue") + + if id.Scope != "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'Scope'", id.Scope, "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group") + } + + if id.PolicyAssignmentName != "policyAssignmentValue" { + t.Fatalf("Expected %q but got %q for Segment 'PolicyAssignmentName'", id.PolicyAssignmentName, "policyAssignmentValue") + } +} + +func TestFormatScopedPolicyAssignmentID(t *testing.T) { + actual := NewScopedPolicyAssignmentID("/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", "policyAssignmentValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.Authorization/policyAssignments/policyAssignmentValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseScopedPolicyAssignmentID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ScopedPolicyAssignmentId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.Authorization", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.Authorization/policyAssignments", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.Authorization/policyAssignments/policyAssignmentValue", + Expected: &ScopedPolicyAssignmentId{ + Scope: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", + PolicyAssignmentName: "policyAssignmentValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.Authorization/policyAssignments/policyAssignmentValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseScopedPolicyAssignmentID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.Scope != v.Expected.Scope { + t.Fatalf("Expected %q but got %q for Scope", v.Expected.Scope, actual.Scope) + } + + if actual.PolicyAssignmentName != v.Expected.PolicyAssignmentName { + t.Fatalf("Expected %q but got %q for PolicyAssignmentName", v.Expected.PolicyAssignmentName, actual.PolicyAssignmentName) + } + + } +} + +func TestParseScopedPolicyAssignmentIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ScopedPolicyAssignmentId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/sOmE-ReSoUrCe-gRoUp", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/sOmE-ReSoUrCe-gRoUp/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.Authorization", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/sOmE-ReSoUrCe-gRoUp/pRoViDeRs/mIcRoSoFt.aUtHoRiZaTiOn", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.Authorization/policyAssignments", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/sOmE-ReSoUrCe-gRoUp/pRoViDeRs/mIcRoSoFt.aUtHoRiZaTiOn/pOlIcYaSsIgNmEnTs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.Authorization/policyAssignments/policyAssignmentValue", + Expected: &ScopedPolicyAssignmentId{ + Scope: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group", + PolicyAssignmentName: "policyAssignmentValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group/providers/Microsoft.Authorization/policyAssignments/policyAssignmentValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/sOmE-ReSoUrCe-gRoUp/pRoViDeRs/mIcRoSoFt.aUtHoRiZaTiOn/pOlIcYaSsIgNmEnTs/pOlIcYaSsIgNmEnTvAlUe", + Expected: &ScopedPolicyAssignmentId{ + Scope: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/sOmE-ReSoUrCe-gRoUp", + PolicyAssignmentName: "pOlIcYaSsIgNmEnTvAlUe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/sOmE-ReSoUrCe-gRoUp/pRoViDeRs/mIcRoSoFt.aUtHoRiZaTiOn/pOlIcYaSsIgNmEnTs/pOlIcYaSsIgNmEnTvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseScopedPolicyAssignmentIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.Scope != v.Expected.Scope { + t.Fatalf("Expected %q but got %q for Scope", v.Expected.Scope, actual.Scope) + } + + if actual.PolicyAssignmentName != v.Expected.PolicyAssignmentName { + t.Fatalf("Expected %q but got %q for PolicyAssignmentName", v.Expected.PolicyAssignmentName, actual.PolicyAssignmentName) + } + + } +} + +func TestSegmentsForScopedPolicyAssignmentId(t *testing.T) { + segments := ScopedPolicyAssignmentId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ScopedPolicyAssignmentId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/resources/2015-11-01/policyassignments/method_create.go b/resource-manager/resources/2015-11-01/policyassignments/method_create.go new file mode 100644 index 00000000000..a532f7d9a19 --- /dev/null +++ b/resource-manager/resources/2015-11-01/policyassignments/method_create.go @@ -0,0 +1,58 @@ +package policyassignments + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *PolicyAssignment +} + +// Create ... +func (c PolicyAssignmentsClient) Create(ctx context.Context, id ScopedPolicyAssignmentId, input PolicyAssignment) (result CreateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model PolicyAssignment + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/resources/2015-11-01/policyassignments/method_createbyid.go b/resource-manager/resources/2015-11-01/policyassignments/method_createbyid.go new file mode 100644 index 00000000000..674d24a20ae --- /dev/null +++ b/resource-manager/resources/2015-11-01/policyassignments/method_createbyid.go @@ -0,0 +1,58 @@ +package policyassignments + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateByIdOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *PolicyAssignment +} + +// CreateById ... +func (c PolicyAssignmentsClient) CreateById(ctx context.Context, id PolicyAssignmentIdId, input PolicyAssignment) (result CreateByIdOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model PolicyAssignment + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/resources/2015-11-01/policyassignments/method_delete.go b/resource-manager/resources/2015-11-01/policyassignments/method_delete.go new file mode 100644 index 00000000000..ffa264e8303 --- /dev/null +++ b/resource-manager/resources/2015-11-01/policyassignments/method_delete.go @@ -0,0 +1,54 @@ +package policyassignments + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/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 *PolicyAssignment +} + +// Delete ... +func (c PolicyAssignmentsClient) Delete(ctx context.Context, id ScopedPolicyAssignmentId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + 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 + } + + var model PolicyAssignment + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/resources/2015-11-01/policyassignments/method_deletebyid.go b/resource-manager/resources/2015-11-01/policyassignments/method_deletebyid.go new file mode 100644 index 00000000000..04fbdc78d76 --- /dev/null +++ b/resource-manager/resources/2015-11-01/policyassignments/method_deletebyid.go @@ -0,0 +1,54 @@ +package policyassignments + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteByIdOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *PolicyAssignment +} + +// DeleteById ... +func (c PolicyAssignmentsClient) DeleteById(ctx context.Context, id PolicyAssignmentIdId) (result DeleteByIdOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + 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 + } + + var model PolicyAssignment + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/resources/2015-11-01/policyassignments/method_get.go b/resource-manager/resources/2015-11-01/policyassignments/method_get.go new file mode 100644 index 00000000000..9e8e5bbce83 --- /dev/null +++ b/resource-manager/resources/2015-11-01/policyassignments/method_get.go @@ -0,0 +1,54 @@ +package policyassignments + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/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 *PolicyAssignment +} + +// Get ... +func (c PolicyAssignmentsClient) Get(ctx context.Context, id ScopedPolicyAssignmentId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model PolicyAssignment + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/resources/2015-11-01/policyassignments/method_getbyid.go b/resource-manager/resources/2015-11-01/policyassignments/method_getbyid.go new file mode 100644 index 00000000000..8f0a663b93d --- /dev/null +++ b/resource-manager/resources/2015-11-01/policyassignments/method_getbyid.go @@ -0,0 +1,54 @@ +package policyassignments + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetByIdOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *PolicyAssignment +} + +// GetById ... +func (c PolicyAssignmentsClient) GetById(ctx context.Context, id PolicyAssignmentIdId) (result GetByIdOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model PolicyAssignment + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/resources/2015-11-01/policyassignments/method_list.go b/resource-manager/resources/2015-11-01/policyassignments/method_list.go new file mode 100644 index 00000000000..5e673631993 --- /dev/null +++ b/resource-manager/resources/2015-11-01/policyassignments/method_list.go @@ -0,0 +1,120 @@ +package policyassignments + +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 *[]PolicyAssignment +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []PolicyAssignment +} + +type ListOperationOptions struct { + Filter *string +} + +func DefaultListOperationOptions() ListOperationOptions { + return ListOperationOptions{} +} + +func (o ListOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o ListOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + return &out +} + +// List ... +func (c PolicyAssignmentsClient) List(ctx context.Context, id commonids.SubscriptionId, options ListOperationOptions) (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.Authorization/policyAssignments", 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 *[]PolicyAssignment `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 PolicyAssignmentsClient) ListComplete(ctx context.Context, id commonids.SubscriptionId, options ListOperationOptions) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, options, PolicyAssignmentOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c PolicyAssignmentsClient) ListCompleteMatchingPredicate(ctx context.Context, id commonids.SubscriptionId, options ListOperationOptions, predicate PolicyAssignmentOperationPredicate) (result ListCompleteResult, err error) { + items := make([]PolicyAssignment, 0) + + resp, err := c.List(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 = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/resources/2015-11-01/policyassignments/method_listforresource.go b/resource-manager/resources/2015-11-01/policyassignments/method_listforresource.go new file mode 100644 index 00000000000..73bf21d7d44 --- /dev/null +++ b/resource-manager/resources/2015-11-01/policyassignments/method_listforresource.go @@ -0,0 +1,120 @@ +package policyassignments + +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 ListForResourceOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]PolicyAssignment +} + +type ListForResourceCompleteResult struct { + LatestHttpResponse *http.Response + Items []PolicyAssignment +} + +type ListForResourceOperationOptions struct { + Filter *string +} + +func DefaultListForResourceOperationOptions() ListForResourceOperationOptions { + return ListForResourceOperationOptions{} +} + +func (o ListForResourceOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListForResourceOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o ListForResourceOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + return &out +} + +// ListForResource ... +func (c PolicyAssignmentsClient) ListForResource(ctx context.Context, id commonids.ScopeId, options ListForResourceOperationOptions) (result ListForResourceOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/resourceNameproviders/Microsoft.Authorization/policyAssignments", 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 *[]PolicyAssignment `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListForResourceComplete retrieves all the results into a single object +func (c PolicyAssignmentsClient) ListForResourceComplete(ctx context.Context, id commonids.ScopeId, options ListForResourceOperationOptions) (ListForResourceCompleteResult, error) { + return c.ListForResourceCompleteMatchingPredicate(ctx, id, options, PolicyAssignmentOperationPredicate{}) +} + +// ListForResourceCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c PolicyAssignmentsClient) ListForResourceCompleteMatchingPredicate(ctx context.Context, id commonids.ScopeId, options ListForResourceOperationOptions, predicate PolicyAssignmentOperationPredicate) (result ListForResourceCompleteResult, err error) { + items := make([]PolicyAssignment, 0) + + resp, err := c.ListForResource(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 = ListForResourceCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/resources/2015-11-01/policyassignments/method_listforresourcegroup.go b/resource-manager/resources/2015-11-01/policyassignments/method_listforresourcegroup.go new file mode 100644 index 00000000000..96e5d96fe92 --- /dev/null +++ b/resource-manager/resources/2015-11-01/policyassignments/method_listforresourcegroup.go @@ -0,0 +1,120 @@ +package policyassignments + +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 ListForResourceGroupOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]PolicyAssignment +} + +type ListForResourceGroupCompleteResult struct { + LatestHttpResponse *http.Response + Items []PolicyAssignment +} + +type ListForResourceGroupOperationOptions struct { + Filter *string +} + +func DefaultListForResourceGroupOperationOptions() ListForResourceGroupOperationOptions { + return ListForResourceGroupOperationOptions{} +} + +func (o ListForResourceGroupOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListForResourceGroupOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o ListForResourceGroupOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + return &out +} + +// ListForResourceGroup ... +func (c PolicyAssignmentsClient) ListForResourceGroup(ctx context.Context, id commonids.ResourceGroupId, options ListForResourceGroupOperationOptions) (result ListForResourceGroupOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/providers/Microsoft.Authorization/policyAssignments", 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 *[]PolicyAssignment `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListForResourceGroupComplete retrieves all the results into a single object +func (c PolicyAssignmentsClient) ListForResourceGroupComplete(ctx context.Context, id commonids.ResourceGroupId, options ListForResourceGroupOperationOptions) (ListForResourceGroupCompleteResult, error) { + return c.ListForResourceGroupCompleteMatchingPredicate(ctx, id, options, PolicyAssignmentOperationPredicate{}) +} + +// ListForResourceGroupCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c PolicyAssignmentsClient) ListForResourceGroupCompleteMatchingPredicate(ctx context.Context, id commonids.ResourceGroupId, options ListForResourceGroupOperationOptions, predicate PolicyAssignmentOperationPredicate) (result ListForResourceGroupCompleteResult, err error) { + items := make([]PolicyAssignment, 0) + + resp, err := c.ListForResourceGroup(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 = ListForResourceGroupCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/resources/2015-11-01/policyassignments/method_listforscope.go b/resource-manager/resources/2015-11-01/policyassignments/method_listforscope.go new file mode 100644 index 00000000000..14c71c06aba --- /dev/null +++ b/resource-manager/resources/2015-11-01/policyassignments/method_listforscope.go @@ -0,0 +1,120 @@ +package policyassignments + +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 ListForScopeOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]PolicyAssignment +} + +type ListForScopeCompleteResult struct { + LatestHttpResponse *http.Response + Items []PolicyAssignment +} + +type ListForScopeOperationOptions struct { + Filter *string +} + +func DefaultListForScopeOperationOptions() ListForScopeOperationOptions { + return ListForScopeOperationOptions{} +} + +func (o ListForScopeOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListForScopeOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o ListForScopeOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + return &out +} + +// ListForScope ... +func (c PolicyAssignmentsClient) ListForScope(ctx context.Context, id commonids.ScopeId, options ListForScopeOperationOptions) (result ListForScopeOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/providers/Microsoft.Authorization/policyAssignments", 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 *[]PolicyAssignment `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListForScopeComplete retrieves all the results into a single object +func (c PolicyAssignmentsClient) ListForScopeComplete(ctx context.Context, id commonids.ScopeId, options ListForScopeOperationOptions) (ListForScopeCompleteResult, error) { + return c.ListForScopeCompleteMatchingPredicate(ctx, id, options, PolicyAssignmentOperationPredicate{}) +} + +// ListForScopeCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c PolicyAssignmentsClient) ListForScopeCompleteMatchingPredicate(ctx context.Context, id commonids.ScopeId, options ListForScopeOperationOptions, predicate PolicyAssignmentOperationPredicate) (result ListForScopeCompleteResult, err error) { + items := make([]PolicyAssignment, 0) + + resp, err := c.ListForScope(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 = ListForScopeCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/resources/2015-11-01/policyassignments/model_policyassignment.go b/resource-manager/resources/2015-11-01/policyassignments/model_policyassignment.go new file mode 100644 index 00000000000..41603eecc42 --- /dev/null +++ b/resource-manager/resources/2015-11-01/policyassignments/model_policyassignment.go @@ -0,0 +1,9 @@ +package policyassignments + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PolicyAssignment struct { + Name *string `json:"name,omitempty"` + Properties *PolicyAssignmentProperties `json:"properties,omitempty"` +} diff --git a/resource-manager/resources/2015-11-01/policyassignments/model_policyassignmentproperties.go b/resource-manager/resources/2015-11-01/policyassignments/model_policyassignmentproperties.go new file mode 100644 index 00000000000..5cc1a5956c2 --- /dev/null +++ b/resource-manager/resources/2015-11-01/policyassignments/model_policyassignmentproperties.go @@ -0,0 +1,10 @@ +package policyassignments + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PolicyAssignmentProperties struct { + DisplayName *string `json:"displayName,omitempty"` + PolicyDefinitionId *string `json:"policyDefinitionId,omitempty"` + Scope *string `json:"scope,omitempty"` +} diff --git a/resource-manager/resources/2015-11-01/policyassignments/predicates.go b/resource-manager/resources/2015-11-01/policyassignments/predicates.go new file mode 100644 index 00000000000..a114ed08e4b --- /dev/null +++ b/resource-manager/resources/2015-11-01/policyassignments/predicates.go @@ -0,0 +1,17 @@ +package policyassignments + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PolicyAssignmentOperationPredicate struct { + Name *string +} + +func (p PolicyAssignmentOperationPredicate) Matches(input PolicyAssignment) bool { + + if p.Name != nil && (input.Name == nil || *p.Name != *input.Name) { + return false + } + + return true +} diff --git a/resource-manager/resources/2015-11-01/policyassignments/version.go b/resource-manager/resources/2015-11-01/policyassignments/version.go new file mode 100644 index 00000000000..97a6ec25cba --- /dev/null +++ b/resource-manager/resources/2015-11-01/policyassignments/version.go @@ -0,0 +1,12 @@ +package policyassignments + +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 = "2015-11-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/policyassignments/%s", defaultApiVersion) +} diff --git a/resource-manager/resources/2015-11-01/policydefinitions/README.md b/resource-manager/resources/2015-11-01/policydefinitions/README.md new file mode 100644 index 00000000000..3168d5f283b --- /dev/null +++ b/resource-manager/resources/2015-11-01/policydefinitions/README.md @@ -0,0 +1,73 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/resources/2015-11-01/policydefinitions` Documentation + +The `policydefinitions` SDK allows for interaction with the Azure Resource Manager Service `resources` (API Version `2015-11-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/resources/2015-11-01/policydefinitions" +``` + + +### Client Initialization + +```go +client := policydefinitions.NewPolicyDefinitionsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `PolicyDefinitionsClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := policydefinitions.NewPolicydefinitionID("12345678-1234-9876-4563-123456789012", "policydefinitionValue") + +payload := policydefinitions.PolicyDefinition{ + // ... +} + + +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: `PolicyDefinitionsClient.Delete` + +```go +ctx := context.TODO() +id := policydefinitions.NewPolicydefinitionID("12345678-1234-9876-4563-123456789012", "policydefinitionValue") + +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: `PolicyDefinitionsClient.Get` + +```go +ctx := context.TODO() +id := policydefinitions.NewPolicydefinitionID("12345678-1234-9876-4563-123456789012", "policydefinitionValue") + +read, err := client.Get(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` diff --git a/resource-manager/resources/2015-11-01/policydefinitions/client.go b/resource-manager/resources/2015-11-01/policydefinitions/client.go new file mode 100644 index 00000000000..b17e0191782 --- /dev/null +++ b/resource-manager/resources/2015-11-01/policydefinitions/client.go @@ -0,0 +1,26 @@ +package policydefinitions + +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 PolicyDefinitionsClient struct { + Client *resourcemanager.Client +} + +func NewPolicyDefinitionsClientWithBaseURI(sdkApi sdkEnv.Api) (*PolicyDefinitionsClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "policydefinitions", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating PolicyDefinitionsClient: %+v", err) + } + + return &PolicyDefinitionsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/resources/2015-11-01/policydefinitions/id_policydefinition.go b/resource-manager/resources/2015-11-01/policydefinitions/id_policydefinition.go new file mode 100644 index 00000000000..9463964bc99 --- /dev/null +++ b/resource-manager/resources/2015-11-01/policydefinitions/id_policydefinition.go @@ -0,0 +1,121 @@ +package policydefinitions + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&PolicydefinitionId{}) +} + +var _ resourceids.ResourceId = &PolicydefinitionId{} + +// PolicydefinitionId is a struct representing the Resource ID for a Policydefinition +type PolicydefinitionId struct { + SubscriptionId string + PolicydefinitionName string +} + +// NewPolicydefinitionID returns a new PolicydefinitionId struct +func NewPolicydefinitionID(subscriptionId string, policydefinitionName string) PolicydefinitionId { + return PolicydefinitionId{ + SubscriptionId: subscriptionId, + PolicydefinitionName: policydefinitionName, + } +} + +// ParsePolicydefinitionID parses 'input' into a PolicydefinitionId +func ParsePolicydefinitionID(input string) (*PolicydefinitionId, error) { + parser := resourceids.NewParserFromResourceIdType(&PolicydefinitionId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := PolicydefinitionId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParsePolicydefinitionIDInsensitively parses 'input' case-insensitively into a PolicydefinitionId +// note: this method should only be used for API response data and not user input +func ParsePolicydefinitionIDInsensitively(input string) (*PolicydefinitionId, error) { + parser := resourceids.NewParserFromResourceIdType(&PolicydefinitionId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := PolicydefinitionId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *PolicydefinitionId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.PolicydefinitionName, ok = input.Parsed["policydefinitionName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "policydefinitionName", input) + } + + return nil +} + +// ValidatePolicydefinitionID checks that 'input' can be parsed as a Policydefinition ID +func ValidatePolicydefinitionID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParsePolicydefinitionID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Policydefinition ID +func (id PolicydefinitionId) ID() string { + fmtString := "/subscriptions/%s/providers/Microsoft.Authorization/policydefinitions/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.PolicydefinitionName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Policydefinition ID +func (id PolicydefinitionId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftAuthorization", "Microsoft.Authorization", "Microsoft.Authorization"), + resourceids.StaticSegment("staticPolicydefinitions", "policydefinitions", "policydefinitions"), + resourceids.UserSpecifiedSegment("policydefinitionName", "policydefinitionValue"), + } +} + +// String returns a human-readable description of this Policydefinition ID +func (id PolicydefinitionId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Policydefinition Name: %q", id.PolicydefinitionName), + } + return fmt.Sprintf("Policydefinition (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/resources/2015-11-01/policydefinitions/id_policydefinition_test.go b/resource-manager/resources/2015-11-01/policydefinitions/id_policydefinition_test.go new file mode 100644 index 00000000000..4758500aec2 --- /dev/null +++ b/resource-manager/resources/2015-11-01/policydefinitions/id_policydefinition_test.go @@ -0,0 +1,237 @@ +package policydefinitions + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &PolicydefinitionId{} + +func TestNewPolicydefinitionID(t *testing.T) { + id := NewPolicydefinitionID("12345678-1234-9876-4563-123456789012", "policydefinitionValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.PolicydefinitionName != "policydefinitionValue" { + t.Fatalf("Expected %q but got %q for Segment 'PolicydefinitionName'", id.PolicydefinitionName, "policydefinitionValue") + } +} + +func TestFormatPolicydefinitionID(t *testing.T) { + actual := NewPolicydefinitionID("12345678-1234-9876-4563-123456789012", "policydefinitionValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Authorization/policydefinitions/policydefinitionValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParsePolicydefinitionID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *PolicydefinitionId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Authorization", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Authorization/policydefinitions", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Authorization/policydefinitions/policydefinitionValue", + Expected: &PolicydefinitionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + PolicydefinitionName: "policydefinitionValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Authorization/policydefinitions/policydefinitionValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParsePolicydefinitionID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.PolicydefinitionName != v.Expected.PolicydefinitionName { + t.Fatalf("Expected %q but got %q for PolicydefinitionName", v.Expected.PolicydefinitionName, actual.PolicydefinitionName) + } + + } +} + +func TestParsePolicydefinitionIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *PolicydefinitionId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Authorization", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.aUtHoRiZaTiOn", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Authorization/policydefinitions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.aUtHoRiZaTiOn/pOlIcYdEfInItIoNs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Authorization/policydefinitions/policydefinitionValue", + Expected: &PolicydefinitionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + PolicydefinitionName: "policydefinitionValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Authorization/policydefinitions/policydefinitionValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.aUtHoRiZaTiOn/pOlIcYdEfInItIoNs/pOlIcYdEfInItIoNvAlUe", + Expected: &PolicydefinitionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + PolicydefinitionName: "pOlIcYdEfInItIoNvAlUe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.aUtHoRiZaTiOn/pOlIcYdEfInItIoNs/pOlIcYdEfInItIoNvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParsePolicydefinitionIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.PolicydefinitionName != v.Expected.PolicydefinitionName { + t.Fatalf("Expected %q but got %q for PolicydefinitionName", v.Expected.PolicydefinitionName, actual.PolicydefinitionName) + } + + } +} + +func TestSegmentsForPolicydefinitionId(t *testing.T) { + segments := PolicydefinitionId{}.Segments() + if len(segments) == 0 { + t.Fatalf("PolicydefinitionId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/resources/2015-11-01/policydefinitions/method_createorupdate.go b/resource-manager/resources/2015-11-01/policydefinitions/method_createorupdate.go new file mode 100644 index 00000000000..e67123f0a3a --- /dev/null +++ b/resource-manager/resources/2015-11-01/policydefinitions/method_createorupdate.go @@ -0,0 +1,58 @@ +package policydefinitions + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/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 *PolicyDefinition +} + +// CreateOrUpdate ... +func (c PolicyDefinitionsClient) CreateOrUpdate(ctx context.Context, id PolicydefinitionId, input PolicyDefinition) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model PolicyDefinition + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/resources/2015-11-01/policydefinitions/method_delete.go b/resource-manager/resources/2015-11-01/policydefinitions/method_delete.go new file mode 100644 index 00000000000..029c22d4037 --- /dev/null +++ b/resource-manager/resources/2015-11-01/policydefinitions/method_delete.go @@ -0,0 +1,46 @@ +package policydefinitions + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// Delete ... +func (c PolicyDefinitionsClient) Delete(ctx context.Context, id PolicydefinitionId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + 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/resources/2015-11-01/policydefinitions/method_get.go b/resource-manager/resources/2015-11-01/policydefinitions/method_get.go new file mode 100644 index 00000000000..37878c29c04 --- /dev/null +++ b/resource-manager/resources/2015-11-01/policydefinitions/method_get.go @@ -0,0 +1,54 @@ +package policydefinitions + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/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 *PolicyDefinition +} + +// Get ... +func (c PolicyDefinitionsClient) Get(ctx context.Context, id PolicydefinitionId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model PolicyDefinition + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/resources/2015-11-01/policydefinitions/model_policydefinition.go b/resource-manager/resources/2015-11-01/policydefinitions/model_policydefinition.go new file mode 100644 index 00000000000..53b4896433d --- /dev/null +++ b/resource-manager/resources/2015-11-01/policydefinitions/model_policydefinition.go @@ -0,0 +1,9 @@ +package policydefinitions + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PolicyDefinition struct { + Name *string `json:"name,omitempty"` + Properties *PolicyDefinitionProperties `json:"properties,omitempty"` +} diff --git a/resource-manager/resources/2015-11-01/policydefinitions/model_policydefinitionproperties.go b/resource-manager/resources/2015-11-01/policydefinitions/model_policydefinitionproperties.go new file mode 100644 index 00000000000..c03f35b7b25 --- /dev/null +++ b/resource-manager/resources/2015-11-01/policydefinitions/model_policydefinitionproperties.go @@ -0,0 +1,10 @@ +package policydefinitions + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PolicyDefinitionProperties struct { + Description *string `json:"description,omitempty"` + DisplayName *string `json:"displayName,omitempty"` + PolicyRule *interface{} `json:"policyRule,omitempty"` +} diff --git a/resource-manager/resources/2015-11-01/policydefinitions/version.go b/resource-manager/resources/2015-11-01/policydefinitions/version.go new file mode 100644 index 00000000000..850428aa411 --- /dev/null +++ b/resource-manager/resources/2015-11-01/policydefinitions/version.go @@ -0,0 +1,12 @@ +package policydefinitions + +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 = "2015-11-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/policydefinitions/%s", defaultApiVersion) +} diff --git a/resource-manager/resources/2015-11-01/providers/README.md b/resource-manager/resources/2015-11-01/providers/README.md new file mode 100644 index 00000000000..c631f9b7255 --- /dev/null +++ b/resource-manager/resources/2015-11-01/providers/README.md @@ -0,0 +1,86 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/resources/2015-11-01/providers` Documentation + +The `providers` SDK allows for interaction with the Azure Resource Manager Service `resources` (API Version `2015-11-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +import "github.com/hashicorp/go-azure-sdk/resource-manager/resources/2015-11-01/providers" +``` + + +### Client Initialization + +```go +client := providers.NewProvidersClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ProvidersClient.Get` + +```go +ctx := context.TODO() +id := providers.NewProviderID("12345678-1234-9876-4563-123456789012", "providerValue") + +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: `ProvidersClient.List` + +```go +ctx := context.TODO() +id := commonids.NewSubscriptionID("12345678-1234-9876-4563-123456789012") + +// alternatively `client.List(ctx, id, providers.DefaultListOperationOptions())` can be used to do batched pagination +items, err := client.ListComplete(ctx, id, providers.DefaultListOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `ProvidersClient.Register` + +```go +ctx := context.TODO() +id := providers.NewProviderID("12345678-1234-9876-4563-123456789012", "providerValue") + +read, err := client.Register(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ProvidersClient.Unregister` + +```go +ctx := context.TODO() +id := providers.NewProviderID("12345678-1234-9876-4563-123456789012", "providerValue") + +read, err := client.Unregister(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/resources/2015-11-01/providers/client.go b/resource-manager/resources/2015-11-01/providers/client.go new file mode 100644 index 00000000000..d7c2b0e499d --- /dev/null +++ b/resource-manager/resources/2015-11-01/providers/client.go @@ -0,0 +1,26 @@ +package providers + +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 ProvidersClient struct { + Client *resourcemanager.Client +} + +func NewProvidersClientWithBaseURI(sdkApi sdkEnv.Api) (*ProvidersClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "providers", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating ProvidersClient: %+v", err) + } + + return &ProvidersClient{ + Client: client, + }, nil +} diff --git a/resource-manager/resources/2015-11-01/providers/id_provider.go b/resource-manager/resources/2015-11-01/providers/id_provider.go new file mode 100644 index 00000000000..6a23a48f553 --- /dev/null +++ b/resource-manager/resources/2015-11-01/providers/id_provider.go @@ -0,0 +1,119 @@ +package providers + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ProviderId{}) +} + +var _ resourceids.ResourceId = &ProviderId{} + +// ProviderId is a struct representing the Resource ID for a Provider +type ProviderId struct { + SubscriptionId string + ProviderName string +} + +// NewProviderID returns a new ProviderId struct +func NewProviderID(subscriptionId string, providerName string) ProviderId { + return ProviderId{ + SubscriptionId: subscriptionId, + ProviderName: providerName, + } +} + +// ParseProviderID parses 'input' into a ProviderId +func ParseProviderID(input string) (*ProviderId, error) { + parser := resourceids.NewParserFromResourceIdType(&ProviderId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ProviderId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseProviderIDInsensitively parses 'input' case-insensitively into a ProviderId +// note: this method should only be used for API response data and not user input +func ParseProviderIDInsensitively(input string) (*ProviderId, error) { + parser := resourceids.NewParserFromResourceIdType(&ProviderId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ProviderId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ProviderId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ProviderName, ok = input.Parsed["providerName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "providerName", input) + } + + return nil +} + +// ValidateProviderID checks that 'input' can be parsed as a Provider ID +func ValidateProviderID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseProviderID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Provider ID +func (id ProviderId) ID() string { + fmtString := "/subscriptions/%s/providers/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ProviderName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Provider ID +func (id ProviderId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.UserSpecifiedSegment("providerName", "providerValue"), + } +} + +// String returns a human-readable description of this Provider ID +func (id ProviderId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Provider Name: %q", id.ProviderName), + } + return fmt.Sprintf("Provider (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/resources/2015-11-01/providers/id_provider_test.go b/resource-manager/resources/2015-11-01/providers/id_provider_test.go new file mode 100644 index 00000000000..a95d5ca1a05 --- /dev/null +++ b/resource-manager/resources/2015-11-01/providers/id_provider_test.go @@ -0,0 +1,207 @@ +package providers + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &ProviderId{} + +func TestNewProviderID(t *testing.T) { + id := NewProviderID("12345678-1234-9876-4563-123456789012", "providerValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ProviderName != "providerValue" { + t.Fatalf("Expected %q but got %q for Segment 'ProviderName'", id.ProviderName, "providerValue") + } +} + +func TestFormatProviderID(t *testing.T) { + actual := NewProviderID("12345678-1234-9876-4563-123456789012", "providerValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/providers/providerValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseProviderID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ProviderId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/providerValue", + Expected: &ProviderId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ProviderName: "providerValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/providerValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseProviderID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ProviderName != v.Expected.ProviderName { + t.Fatalf("Expected %q but got %q for ProviderName", v.Expected.ProviderName, actual.ProviderName) + } + + } +} + +func TestParseProviderIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ProviderId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/providerValue", + Expected: &ProviderId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ProviderName: "providerValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/providerValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/pRoViDeRvAlUe", + Expected: &ProviderId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ProviderName: "pRoViDeRvAlUe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/pRoViDeRvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseProviderIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ProviderName != v.Expected.ProviderName { + t.Fatalf("Expected %q but got %q for ProviderName", v.Expected.ProviderName, actual.ProviderName) + } + + } +} + +func TestSegmentsForProviderId(t *testing.T) { + segments := ProviderId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ProviderId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/resources/2015-11-01/providers/method_get.go b/resource-manager/resources/2015-11-01/providers/method_get.go new file mode 100644 index 00000000000..74d0904b949 --- /dev/null +++ b/resource-manager/resources/2015-11-01/providers/method_get.go @@ -0,0 +1,54 @@ +package providers + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/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 *Provider +} + +// Get ... +func (c ProvidersClient) Get(ctx context.Context, id ProviderId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model Provider + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/resources/2015-11-01/providers/method_list.go b/resource-manager/resources/2015-11-01/providers/method_list.go new file mode 100644 index 00000000000..718da64c439 --- /dev/null +++ b/resource-manager/resources/2015-11-01/providers/method_list.go @@ -0,0 +1,120 @@ +package providers + +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 *[]Provider +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []Provider +} + +type ListOperationOptions struct { + Top *int64 +} + +func DefaultListOperationOptions() ListOperationOptions { + return ListOperationOptions{} +} + +func (o ListOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o ListOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +// List ... +func (c ProvidersClient) List(ctx context.Context, id commonids.SubscriptionId, options ListOperationOptions) (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", 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 *[]Provider `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 ProvidersClient) ListComplete(ctx context.Context, id commonids.SubscriptionId, options ListOperationOptions) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, options, ProviderOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ProvidersClient) ListCompleteMatchingPredicate(ctx context.Context, id commonids.SubscriptionId, options ListOperationOptions, predicate ProviderOperationPredicate) (result ListCompleteResult, err error) { + items := make([]Provider, 0) + + resp, err := c.List(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 = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/resources/2015-11-01/providers/method_register.go b/resource-manager/resources/2015-11-01/providers/method_register.go new file mode 100644 index 00000000000..549db8fe36e --- /dev/null +++ b/resource-manager/resources/2015-11-01/providers/method_register.go @@ -0,0 +1,55 @@ +package providers + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RegisterOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *Provider +} + +// Register ... +func (c ProvidersClient) Register(ctx context.Context, id ProviderId) (result RegisterOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/register", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model Provider + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/resources/2015-11-01/providers/method_unregister.go b/resource-manager/resources/2015-11-01/providers/method_unregister.go new file mode 100644 index 00000000000..39419b80e7c --- /dev/null +++ b/resource-manager/resources/2015-11-01/providers/method_unregister.go @@ -0,0 +1,55 @@ +package providers + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type UnregisterOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *Provider +} + +// Unregister ... +func (c ProvidersClient) Unregister(ctx context.Context, id ProviderId) (result UnregisterOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/unregister", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model Provider + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/resources/2015-11-01/providers/model_provider.go b/resource-manager/resources/2015-11-01/providers/model_provider.go new file mode 100644 index 00000000000..fa9a8785033 --- /dev/null +++ b/resource-manager/resources/2015-11-01/providers/model_provider.go @@ -0,0 +1,11 @@ +package providers + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Provider struct { + Id *string `json:"id,omitempty"` + Namespace *string `json:"namespace,omitempty"` + RegistrationState *string `json:"registrationState,omitempty"` + ResourceTypes *[]ProviderResourceType `json:"resourceTypes,omitempty"` +} diff --git a/resource-manager/resources/2015-11-01/providers/model_providerresourcetype.go b/resource-manager/resources/2015-11-01/providers/model_providerresourcetype.go new file mode 100644 index 00000000000..996e7c328e7 --- /dev/null +++ b/resource-manager/resources/2015-11-01/providers/model_providerresourcetype.go @@ -0,0 +1,11 @@ +package providers + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ProviderResourceType struct { + ApiVersions *[]string `json:"apiVersions,omitempty"` + Locations *[]string `json:"locations,omitempty"` + Properties *map[string]string `json:"properties,omitempty"` + ResourceType *string `json:"resourceType,omitempty"` +} diff --git a/resource-manager/resources/2015-11-01/providers/predicates.go b/resource-manager/resources/2015-11-01/providers/predicates.go new file mode 100644 index 00000000000..297fa034b23 --- /dev/null +++ b/resource-manager/resources/2015-11-01/providers/predicates.go @@ -0,0 +1,27 @@ +package providers + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ProviderOperationPredicate struct { + Id *string + Namespace *string + RegistrationState *string +} + +func (p ProviderOperationPredicate) Matches(input Provider) bool { + + if p.Id != nil && (input.Id == nil || *p.Id != *input.Id) { + return false + } + + if p.Namespace != nil && (input.Namespace == nil || *p.Namespace != *input.Namespace) { + return false + } + + if p.RegistrationState != nil && (input.RegistrationState == nil || *p.RegistrationState != *input.RegistrationState) { + return false + } + + return true +} diff --git a/resource-manager/resources/2015-11-01/providers/version.go b/resource-manager/resources/2015-11-01/providers/version.go new file mode 100644 index 00000000000..e91ecd68b00 --- /dev/null +++ b/resource-manager/resources/2015-11-01/providers/version.go @@ -0,0 +1,12 @@ +package providers + +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 = "2015-11-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/providers/%s", defaultApiVersion) +} diff --git a/resource-manager/resources/2015-11-01/resourcegroups/README.md b/resource-manager/resources/2015-11-01/resourcegroups/README.md new file mode 100644 index 00000000000..905503f3d89 --- /dev/null +++ b/resource-manager/resources/2015-11-01/resourcegroups/README.md @@ -0,0 +1,141 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/resources/2015-11-01/resourcegroups` Documentation + +The `resourcegroups` SDK allows for interaction with the Azure Resource Manager Service `resources` (API Version `2015-11-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +import "github.com/hashicorp/go-azure-sdk/resource-manager/resources/2015-11-01/resourcegroups" +``` + + +### Client Initialization + +```go +client := resourcegroups.NewResourceGroupsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ResourceGroupsClient.CheckExistence` + +```go +ctx := context.TODO() +id := commonids.NewResourceGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group") + +read, err := client.CheckExistence(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ResourceGroupsClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := commonids.NewResourceGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group") + +payload := resourcegroups.ResourceGroup{ + // ... +} + + +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: `ResourceGroupsClient.Delete` + +```go +ctx := context.TODO() +id := commonids.NewResourceGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group") + +if err := client.DeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `ResourceGroupsClient.Get` + +```go +ctx := context.TODO() +id := commonids.NewResourceGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group") + +read, err := client.Get(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ResourceGroupsClient.List` + +```go +ctx := context.TODO() +id := commonids.NewSubscriptionID("12345678-1234-9876-4563-123456789012") + +// alternatively `client.List(ctx, id, resourcegroups.DefaultListOperationOptions())` can be used to do batched pagination +items, err := client.ListComplete(ctx, id, resourcegroups.DefaultListOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `ResourceGroupsClient.ListResources` + +```go +ctx := context.TODO() +id := commonids.NewResourceGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group") + +// alternatively `client.ListResources(ctx, id, resourcegroups.DefaultListResourcesOperationOptions())` can be used to do batched pagination +items, err := client.ListResourcesComplete(ctx, id, resourcegroups.DefaultListResourcesOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `ResourceGroupsClient.Patch` + +```go +ctx := context.TODO() +id := commonids.NewResourceGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group") + +payload := resourcegroups.ResourceGroup{ + // ... +} + + +read, err := client.Patch(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/resources/2015-11-01/resourcegroups/client.go b/resource-manager/resources/2015-11-01/resourcegroups/client.go new file mode 100644 index 00000000000..1f154d80422 --- /dev/null +++ b/resource-manager/resources/2015-11-01/resourcegroups/client.go @@ -0,0 +1,26 @@ +package resourcegroups + +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 ResourceGroupsClient struct { + Client *resourcemanager.Client +} + +func NewResourceGroupsClientWithBaseURI(sdkApi sdkEnv.Api) (*ResourceGroupsClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "resourcegroups", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating ResourceGroupsClient: %+v", err) + } + + return &ResourceGroupsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/resources/2015-11-01/resourcegroups/method_checkexistence.go b/resource-manager/resources/2015-11-01/resourcegroups/method_checkexistence.go new file mode 100644 index 00000000000..18ba2870e19 --- /dev/null +++ b/resource-manager/resources/2015-11-01/resourcegroups/method_checkexistence.go @@ -0,0 +1,47 @@ +package resourcegroups + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CheckExistenceOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// CheckExistence ... +func (c ResourceGroupsClient) CheckExistence(ctx context.Context, id commonids.ResourceGroupId) (result CheckExistenceOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + }, + HttpMethod: http.MethodHead, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/resources/2015-11-01/resourcegroups/method_createorupdate.go b/resource-manager/resources/2015-11-01/resourcegroups/method_createorupdate.go new file mode 100644 index 00000000000..a0c7a8a2ada --- /dev/null +++ b/resource-manager/resources/2015-11-01/resourcegroups/method_createorupdate.go @@ -0,0 +1,60 @@ +package resourcegroups + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// 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 *ResourceGroup +} + +// CreateOrUpdate ... +func (c ResourceGroupsClient) CreateOrUpdate(ctx context.Context, id commonids.ResourceGroupId, input ResourceGroup) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model ResourceGroup + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/resources/2015-11-01/resourcegroups/method_delete.go b/resource-manager/resources/2015-11-01/resourcegroups/method_delete.go new file mode 100644 index 00000000000..bfa3255c1ca --- /dev/null +++ b/resource-manager/resources/2015-11-01/resourcegroups/method_delete.go @@ -0,0 +1,71 @@ +package resourcegroups + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// Delete ... +func (c ResourceGroupsClient) Delete(ctx context.Context, id commonids.ResourceGroupId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.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 ResourceGroupsClient) DeleteThenPoll(ctx context.Context, id commonids.ResourceGroupId) error { + result, err := c.Delete(ctx, id) + if err != nil { + return fmt.Errorf("performing Delete: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after Delete: %+v", err) + } + + return nil +} diff --git a/resource-manager/resources/2015-11-01/resourcegroups/method_get.go b/resource-manager/resources/2015-11-01/resourcegroups/method_get.go new file mode 100644 index 00000000000..a75549521ac --- /dev/null +++ b/resource-manager/resources/2015-11-01/resourcegroups/method_get.go @@ -0,0 +1,55 @@ +package resourcegroups + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// 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 *ResourceGroup +} + +// Get ... +func (c ResourceGroupsClient) Get(ctx context.Context, id commonids.ResourceGroupId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model ResourceGroup + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/resources/2015-11-01/resourcegroups/method_list.go b/resource-manager/resources/2015-11-01/resourcegroups/method_list.go new file mode 100644 index 00000000000..2f321d173a9 --- /dev/null +++ b/resource-manager/resources/2015-11-01/resourcegroups/method_list.go @@ -0,0 +1,124 @@ +package resourcegroups + +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 *[]ResourceGroup +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []ResourceGroup +} + +type ListOperationOptions struct { + Filter *string + Top *int64 +} + +func DefaultListOperationOptions() ListOperationOptions { + return ListOperationOptions{} +} + +func (o ListOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o ListOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +// List ... +func (c ResourceGroupsClient) List(ctx context.Context, id commonids.SubscriptionId, options ListOperationOptions) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/resourceGroups", 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 *[]ResourceGroup `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 ResourceGroupsClient) ListComplete(ctx context.Context, id commonids.SubscriptionId, options ListOperationOptions) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, options, ResourceGroupOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ResourceGroupsClient) ListCompleteMatchingPredicate(ctx context.Context, id commonids.SubscriptionId, options ListOperationOptions, predicate ResourceGroupOperationPredicate) (result ListCompleteResult, err error) { + items := make([]ResourceGroup, 0) + + resp, err := c.List(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 = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/resources/2015-11-01/resourcegroups/method_listresources.go b/resource-manager/resources/2015-11-01/resourcegroups/method_listresources.go new file mode 100644 index 00000000000..a133be5a28b --- /dev/null +++ b/resource-manager/resources/2015-11-01/resourcegroups/method_listresources.go @@ -0,0 +1,128 @@ +package resourcegroups + +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 ListResourcesOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]GenericResourceExpanded +} + +type ListResourcesCompleteResult struct { + LatestHttpResponse *http.Response + Items []GenericResourceExpanded +} + +type ListResourcesOperationOptions struct { + Expand *string + Filter *string + Top *int64 +} + +func DefaultListResourcesOperationOptions() ListResourcesOperationOptions { + return ListResourcesOperationOptions{} +} + +func (o ListResourcesOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListResourcesOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o ListResourcesOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Expand != nil { + out.Append("$expand", fmt.Sprintf("%v", *o.Expand)) + } + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +// ListResources ... +func (c ResourceGroupsClient) ListResources(ctx context.Context, id commonids.ResourceGroupId, options ListResourcesOperationOptions) (result ListResourcesOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/resources", 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 *[]GenericResourceExpanded `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListResourcesComplete retrieves all the results into a single object +func (c ResourceGroupsClient) ListResourcesComplete(ctx context.Context, id commonids.ResourceGroupId, options ListResourcesOperationOptions) (ListResourcesCompleteResult, error) { + return c.ListResourcesCompleteMatchingPredicate(ctx, id, options, GenericResourceExpandedOperationPredicate{}) +} + +// ListResourcesCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ResourceGroupsClient) ListResourcesCompleteMatchingPredicate(ctx context.Context, id commonids.ResourceGroupId, options ListResourcesOperationOptions, predicate GenericResourceExpandedOperationPredicate) (result ListResourcesCompleteResult, err error) { + items := make([]GenericResourceExpanded, 0) + + resp, err := c.ListResources(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 = ListResourcesCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/resources/2015-11-01/resourcegroups/method_patch.go b/resource-manager/resources/2015-11-01/resourcegroups/method_patch.go new file mode 100644 index 00000000000..239e2dd080a --- /dev/null +++ b/resource-manager/resources/2015-11-01/resourcegroups/method_patch.go @@ -0,0 +1,59 @@ +package resourcegroups + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PatchOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *ResourceGroup +} + +// Patch ... +func (c ResourceGroupsClient) Patch(ctx context.Context, id commonids.ResourceGroupId, input ResourceGroup) (result PatchOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPatch, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model ResourceGroup + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/resources/2015-11-01/resourcegroups/model_genericresourceexpanded.go b/resource-manager/resources/2015-11-01/resourcegroups/model_genericresourceexpanded.go new file mode 100644 index 00000000000..574af83c37c --- /dev/null +++ b/resource-manager/resources/2015-11-01/resourcegroups/model_genericresourceexpanded.go @@ -0,0 +1,47 @@ +package resourcegroups + +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 GenericResourceExpanded struct { + ChangedTime *string `json:"changedTime,omitempty"` + CreatedTime *string `json:"createdTime,omitempty"` + Id *string `json:"id,omitempty"` + Location string `json:"location"` + Name *string `json:"name,omitempty"` + Plan *Plan `json:"plan,omitempty"` + Properties *interface{} `json:"properties,omitempty"` + ProvisioningState *string `json:"provisioningState,omitempty"` + Tags *map[string]string `json:"tags,omitempty"` + Type *string `json:"type,omitempty"` +} + +func (o *GenericResourceExpanded) GetChangedTimeAsTime() (*time.Time, error) { + if o.ChangedTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.ChangedTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *GenericResourceExpanded) SetChangedTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.ChangedTime = &formatted +} + +func (o *GenericResourceExpanded) GetCreatedTimeAsTime() (*time.Time, error) { + if o.CreatedTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.CreatedTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *GenericResourceExpanded) SetCreatedTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.CreatedTime = &formatted +} diff --git a/resource-manager/resources/2015-11-01/resourcegroups/model_plan.go b/resource-manager/resources/2015-11-01/resourcegroups/model_plan.go new file mode 100644 index 00000000000..53a13eeec70 --- /dev/null +++ b/resource-manager/resources/2015-11-01/resourcegroups/model_plan.go @@ -0,0 +1,11 @@ +package resourcegroups + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Plan struct { + Name *string `json:"name,omitempty"` + Product *string `json:"product,omitempty"` + PromotionCode *string `json:"promotionCode,omitempty"` + Publisher *string `json:"publisher,omitempty"` +} diff --git a/resource-manager/resources/2015-11-01/resourcegroups/model_resourcegroup.go b/resource-manager/resources/2015-11-01/resourcegroups/model_resourcegroup.go new file mode 100644 index 00000000000..4c03f530b07 --- /dev/null +++ b/resource-manager/resources/2015-11-01/resourcegroups/model_resourcegroup.go @@ -0,0 +1,12 @@ +package resourcegroups + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ResourceGroup struct { + Id *string `json:"id,omitempty"` + Location string `json:"location"` + Name *string `json:"name,omitempty"` + Properties *ResourceGroupProperties `json:"properties,omitempty"` + Tags *map[string]string `json:"tags,omitempty"` +} diff --git a/resource-manager/resources/2015-11-01/resourcegroups/model_resourcegroupproperties.go b/resource-manager/resources/2015-11-01/resourcegroups/model_resourcegroupproperties.go new file mode 100644 index 00000000000..aa68a1f10b4 --- /dev/null +++ b/resource-manager/resources/2015-11-01/resourcegroups/model_resourcegroupproperties.go @@ -0,0 +1,8 @@ +package resourcegroups + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ResourceGroupProperties struct { + ProvisioningState *string `json:"provisioningState,omitempty"` +} diff --git a/resource-manager/resources/2015-11-01/resourcegroups/predicates.go b/resource-manager/resources/2015-11-01/resourcegroups/predicates.go new file mode 100644 index 00000000000..822bbfe726e --- /dev/null +++ b/resource-manager/resources/2015-11-01/resourcegroups/predicates.go @@ -0,0 +1,75 @@ +package resourcegroups + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GenericResourceExpandedOperationPredicate struct { + ChangedTime *string + CreatedTime *string + Id *string + Location *string + Name *string + Properties *interface{} + ProvisioningState *string + Type *string +} + +func (p GenericResourceExpandedOperationPredicate) Matches(input GenericResourceExpanded) bool { + + if p.ChangedTime != nil && (input.ChangedTime == nil || *p.ChangedTime != *input.ChangedTime) { + return false + } + + if p.CreatedTime != nil && (input.CreatedTime == nil || *p.CreatedTime != *input.CreatedTime) { + return false + } + + if p.Id != nil && (input.Id == nil || *p.Id != *input.Id) { + return false + } + + if p.Location != nil && *p.Location != input.Location { + return false + } + + if p.Name != nil && (input.Name == nil || *p.Name != *input.Name) { + return false + } + + if p.Properties != nil && (input.Properties == nil || *p.Properties != *input.Properties) { + return false + } + + if p.ProvisioningState != nil && (input.ProvisioningState == nil || *p.ProvisioningState != *input.ProvisioningState) { + return false + } + + if p.Type != nil && (input.Type == nil || *p.Type != *input.Type) { + return false + } + + return true +} + +type ResourceGroupOperationPredicate struct { + Id *string + Location *string + Name *string +} + +func (p ResourceGroupOperationPredicate) Matches(input ResourceGroup) 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 + } + + return true +} diff --git a/resource-manager/resources/2015-11-01/resourcegroups/version.go b/resource-manager/resources/2015-11-01/resourcegroups/version.go new file mode 100644 index 00000000000..4e86a5ec530 --- /dev/null +++ b/resource-manager/resources/2015-11-01/resourcegroups/version.go @@ -0,0 +1,12 @@ +package resourcegroups + +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 = "2015-11-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/resourcegroups/%s", defaultApiVersion) +} diff --git a/resource-manager/resources/2015-11-01/resources/README.md b/resource-manager/resources/2015-11-01/resources/README.md new file mode 100644 index 00000000000..b18d3350a87 --- /dev/null +++ b/resource-manager/resources/2015-11-01/resources/README.md @@ -0,0 +1,141 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/resources/2015-11-01/resources` Documentation + +The `resources` SDK allows for interaction with the Azure Resource Manager Service `resources` (API Version `2015-11-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +import "github.com/hashicorp/go-azure-sdk/resource-manager/resources/2015-11-01/resources" +``` + + +### Client Initialization + +```go +client := resources.NewResourcesClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ResourcesClient.CheckExistence` + +```go +ctx := context.TODO() +id := commonids.NewScopeID("/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group") + +read, err := client.CheckExistence(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ResourcesClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := commonids.NewScopeID("/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group") + +payload := resources.GenericResource{ + // ... +} + + +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: `ResourcesClient.Delete` + +```go +ctx := context.TODO() +id := commonids.NewScopeID("/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group") + +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: `ResourcesClient.Get` + +```go +ctx := context.TODO() +id := commonids.NewScopeID("/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group") + +read, err := client.Get(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ResourcesClient.List` + +```go +ctx := context.TODO() +id := commonids.NewSubscriptionID("12345678-1234-9876-4563-123456789012") + +// alternatively `client.List(ctx, id, resources.DefaultListOperationOptions())` can be used to do batched pagination +items, err := client.ListComplete(ctx, id, resources.DefaultListOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `ResourcesClient.MoveResources` + +```go +ctx := context.TODO() +id := commonids.NewResourceGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group") + +payload := resources.ResourcesMoveInfo{ + // ... +} + + +if err := client.MoveResourcesThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `ResourcesClient.Update` + +```go +ctx := context.TODO() +id := commonids.NewScopeID("/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group") + +payload := resources.GenericResource{ + // ... +} + + +if err := client.UpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` diff --git a/resource-manager/resources/2015-11-01/resources/client.go b/resource-manager/resources/2015-11-01/resources/client.go new file mode 100644 index 00000000000..3b409247557 --- /dev/null +++ b/resource-manager/resources/2015-11-01/resources/client.go @@ -0,0 +1,26 @@ +package resources + +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 ResourcesClient struct { + Client *resourcemanager.Client +} + +func NewResourcesClientWithBaseURI(sdkApi sdkEnv.Api) (*ResourcesClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "resources", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating ResourcesClient: %+v", err) + } + + return &ResourcesClient{ + Client: client, + }, nil +} diff --git a/resource-manager/resources/2015-11-01/resources/method_checkexistence.go b/resource-manager/resources/2015-11-01/resources/method_checkexistence.go new file mode 100644 index 00000000000..ad5faa25cc1 --- /dev/null +++ b/resource-manager/resources/2015-11-01/resources/method_checkexistence.go @@ -0,0 +1,47 @@ +package resources + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CheckExistenceOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// CheckExistence ... +func (c ResourcesClient) CheckExistence(ctx context.Context, id commonids.ScopeId) (result CheckExistenceOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + }, + HttpMethod: http.MethodHead, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/resources/2015-11-01/resources/method_createorupdate.go b/resource-manager/resources/2015-11-01/resources/method_createorupdate.go new file mode 100644 index 00000000000..7fab7f13872 --- /dev/null +++ b/resource-manager/resources/2015-11-01/resources/method_createorupdate.go @@ -0,0 +1,60 @@ +package resources + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// 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 *GenericResource +} + +// CreateOrUpdate ... +func (c ResourcesClient) CreateOrUpdate(ctx context.Context, id commonids.ScopeId, input GenericResource) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model GenericResource + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/resources/2015-11-01/resources/method_delete.go b/resource-manager/resources/2015-11-01/resources/method_delete.go new file mode 100644 index 00000000000..773539fc95b --- /dev/null +++ b/resource-manager/resources/2015-11-01/resources/method_delete.go @@ -0,0 +1,49 @@ +package resources + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// Delete ... +func (c ResourcesClient) Delete(ctx context.Context, id commonids.ScopeId) (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 + } + + return +} diff --git a/resource-manager/resources/2015-11-01/resources/method_get.go b/resource-manager/resources/2015-11-01/resources/method_get.go new file mode 100644 index 00000000000..a8809c97b53 --- /dev/null +++ b/resource-manager/resources/2015-11-01/resources/method_get.go @@ -0,0 +1,56 @@ +package resources + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// 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 *GenericResource +} + +// Get ... +func (c ResourcesClient) Get(ctx context.Context, id commonids.ScopeId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model GenericResource + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/resources/2015-11-01/resources/method_list.go b/resource-manager/resources/2015-11-01/resources/method_list.go new file mode 100644 index 00000000000..0629f72fd51 --- /dev/null +++ b/resource-manager/resources/2015-11-01/resources/method_list.go @@ -0,0 +1,128 @@ +package resources + +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 *[]GenericResourceExpanded +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []GenericResourceExpanded +} + +type ListOperationOptions struct { + Expand *string + Filter *string + Top *int64 +} + +func DefaultListOperationOptions() ListOperationOptions { + return ListOperationOptions{} +} + +func (o ListOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o ListOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Expand != nil { + out.Append("$expand", fmt.Sprintf("%v", *o.Expand)) + } + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +// List ... +func (c ResourcesClient) List(ctx context.Context, id commonids.SubscriptionId, options ListOperationOptions) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/resources", 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 *[]GenericResourceExpanded `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 ResourcesClient) ListComplete(ctx context.Context, id commonids.SubscriptionId, options ListOperationOptions) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, options, GenericResourceExpandedOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ResourcesClient) ListCompleteMatchingPredicate(ctx context.Context, id commonids.SubscriptionId, options ListOperationOptions, predicate GenericResourceExpandedOperationPredicate) (result ListCompleteResult, err error) { + items := make([]GenericResourceExpanded, 0) + + resp, err := c.List(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 = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/resources/2015-11-01/resources/method_moveresources.go b/resource-manager/resources/2015-11-01/resources/method_moveresources.go new file mode 100644 index 00000000000..424b1c4539e --- /dev/null +++ b/resource-manager/resources/2015-11-01/resources/method_moveresources.go @@ -0,0 +1,75 @@ +package resources + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MoveResourcesOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// MoveResources ... +func (c ResourcesClient) MoveResources(ctx context.Context, id commonids.ResourceGroupId, input ResourcesMoveInfo) (result MoveResourcesOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusNoContent, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/moveResources", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + 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 +} + +// MoveResourcesThenPoll performs MoveResources then polls until it's completed +func (c ResourcesClient) MoveResourcesThenPoll(ctx context.Context, id commonids.ResourceGroupId, input ResourcesMoveInfo) error { + result, err := c.MoveResources(ctx, id, input) + if err != nil { + return fmt.Errorf("performing MoveResources: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after MoveResources: %+v", err) + } + + return nil +} diff --git a/resource-manager/resources/2015-11-01/resources/method_update.go b/resource-manager/resources/2015-11-01/resources/method_update.go new file mode 100644 index 00000000000..86d87e03726 --- /dev/null +++ b/resource-manager/resources/2015-11-01/resources/method_update.go @@ -0,0 +1,76 @@ +package resources + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type UpdateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *GenericResource +} + +// Update ... +func (c ResourcesClient) Update(ctx context.Context, id commonids.ScopeId, input GenericResource) (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 ResourcesClient) UpdateThenPoll(ctx context.Context, id commonids.ScopeId, input GenericResource) 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/resources/2015-11-01/resources/model_genericresource.go b/resource-manager/resources/2015-11-01/resources/model_genericresource.go new file mode 100644 index 00000000000..8988d856fb6 --- /dev/null +++ b/resource-manager/resources/2015-11-01/resources/model_genericresource.go @@ -0,0 +1,14 @@ +package resources + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GenericResource struct { + Id *string `json:"id,omitempty"` + Location string `json:"location"` + Name *string `json:"name,omitempty"` + Plan *Plan `json:"plan,omitempty"` + Properties *interface{} `json:"properties,omitempty"` + Tags *map[string]string `json:"tags,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/resources/2015-11-01/resources/model_genericresourceexpanded.go b/resource-manager/resources/2015-11-01/resources/model_genericresourceexpanded.go new file mode 100644 index 00000000000..407ff1d8785 --- /dev/null +++ b/resource-manager/resources/2015-11-01/resources/model_genericresourceexpanded.go @@ -0,0 +1,47 @@ +package resources + +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 GenericResourceExpanded struct { + ChangedTime *string `json:"changedTime,omitempty"` + CreatedTime *string `json:"createdTime,omitempty"` + Id *string `json:"id,omitempty"` + Location string `json:"location"` + Name *string `json:"name,omitempty"` + Plan *Plan `json:"plan,omitempty"` + Properties *interface{} `json:"properties,omitempty"` + ProvisioningState *string `json:"provisioningState,omitempty"` + Tags *map[string]string `json:"tags,omitempty"` + Type *string `json:"type,omitempty"` +} + +func (o *GenericResourceExpanded) GetChangedTimeAsTime() (*time.Time, error) { + if o.ChangedTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.ChangedTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *GenericResourceExpanded) SetChangedTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.ChangedTime = &formatted +} + +func (o *GenericResourceExpanded) GetCreatedTimeAsTime() (*time.Time, error) { + if o.CreatedTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.CreatedTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *GenericResourceExpanded) SetCreatedTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.CreatedTime = &formatted +} diff --git a/resource-manager/resources/2015-11-01/resources/model_plan.go b/resource-manager/resources/2015-11-01/resources/model_plan.go new file mode 100644 index 00000000000..d34b2a753c6 --- /dev/null +++ b/resource-manager/resources/2015-11-01/resources/model_plan.go @@ -0,0 +1,11 @@ +package resources + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Plan struct { + Name *string `json:"name,omitempty"` + Product *string `json:"product,omitempty"` + PromotionCode *string `json:"promotionCode,omitempty"` + Publisher *string `json:"publisher,omitempty"` +} diff --git a/resource-manager/resources/2015-11-01/resources/model_resourcesmoveinfo.go b/resource-manager/resources/2015-11-01/resources/model_resourcesmoveinfo.go new file mode 100644 index 00000000000..0d90bb09287 --- /dev/null +++ b/resource-manager/resources/2015-11-01/resources/model_resourcesmoveinfo.go @@ -0,0 +1,9 @@ +package resources + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ResourcesMoveInfo struct { + Resources *[]string `json:"resources,omitempty"` + TargetResourceGroup *string `json:"targetResourceGroup,omitempty"` +} diff --git a/resource-manager/resources/2015-11-01/resources/predicates.go b/resource-manager/resources/2015-11-01/resources/predicates.go new file mode 100644 index 00000000000..e4520394f16 --- /dev/null +++ b/resource-manager/resources/2015-11-01/resources/predicates.go @@ -0,0 +1,52 @@ +package resources + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GenericResourceExpandedOperationPredicate struct { + ChangedTime *string + CreatedTime *string + Id *string + Location *string + Name *string + Properties *interface{} + ProvisioningState *string + Type *string +} + +func (p GenericResourceExpandedOperationPredicate) Matches(input GenericResourceExpanded) bool { + + if p.ChangedTime != nil && (input.ChangedTime == nil || *p.ChangedTime != *input.ChangedTime) { + return false + } + + if p.CreatedTime != nil && (input.CreatedTime == nil || *p.CreatedTime != *input.CreatedTime) { + return false + } + + if p.Id != nil && (input.Id == nil || *p.Id != *input.Id) { + return false + } + + if p.Location != nil && *p.Location != input.Location { + return false + } + + if p.Name != nil && (input.Name == nil || *p.Name != *input.Name) { + return false + } + + if p.Properties != nil && (input.Properties == nil || *p.Properties != *input.Properties) { + return false + } + + if p.ProvisioningState != nil && (input.ProvisioningState == nil || *p.ProvisioningState != *input.ProvisioningState) { + return false + } + + if p.Type != nil && (input.Type == nil || *p.Type != *input.Type) { + return false + } + + return true +} diff --git a/resource-manager/resources/2015-11-01/resources/version.go b/resource-manager/resources/2015-11-01/resources/version.go new file mode 100644 index 00000000000..8995760312c --- /dev/null +++ b/resource-manager/resources/2015-11-01/resources/version.go @@ -0,0 +1,12 @@ +package resources + +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 = "2015-11-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/resources/%s", defaultApiVersion) +} diff --git a/resource-manager/resources/2015-11-01/subscriptions/README.md b/resource-manager/resources/2015-11-01/subscriptions/README.md new file mode 100644 index 00000000000..5b1d8a43be7 --- /dev/null +++ b/resource-manager/resources/2015-11-01/subscriptions/README.md @@ -0,0 +1,91 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/resources/2015-11-01/subscriptions` Documentation + +The `subscriptions` SDK allows for interaction with the Azure Resource Manager Service `resources` (API Version `2015-11-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +import "github.com/hashicorp/go-azure-sdk/resource-manager/resources/2015-11-01/subscriptions" +``` + + +### Client Initialization + +```go +client := subscriptions.NewSubscriptionsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `SubscriptionsClient.CheckZonePeers` + +```go +ctx := context.TODO() +id := commonids.NewSubscriptionID("12345678-1234-9876-4563-123456789012") + +payload := subscriptions.CheckZonePeersRequest{ + // ... +} + + +read, err := client.CheckZonePeers(ctx, id, payload) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `SubscriptionsClient.Get` + +```go +ctx := context.TODO() +id := commonids.NewSubscriptionID("12345678-1234-9876-4563-123456789012") + +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: `SubscriptionsClient.List` + +```go +ctx := context.TODO() + + +// alternatively `client.List(ctx)` can be used to do batched pagination +items, err := client.ListComplete(ctx) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `SubscriptionsClient.ListLocations` + +```go +ctx := context.TODO() +id := commonids.NewSubscriptionID("12345678-1234-9876-4563-123456789012") + +read, err := client.ListLocations(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/resources/2015-11-01/subscriptions/client.go b/resource-manager/resources/2015-11-01/subscriptions/client.go new file mode 100644 index 00000000000..09be7cb1cfb --- /dev/null +++ b/resource-manager/resources/2015-11-01/subscriptions/client.go @@ -0,0 +1,26 @@ +package subscriptions + +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 SubscriptionsClient struct { + Client *resourcemanager.Client +} + +func NewSubscriptionsClientWithBaseURI(sdkApi sdkEnv.Api) (*SubscriptionsClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "subscriptions", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating SubscriptionsClient: %+v", err) + } + + return &SubscriptionsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/resources/2015-11-01/subscriptions/method_checkzonepeers.go b/resource-manager/resources/2015-11-01/subscriptions/method_checkzonepeers.go new file mode 100644 index 00000000000..6d405dcc9cf --- /dev/null +++ b/resource-manager/resources/2015-11-01/subscriptions/method_checkzonepeers.go @@ -0,0 +1,60 @@ +package subscriptions + +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 CheckZonePeersOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *CheckZonePeersResult +} + +// CheckZonePeers ... +func (c SubscriptionsClient) CheckZonePeers(ctx context.Context, id commonids.SubscriptionId, input CheckZonePeersRequest) (result CheckZonePeersOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/providers/Microsoft.Resources/checkZonePeers", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model CheckZonePeersResult + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/resources/2015-11-01/subscriptions/method_get.go b/resource-manager/resources/2015-11-01/subscriptions/method_get.go new file mode 100644 index 00000000000..b282b4a832f --- /dev/null +++ b/resource-manager/resources/2015-11-01/subscriptions/method_get.go @@ -0,0 +1,55 @@ +package subscriptions + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// 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 *Subscription +} + +// Get ... +func (c SubscriptionsClient) Get(ctx context.Context, id commonids.SubscriptionId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model Subscription + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/resources/2015-11-01/subscriptions/method_list.go b/resource-manager/resources/2015-11-01/subscriptions/method_list.go new file mode 100644 index 00000000000..2e5fb89ce1d --- /dev/null +++ b/resource-manager/resources/2015-11-01/subscriptions/method_list.go @@ -0,0 +1,91 @@ +package subscriptions + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/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 *[]Subscription +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []Subscription +} + +// List ... +func (c SubscriptionsClient) List(ctx context.Context) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: "/subscriptions", + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]Subscription `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListComplete retrieves all the results into a single object +func (c SubscriptionsClient) ListComplete(ctx context.Context) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, SubscriptionOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c SubscriptionsClient) ListCompleteMatchingPredicate(ctx context.Context, predicate SubscriptionOperationPredicate) (result ListCompleteResult, err error) { + items := make([]Subscription, 0) + + resp, err := c.List(ctx) + 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/resources/2015-11-01/subscriptions/method_listlocations.go b/resource-manager/resources/2015-11-01/subscriptions/method_listlocations.go new file mode 100644 index 00000000000..fd56a2b35c9 --- /dev/null +++ b/resource-manager/resources/2015-11-01/subscriptions/method_listlocations.go @@ -0,0 +1,56 @@ +package subscriptions + +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 ListLocationsOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *LocationListResult +} + +// ListLocations ... +func (c SubscriptionsClient) ListLocations(ctx context.Context, id commonids.SubscriptionId) (result ListLocationsOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/locations", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model LocationListResult + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/resources/2015-11-01/subscriptions/model_availabilityzonepeers.go b/resource-manager/resources/2015-11-01/subscriptions/model_availabilityzonepeers.go new file mode 100644 index 00000000000..b781bc0a41f --- /dev/null +++ b/resource-manager/resources/2015-11-01/subscriptions/model_availabilityzonepeers.go @@ -0,0 +1,9 @@ +package subscriptions + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AvailabilityZonePeers struct { + AvailabilityZone *string `json:"availabilityZone,omitempty"` + Peers *[]Peers `json:"peers,omitempty"` +} diff --git a/resource-manager/resources/2015-11-01/subscriptions/model_checkzonepeersrequest.go b/resource-manager/resources/2015-11-01/subscriptions/model_checkzonepeersrequest.go new file mode 100644 index 00000000000..a7182c1c1e1 --- /dev/null +++ b/resource-manager/resources/2015-11-01/subscriptions/model_checkzonepeersrequest.go @@ -0,0 +1,9 @@ +package subscriptions + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CheckZonePeersRequest struct { + Location *string `json:"location,omitempty"` + SubscriptionIds *[]string `json:"subscriptionIds,omitempty"` +} diff --git a/resource-manager/resources/2015-11-01/subscriptions/model_checkzonepeersresult.go b/resource-manager/resources/2015-11-01/subscriptions/model_checkzonepeersresult.go new file mode 100644 index 00000000000..40750aae541 --- /dev/null +++ b/resource-manager/resources/2015-11-01/subscriptions/model_checkzonepeersresult.go @@ -0,0 +1,10 @@ +package subscriptions + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CheckZonePeersResult struct { + AvailabilityZonePeers *[]AvailabilityZonePeers `json:"availabilityZonePeers,omitempty"` + Location *string `json:"location,omitempty"` + SubscriptionId *string `json:"subscriptionId,omitempty"` +} diff --git a/resource-manager/resources/2015-11-01/subscriptions/model_location.go b/resource-manager/resources/2015-11-01/subscriptions/model_location.go new file mode 100644 index 00000000000..448baf6d231 --- /dev/null +++ b/resource-manager/resources/2015-11-01/subscriptions/model_location.go @@ -0,0 +1,13 @@ +package subscriptions + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Location struct { + DisplayName *string `json:"displayName,omitempty"` + Id *string `json:"id,omitempty"` + Latitude *string `json:"latitude,omitempty"` + Longitude *string `json:"longitude,omitempty"` + Name *string `json:"name,omitempty"` + SubscriptionId *string `json:"subscriptionId,omitempty"` +} diff --git a/resource-manager/resources/2015-11-01/subscriptions/model_locationlistresult.go b/resource-manager/resources/2015-11-01/subscriptions/model_locationlistresult.go new file mode 100644 index 00000000000..7cc6e662b6c --- /dev/null +++ b/resource-manager/resources/2015-11-01/subscriptions/model_locationlistresult.go @@ -0,0 +1,8 @@ +package subscriptions + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type LocationListResult struct { + Value *[]Location `json:"value,omitempty"` +} diff --git a/resource-manager/resources/2015-11-01/subscriptions/model_peers.go b/resource-manager/resources/2015-11-01/subscriptions/model_peers.go new file mode 100644 index 00000000000..4fb02159641 --- /dev/null +++ b/resource-manager/resources/2015-11-01/subscriptions/model_peers.go @@ -0,0 +1,9 @@ +package subscriptions + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Peers struct { + AvailabilityZone *string `json:"availabilityZone,omitempty"` + SubscriptionId *string `json:"subscriptionId,omitempty"` +} diff --git a/resource-manager/resources/2015-11-01/subscriptions/model_subscription.go b/resource-manager/resources/2015-11-01/subscriptions/model_subscription.go new file mode 100644 index 00000000000..4fd1adcff2a --- /dev/null +++ b/resource-manager/resources/2015-11-01/subscriptions/model_subscription.go @@ -0,0 +1,12 @@ +package subscriptions + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Subscription struct { + DisplayName *string `json:"displayName,omitempty"` + Id *string `json:"id,omitempty"` + State *string `json:"state,omitempty"` + SubscriptionId *string `json:"subscriptionId,omitempty"` + SubscriptionPolicies *SubscriptionPolicies `json:"subscriptionPolicies,omitempty"` +} diff --git a/resource-manager/resources/2015-11-01/subscriptions/model_subscriptionpolicies.go b/resource-manager/resources/2015-11-01/subscriptions/model_subscriptionpolicies.go new file mode 100644 index 00000000000..b7f9d0ba6c0 --- /dev/null +++ b/resource-manager/resources/2015-11-01/subscriptions/model_subscriptionpolicies.go @@ -0,0 +1,9 @@ +package subscriptions + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SubscriptionPolicies struct { + LocationPlacementId *string `json:"locationPlacementId,omitempty"` + QuotaId *string `json:"quotaId,omitempty"` +} diff --git a/resource-manager/resources/2015-11-01/subscriptions/predicates.go b/resource-manager/resources/2015-11-01/subscriptions/predicates.go new file mode 100644 index 00000000000..84b4e9dbb78 --- /dev/null +++ b/resource-manager/resources/2015-11-01/subscriptions/predicates.go @@ -0,0 +1,32 @@ +package subscriptions + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SubscriptionOperationPredicate struct { + DisplayName *string + Id *string + State *string + SubscriptionId *string +} + +func (p SubscriptionOperationPredicate) Matches(input Subscription) bool { + + if p.DisplayName != nil && (input.DisplayName == nil || *p.DisplayName != *input.DisplayName) { + return false + } + + if p.Id != nil && (input.Id == nil || *p.Id != *input.Id) { + return false + } + + if p.State != nil && (input.State == nil || *p.State != *input.State) { + return false + } + + if p.SubscriptionId != nil && (input.SubscriptionId == nil || *p.SubscriptionId != *input.SubscriptionId) { + return false + } + + return true +} diff --git a/resource-manager/resources/2015-11-01/subscriptions/version.go b/resource-manager/resources/2015-11-01/subscriptions/version.go new file mode 100644 index 00000000000..033a247c860 --- /dev/null +++ b/resource-manager/resources/2015-11-01/subscriptions/version.go @@ -0,0 +1,12 @@ +package subscriptions + +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 = "2015-11-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/subscriptions/%s", defaultApiVersion) +} diff --git a/resource-manager/resources/2015-11-01/tags/README.md b/resource-manager/resources/2015-11-01/tags/README.md new file mode 100644 index 00000000000..bf674c56fe1 --- /dev/null +++ b/resource-manager/resources/2015-11-01/tags/README.md @@ -0,0 +1,102 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/resources/2015-11-01/tags` Documentation + +The `tags` SDK allows for interaction with the Azure Resource Manager Service `resources` (API Version `2015-11-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +import "github.com/hashicorp/go-azure-sdk/resource-manager/resources/2015-11-01/tags" +``` + + +### Client Initialization + +```go +client := tags.NewTagsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `TagsClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := tags.NewTagNameID("12345678-1234-9876-4563-123456789012", "tagValue") + +read, err := client.CreateOrUpdate(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `TagsClient.CreateOrUpdateValue` + +```go +ctx := context.TODO() +id := tags.NewTagValueID("12345678-1234-9876-4563-123456789012", "tagValue", "tagValueValue") + +read, err := client.CreateOrUpdateValue(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `TagsClient.Delete` + +```go +ctx := context.TODO() +id := tags.NewTagNameID("12345678-1234-9876-4563-123456789012", "tagValue") + +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: `TagsClient.DeleteValue` + +```go +ctx := context.TODO() +id := tags.NewTagValueID("12345678-1234-9876-4563-123456789012", "tagValue", "tagValueValue") + +read, err := client.DeleteValue(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `TagsClient.List` + +```go +ctx := context.TODO() +id := commonids.NewSubscriptionID("12345678-1234-9876-4563-123456789012") + +// alternatively `client.List(ctx, id)` can be used to do batched pagination +items, err := client.ListComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/resources/2015-11-01/tags/client.go b/resource-manager/resources/2015-11-01/tags/client.go new file mode 100644 index 00000000000..8ef9b9a30b4 --- /dev/null +++ b/resource-manager/resources/2015-11-01/tags/client.go @@ -0,0 +1,26 @@ +package tags + +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 TagsClient struct { + Client *resourcemanager.Client +} + +func NewTagsClientWithBaseURI(sdkApi sdkEnv.Api) (*TagsClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "tags", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating TagsClient: %+v", err) + } + + return &TagsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/resources/2015-11-01/tags/id_tagname.go b/resource-manager/resources/2015-11-01/tags/id_tagname.go new file mode 100644 index 00000000000..44322e58a52 --- /dev/null +++ b/resource-manager/resources/2015-11-01/tags/id_tagname.go @@ -0,0 +1,119 @@ +package tags + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&TagNameId{}) +} + +var _ resourceids.ResourceId = &TagNameId{} + +// TagNameId is a struct representing the Resource ID for a Tag Name +type TagNameId struct { + SubscriptionId string + TagName string +} + +// NewTagNameID returns a new TagNameId struct +func NewTagNameID(subscriptionId string, tagName string) TagNameId { + return TagNameId{ + SubscriptionId: subscriptionId, + TagName: tagName, + } +} + +// ParseTagNameID parses 'input' into a TagNameId +func ParseTagNameID(input string) (*TagNameId, error) { + parser := resourceids.NewParserFromResourceIdType(&TagNameId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := TagNameId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseTagNameIDInsensitively parses 'input' case-insensitively into a TagNameId +// note: this method should only be used for API response data and not user input +func ParseTagNameIDInsensitively(input string) (*TagNameId, error) { + parser := resourceids.NewParserFromResourceIdType(&TagNameId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := TagNameId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *TagNameId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.TagName, ok = input.Parsed["tagName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "tagName", input) + } + + return nil +} + +// ValidateTagNameID checks that 'input' can be parsed as a Tag Name ID +func ValidateTagNameID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseTagNameID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Tag Name ID +func (id TagNameId) ID() string { + fmtString := "/subscriptions/%s/tagNames/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.TagName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Tag Name ID +func (id TagNameId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticTagNames", "tagNames", "tagNames"), + resourceids.UserSpecifiedSegment("tagName", "tagValue"), + } +} + +// String returns a human-readable description of this Tag Name ID +func (id TagNameId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Tag Name: %q", id.TagName), + } + return fmt.Sprintf("Tag Name (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/resources/2015-11-01/tags/id_tagname_test.go b/resource-manager/resources/2015-11-01/tags/id_tagname_test.go new file mode 100644 index 00000000000..1a71d80e6a6 --- /dev/null +++ b/resource-manager/resources/2015-11-01/tags/id_tagname_test.go @@ -0,0 +1,207 @@ +package tags + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &TagNameId{} + +func TestNewTagNameID(t *testing.T) { + id := NewTagNameID("12345678-1234-9876-4563-123456789012", "tagValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.TagName != "tagValue" { + t.Fatalf("Expected %q but got %q for Segment 'TagName'", id.TagName, "tagValue") + } +} + +func TestFormatTagNameID(t *testing.T) { + actual := NewTagNameID("12345678-1234-9876-4563-123456789012", "tagValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/tagNames/tagValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseTagNameID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *TagNameId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/tagNames", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/tagNames/tagValue", + Expected: &TagNameId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + TagName: "tagValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/tagNames/tagValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseTagNameID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.TagName != v.Expected.TagName { + t.Fatalf("Expected %q but got %q for TagName", v.Expected.TagName, actual.TagName) + } + + } +} + +func TestParseTagNameIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *TagNameId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/tagNames", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/tAgNaMeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/tagNames/tagValue", + Expected: &TagNameId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + TagName: "tagValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/tagNames/tagValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/tAgNaMeS/tAgVaLuE", + Expected: &TagNameId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + TagName: "tAgVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/tAgNaMeS/tAgVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseTagNameIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.TagName != v.Expected.TagName { + t.Fatalf("Expected %q but got %q for TagName", v.Expected.TagName, actual.TagName) + } + + } +} + +func TestSegmentsForTagNameId(t *testing.T) { + segments := TagNameId{}.Segments() + if len(segments) == 0 { + t.Fatalf("TagNameId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/resources/2015-11-01/tags/id_tagvalue.go b/resource-manager/resources/2015-11-01/tags/id_tagvalue.go new file mode 100644 index 00000000000..b7c8bfa6265 --- /dev/null +++ b/resource-manager/resources/2015-11-01/tags/id_tagvalue.go @@ -0,0 +1,128 @@ +package tags + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&TagValueId{}) +} + +var _ resourceids.ResourceId = &TagValueId{} + +// TagValueId is a struct representing the Resource ID for a Tag Value +type TagValueId struct { + SubscriptionId string + TagName string + TagValueName string +} + +// NewTagValueID returns a new TagValueId struct +func NewTagValueID(subscriptionId string, tagName string, tagValueName string) TagValueId { + return TagValueId{ + SubscriptionId: subscriptionId, + TagName: tagName, + TagValueName: tagValueName, + } +} + +// ParseTagValueID parses 'input' into a TagValueId +func ParseTagValueID(input string) (*TagValueId, error) { + parser := resourceids.NewParserFromResourceIdType(&TagValueId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := TagValueId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseTagValueIDInsensitively parses 'input' case-insensitively into a TagValueId +// note: this method should only be used for API response data and not user input +func ParseTagValueIDInsensitively(input string) (*TagValueId, error) { + parser := resourceids.NewParserFromResourceIdType(&TagValueId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := TagValueId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *TagValueId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.TagName, ok = input.Parsed["tagName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "tagName", input) + } + + if id.TagValueName, ok = input.Parsed["tagValueName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "tagValueName", input) + } + + return nil +} + +// ValidateTagValueID checks that 'input' can be parsed as a Tag Value ID +func ValidateTagValueID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseTagValueID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Tag Value ID +func (id TagValueId) ID() string { + fmtString := "/subscriptions/%s/tagNames/%s/tagValues/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.TagName, id.TagValueName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Tag Value ID +func (id TagValueId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticTagNames", "tagNames", "tagNames"), + resourceids.UserSpecifiedSegment("tagName", "tagValue"), + resourceids.StaticSegment("staticTagValues", "tagValues", "tagValues"), + resourceids.UserSpecifiedSegment("tagValueName", "tagValueValue"), + } +} + +// String returns a human-readable description of this Tag Value ID +func (id TagValueId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Tag Name: %q", id.TagName), + fmt.Sprintf("Tag Value Name: %q", id.TagValueName), + } + return fmt.Sprintf("Tag Value (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/resources/2015-11-01/tags/id_tagvalue_test.go b/resource-manager/resources/2015-11-01/tags/id_tagvalue_test.go new file mode 100644 index 00000000000..a3b402d96ab --- /dev/null +++ b/resource-manager/resources/2015-11-01/tags/id_tagvalue_test.go @@ -0,0 +1,252 @@ +package tags + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &TagValueId{} + +func TestNewTagValueID(t *testing.T) { + id := NewTagValueID("12345678-1234-9876-4563-123456789012", "tagValue", "tagValueValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.TagName != "tagValue" { + t.Fatalf("Expected %q but got %q for Segment 'TagName'", id.TagName, "tagValue") + } + + if id.TagValueName != "tagValueValue" { + t.Fatalf("Expected %q but got %q for Segment 'TagValueName'", id.TagValueName, "tagValueValue") + } +} + +func TestFormatTagValueID(t *testing.T) { + actual := NewTagValueID("12345678-1234-9876-4563-123456789012", "tagValue", "tagValueValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/tagNames/tagValue/tagValues/tagValueValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseTagValueID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *TagValueId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/tagNames", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/tagNames/tagValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/tagNames/tagValue/tagValues", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/tagNames/tagValue/tagValues/tagValueValue", + Expected: &TagValueId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + TagName: "tagValue", + TagValueName: "tagValueValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/tagNames/tagValue/tagValues/tagValueValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseTagValueID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.TagName != v.Expected.TagName { + t.Fatalf("Expected %q but got %q for TagName", v.Expected.TagName, actual.TagName) + } + + if actual.TagValueName != v.Expected.TagValueName { + t.Fatalf("Expected %q but got %q for TagValueName", v.Expected.TagValueName, actual.TagValueName) + } + + } +} + +func TestParseTagValueIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *TagValueId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/tagNames", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/tAgNaMeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/tagNames/tagValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/tAgNaMeS/tAgVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/tagNames/tagValue/tagValues", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/tAgNaMeS/tAgVaLuE/tAgVaLuEs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/tagNames/tagValue/tagValues/tagValueValue", + Expected: &TagValueId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + TagName: "tagValue", + TagValueName: "tagValueValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/tagNames/tagValue/tagValues/tagValueValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/tAgNaMeS/tAgVaLuE/tAgVaLuEs/tAgVaLuEvAlUe", + Expected: &TagValueId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + TagName: "tAgVaLuE", + TagValueName: "tAgVaLuEvAlUe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/tAgNaMeS/tAgVaLuE/tAgVaLuEs/tAgVaLuEvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseTagValueIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.TagName != v.Expected.TagName { + t.Fatalf("Expected %q but got %q for TagName", v.Expected.TagName, actual.TagName) + } + + if actual.TagValueName != v.Expected.TagValueName { + t.Fatalf("Expected %q but got %q for TagValueName", v.Expected.TagValueName, actual.TagValueName) + } + + } +} + +func TestSegmentsForTagValueId(t *testing.T) { + segments := TagValueId{}.Segments() + if len(segments) == 0 { + t.Fatalf("TagValueId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/resources/2015-11-01/tags/method_createorupdate.go b/resource-manager/resources/2015-11-01/tags/method_createorupdate.go new file mode 100644 index 00000000000..1ecb632da6d --- /dev/null +++ b/resource-manager/resources/2015-11-01/tags/method_createorupdate.go @@ -0,0 +1,55 @@ +package tags + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/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 *TagDetails +} + +// CreateOrUpdate ... +func (c TagsClient) CreateOrUpdate(ctx context.Context, id TagNameId) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model TagDetails + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/resources/2015-11-01/tags/method_createorupdatevalue.go b/resource-manager/resources/2015-11-01/tags/method_createorupdatevalue.go new file mode 100644 index 00000000000..af5cdd0624b --- /dev/null +++ b/resource-manager/resources/2015-11-01/tags/method_createorupdatevalue.go @@ -0,0 +1,55 @@ +package tags + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOrUpdateValueOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *TagValue +} + +// CreateOrUpdateValue ... +func (c TagsClient) CreateOrUpdateValue(ctx context.Context, id TagValueId) (result CreateOrUpdateValueOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model TagValue + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/resources/2015-11-01/tags/method_delete.go b/resource-manager/resources/2015-11-01/tags/method_delete.go new file mode 100644 index 00000000000..f1d45af739d --- /dev/null +++ b/resource-manager/resources/2015-11-01/tags/method_delete.go @@ -0,0 +1,47 @@ +package tags + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// Delete ... +func (c TagsClient) Delete(ctx context.Context, id TagNameId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/resources/2015-11-01/tags/method_deletevalue.go b/resource-manager/resources/2015-11-01/tags/method_deletevalue.go new file mode 100644 index 00000000000..63a72bc151e --- /dev/null +++ b/resource-manager/resources/2015-11-01/tags/method_deletevalue.go @@ -0,0 +1,47 @@ +package tags + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteValueOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// DeleteValue ... +func (c TagsClient) DeleteValue(ctx context.Context, id TagValueId) (result DeleteValueOperationResponse, 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/resources/2015-11-01/tags/method_list.go b/resource-manager/resources/2015-11-01/tags/method_list.go new file mode 100644 index 00000000000..12cdf91995e --- /dev/null +++ b/resource-manager/resources/2015-11-01/tags/method_list.go @@ -0,0 +1,92 @@ +package tags + +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 *[]TagDetails +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []TagDetails +} + +// List ... +func (c TagsClient) 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/tagNames", 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 *[]TagDetails `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 TagsClient) ListComplete(ctx context.Context, id commonids.SubscriptionId) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, TagDetailsOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c TagsClient) ListCompleteMatchingPredicate(ctx context.Context, id commonids.SubscriptionId, predicate TagDetailsOperationPredicate) (result ListCompleteResult, err error) { + items := make([]TagDetails, 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/resources/2015-11-01/tags/model_tagcount.go b/resource-manager/resources/2015-11-01/tags/model_tagcount.go new file mode 100644 index 00000000000..9b6b46cb693 --- /dev/null +++ b/resource-manager/resources/2015-11-01/tags/model_tagcount.go @@ -0,0 +1,9 @@ +package tags + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type TagCount struct { + Type *string `json:"type,omitempty"` + Value *string `json:"value,omitempty"` +} diff --git a/resource-manager/resources/2015-11-01/tags/model_tagdetails.go b/resource-manager/resources/2015-11-01/tags/model_tagdetails.go new file mode 100644 index 00000000000..8123c21aaff --- /dev/null +++ b/resource-manager/resources/2015-11-01/tags/model_tagdetails.go @@ -0,0 +1,11 @@ +package tags + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type TagDetails struct { + Count *TagCount `json:"count,omitempty"` + Id *string `json:"id,omitempty"` + TagName *string `json:"tagName,omitempty"` + Values *[]TagValue `json:"values,omitempty"` +} diff --git a/resource-manager/resources/2015-11-01/tags/model_tagvalue.go b/resource-manager/resources/2015-11-01/tags/model_tagvalue.go new file mode 100644 index 00000000000..7c276e68277 --- /dev/null +++ b/resource-manager/resources/2015-11-01/tags/model_tagvalue.go @@ -0,0 +1,10 @@ +package tags + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type TagValue struct { + Count *TagCount `json:"count,omitempty"` + Id *string `json:"id,omitempty"` + TagValue *string `json:"tagValue,omitempty"` +} diff --git a/resource-manager/resources/2015-11-01/tags/predicates.go b/resource-manager/resources/2015-11-01/tags/predicates.go new file mode 100644 index 00000000000..8ff401b12ca --- /dev/null +++ b/resource-manager/resources/2015-11-01/tags/predicates.go @@ -0,0 +1,22 @@ +package tags + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type TagDetailsOperationPredicate struct { + Id *string + TagName *string +} + +func (p TagDetailsOperationPredicate) Matches(input TagDetails) bool { + + if p.Id != nil && (input.Id == nil || *p.Id != *input.Id) { + return false + } + + if p.TagName != nil && (input.TagName == nil || *p.TagName != *input.TagName) { + return false + } + + return true +} diff --git a/resource-manager/resources/2015-11-01/tags/version.go b/resource-manager/resources/2015-11-01/tags/version.go new file mode 100644 index 00000000000..9750331c88d --- /dev/null +++ b/resource-manager/resources/2015-11-01/tags/version.go @@ -0,0 +1,12 @@ +package tags + +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 = "2015-11-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/tags/%s", defaultApiVersion) +} diff --git a/resource-manager/resources/2015-11-01/tenants/README.md b/resource-manager/resources/2015-11-01/tenants/README.md new file mode 100644 index 00000000000..3686d62cbe4 --- /dev/null +++ b/resource-manager/resources/2015-11-01/tenants/README.md @@ -0,0 +1,57 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/resources/2015-11-01/tenants` Documentation + +The `tenants` SDK allows for interaction with the Azure Resource Manager Service `resources` (API Version `2015-11-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/resources/2015-11-01/tenants" +``` + + +### Client Initialization + +```go +client := tenants.NewTenantsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `TenantsClient.CheckResourceName` + +```go +ctx := context.TODO() + +payload := tenants.ResourceName{ + // ... +} + + +read, err := client.CheckResourceName(ctx, payload) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `TenantsClient.List` + +```go +ctx := context.TODO() + + +// alternatively `client.List(ctx)` can be used to do batched pagination +items, err := client.ListComplete(ctx) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/resources/2015-11-01/tenants/client.go b/resource-manager/resources/2015-11-01/tenants/client.go new file mode 100644 index 00000000000..1be7e109076 --- /dev/null +++ b/resource-manager/resources/2015-11-01/tenants/client.go @@ -0,0 +1,26 @@ +package tenants + +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 TenantsClient struct { + Client *resourcemanager.Client +} + +func NewTenantsClientWithBaseURI(sdkApi sdkEnv.Api) (*TenantsClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "tenants", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating TenantsClient: %+v", err) + } + + return &TenantsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/resources/2015-11-01/tenants/constants.go b/resource-manager/resources/2015-11-01/tenants/constants.go new file mode 100644 index 00000000000..119aebec6a1 --- /dev/null +++ b/resource-manager/resources/2015-11-01/tenants/constants.go @@ -0,0 +1,51 @@ +package tenants + +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 ResourceNameStatus string + +const ( + ResourceNameStatusAllowed ResourceNameStatus = "Allowed" + ResourceNameStatusReserved ResourceNameStatus = "Reserved" +) + +func PossibleValuesForResourceNameStatus() []string { + return []string{ + string(ResourceNameStatusAllowed), + string(ResourceNameStatusReserved), + } +} + +func (s *ResourceNameStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseResourceNameStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseResourceNameStatus(input string) (*ResourceNameStatus, error) { + vals := map[string]ResourceNameStatus{ + "allowed": ResourceNameStatusAllowed, + "reserved": ResourceNameStatusReserved, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ResourceNameStatus(input) + return &out, nil +} diff --git a/resource-manager/resources/2015-11-01/tenants/method_checkresourcename.go b/resource-manager/resources/2015-11-01/tenants/method_checkresourcename.go new file mode 100644 index 00000000000..8e2aa51e8f4 --- /dev/null +++ b/resource-manager/resources/2015-11-01/tenants/method_checkresourcename.go @@ -0,0 +1,58 @@ +package tenants + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CheckResourceNameOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *CheckResourceNameResult +} + +// CheckResourceName ... +func (c TenantsClient) CheckResourceName(ctx context.Context, input ResourceName) (result CheckResourceNameOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: "/providers/Microsoft.Resources/checkResourceName", + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model CheckResourceNameResult + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/resources/2015-11-01/tenants/method_list.go b/resource-manager/resources/2015-11-01/tenants/method_list.go new file mode 100644 index 00000000000..0c487f73014 --- /dev/null +++ b/resource-manager/resources/2015-11-01/tenants/method_list.go @@ -0,0 +1,91 @@ +package tenants + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/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 *[]TenantIdDescription +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []TenantIdDescription +} + +// List ... +func (c TenantsClient) List(ctx context.Context) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: "/tenants", + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]TenantIdDescription `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 TenantsClient) ListComplete(ctx context.Context) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, TenantIdDescriptionOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c TenantsClient) ListCompleteMatchingPredicate(ctx context.Context, predicate TenantIdDescriptionOperationPredicate) (result ListCompleteResult, err error) { + items := make([]TenantIdDescription, 0) + + resp, err := c.List(ctx) + 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/resources/2015-11-01/tenants/model_checkresourcenameresult.go b/resource-manager/resources/2015-11-01/tenants/model_checkresourcenameresult.go new file mode 100644 index 00000000000..ece46798e45 --- /dev/null +++ b/resource-manager/resources/2015-11-01/tenants/model_checkresourcenameresult.go @@ -0,0 +1,10 @@ +package tenants + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CheckResourceNameResult struct { + Name *string `json:"name,omitempty"` + Status *ResourceNameStatus `json:"status,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/resources/2015-11-01/tenants/model_resourcename.go b/resource-manager/resources/2015-11-01/tenants/model_resourcename.go new file mode 100644 index 00000000000..59d64adf843 --- /dev/null +++ b/resource-manager/resources/2015-11-01/tenants/model_resourcename.go @@ -0,0 +1,9 @@ +package tenants + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ResourceName struct { + Name string `json:"name"` + Type string `json:"type"` +} diff --git a/resource-manager/resources/2015-11-01/tenants/model_tenantiddescription.go b/resource-manager/resources/2015-11-01/tenants/model_tenantiddescription.go new file mode 100644 index 00000000000..12b7d7158a8 --- /dev/null +++ b/resource-manager/resources/2015-11-01/tenants/model_tenantiddescription.go @@ -0,0 +1,9 @@ +package tenants + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type TenantIdDescription struct { + Id *string `json:"id,omitempty"` + TenantId *string `json:"tenantId,omitempty"` +} diff --git a/resource-manager/resources/2015-11-01/tenants/predicates.go b/resource-manager/resources/2015-11-01/tenants/predicates.go new file mode 100644 index 00000000000..f2cb6fe1f29 --- /dev/null +++ b/resource-manager/resources/2015-11-01/tenants/predicates.go @@ -0,0 +1,22 @@ +package tenants + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type TenantIdDescriptionOperationPredicate struct { + Id *string + TenantId *string +} + +func (p TenantIdDescriptionOperationPredicate) Matches(input TenantIdDescription) bool { + + if p.Id != nil && (input.Id == nil || *p.Id != *input.Id) { + return false + } + + if p.TenantId != nil && (input.TenantId == nil || *p.TenantId != *input.TenantId) { + return false + } + + return true +} diff --git a/resource-manager/resources/2015-11-01/tenants/version.go b/resource-manager/resources/2015-11-01/tenants/version.go new file mode 100644 index 00000000000..38b3401304a --- /dev/null +++ b/resource-manager/resources/2015-11-01/tenants/version.go @@ -0,0 +1,12 @@ +package tenants + +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 = "2015-11-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/tenants/%s", defaultApiVersion) +}