From 3e5a32ab4182cbb17f4f62c3b9946a2f1b5817ab Mon Sep 17 00:00:00 2001 From: SDKAuto Date: Mon, 22 May 2023 09:10:04 +0000 Subject: [PATCH] CodeGen from PR 24088 in Azure/azure-rest-api-specs Merge f0ff264de63f4aefa8f4858c805b12c5d996079e into 529205bb71049de32c1126c69b6016904261da32 --- .../resources/armpolicy/CHANGELOG.md | 46 + .../resources/armpolicy/assignments_client.go | 48 +- .../assignments_client_example_test.go | 1067 ----------------- .../resources/armpolicy/autorest.md | 6 +- .../resources/armpolicy/client_factory.go | 20 +- .../resources/armpolicy/constants.go | 60 +- ...datapolicymanifests_client_example_test.go | 278 ----- .../definitions_client_example_test.go | 806 ------------- .../resources/armpolicy/exemptions_client.go | 83 +- .../exemptions_client_example_test.go | 432 ------- .../resources/armpolicy/go.mod | 2 +- .../resources/armpolicy/models.go | 248 ++++ .../resources/armpolicy/models_serde.go | 470 ++++++++ .../resources/armpolicy/response_types.go | 85 ++ .../setdefinitions_client_example_test.go | 1028 ---------------- .../resources/armpolicy/variables_client.go | 475 ++++++++ .../armpolicy/variablevalues_client.go | 518 ++++++++ 17 files changed, 2013 insertions(+), 3659 deletions(-) delete mode 100644 sdk/resourcemanager/resources/armpolicy/assignments_client_example_test.go delete mode 100644 sdk/resourcemanager/resources/armpolicy/datapolicymanifests_client_example_test.go delete mode 100644 sdk/resourcemanager/resources/armpolicy/definitions_client_example_test.go delete mode 100644 sdk/resourcemanager/resources/armpolicy/exemptions_client_example_test.go delete mode 100644 sdk/resourcemanager/resources/armpolicy/setdefinitions_client_example_test.go create mode 100644 sdk/resourcemanager/resources/armpolicy/variables_client.go create mode 100644 sdk/resourcemanager/resources/armpolicy/variablevalues_client.go diff --git a/sdk/resourcemanager/resources/armpolicy/CHANGELOG.md b/sdk/resourcemanager/resources/armpolicy/CHANGELOG.md index 280084c8f79c..c3cb1b9b3e20 100644 --- a/sdk/resourcemanager/resources/armpolicy/CHANGELOG.md +++ b/sdk/resourcemanager/resources/armpolicy/CHANGELOG.md @@ -1,5 +1,51 @@ # Release History +## 0.8.0 (2023-05-22) +### Features Added + +- New enum type `AssignmentScopeValidation` with values `AssignmentScopeValidationDefault`, `AssignmentScopeValidationDoNotValidate` +- New enum type `OverrideKind` with values `OverrideKindPolicyEffect` +- New enum type `SelectorKind` with values `SelectorKindPolicyDefinitionReferenceID`, `SelectorKindResourceLocation`, `SelectorKindResourceType`, `SelectorKindResourceWithoutLocation` +- New function `*ClientFactory.NewVariableValuesClient() *VariableValuesClient` +- New function `*ClientFactory.NewVariablesClient() *VariablesClient` +- New function `*ExemptionsClient.Update(context.Context, string, string, ExemptionUpdate, *ExemptionsClientUpdateOptions) (ExemptionsClientUpdateResponse, error)` +- New function `NewVariableValuesClient(string, azcore.TokenCredential, *arm.ClientOptions) (*VariableValuesClient, error)` +- New function `*VariableValuesClient.CreateOrUpdate(context.Context, string, string, VariableValue, *VariableValuesClientCreateOrUpdateOptions) (VariableValuesClientCreateOrUpdateResponse, error)` +- New function `*VariableValuesClient.CreateOrUpdateAtManagementGroup(context.Context, string, string, string, VariableValue, *VariableValuesClientCreateOrUpdateAtManagementGroupOptions) (VariableValuesClientCreateOrUpdateAtManagementGroupResponse, error)` +- New function `*VariableValuesClient.Delete(context.Context, string, string, *VariableValuesClientDeleteOptions) (VariableValuesClientDeleteResponse, error)` +- New function `*VariableValuesClient.DeleteAtManagementGroup(context.Context, string, string, string, *VariableValuesClientDeleteAtManagementGroupOptions) (VariableValuesClientDeleteAtManagementGroupResponse, error)` +- New function `*VariableValuesClient.Get(context.Context, string, string, *VariableValuesClientGetOptions) (VariableValuesClientGetResponse, error)` +- New function `*VariableValuesClient.GetAtManagementGroup(context.Context, string, string, string, *VariableValuesClientGetAtManagementGroupOptions) (VariableValuesClientGetAtManagementGroupResponse, error)` +- New function `*VariableValuesClient.NewListForManagementGroupPager(string, string, *VariableValuesClientListForManagementGroupOptions) *runtime.Pager[VariableValuesClientListForManagementGroupResponse]` +- New function `*VariableValuesClient.NewListPager(string, *VariableValuesClientListOptions) *runtime.Pager[VariableValuesClientListResponse]` +- New function `NewVariablesClient(string, azcore.TokenCredential, *arm.ClientOptions) (*VariablesClient, error)` +- New function `*VariablesClient.CreateOrUpdate(context.Context, string, Variable, *VariablesClientCreateOrUpdateOptions) (VariablesClientCreateOrUpdateResponse, error)` +- New function `*VariablesClient.CreateOrUpdateAtManagementGroup(context.Context, string, string, Variable, *VariablesClientCreateOrUpdateAtManagementGroupOptions) (VariablesClientCreateOrUpdateAtManagementGroupResponse, error)` +- New function `*VariablesClient.Delete(context.Context, string, *VariablesClientDeleteOptions) (VariablesClientDeleteResponse, error)` +- New function `*VariablesClient.DeleteAtManagementGroup(context.Context, string, string, *VariablesClientDeleteAtManagementGroupOptions) (VariablesClientDeleteAtManagementGroupResponse, error)` +- New function `*VariablesClient.Get(context.Context, string, *VariablesClientGetOptions) (VariablesClientGetResponse, error)` +- New function `*VariablesClient.GetAtManagementGroup(context.Context, string, string, *VariablesClientGetAtManagementGroupOptions) (VariablesClientGetAtManagementGroupResponse, error)` +- New function `*VariablesClient.NewListForManagementGroupPager(string, *VariablesClientListForManagementGroupOptions) *runtime.Pager[VariablesClientListForManagementGroupResponse]` +- New function `*VariablesClient.NewListPager(*VariablesClientListOptions) *runtime.Pager[VariablesClientListResponse]` +- New struct `AssignmentUpdateProperties` +- New struct `ExemptionUpdate` +- New struct `ExemptionUpdateProperties` +- New struct `Override` +- New struct `ResourceSelector` +- New struct `Selector` +- New struct `Variable` +- New struct `VariableColumn` +- New struct `VariableListResult` +- New struct `VariableProperties` +- New struct `VariableValue` +- New struct `VariableValueColumnValue` +- New struct `VariableValueListResult` +- New struct `VariableValueProperties` +- New field `Overrides`, `ResourceSelectors` in struct `AssignmentProperties` +- New field `Properties` in struct `AssignmentUpdate` +- New field `AssignmentScopeValidation`, `ResourceSelectors` in struct `ExemptionProperties` + + ## 0.7.1 (2023-04-14) ### Bug Fixes diff --git a/sdk/resourcemanager/resources/armpolicy/assignments_client.go b/sdk/resourcemanager/resources/armpolicy/assignments_client.go index b37a2d5eaeb2..85a074f5bc1b 100644 --- a/sdk/resourcemanager/resources/armpolicy/assignments_client.go +++ b/sdk/resourcemanager/resources/armpolicy/assignments_client.go @@ -50,7 +50,7 @@ func NewAssignmentsClient(subscriptionID string, credential azcore.TokenCredenti // resource group scope, that policy applies to all resources in the group. // If the operation fails it returns an *azcore.ResponseError type. // -// Generated from API version 2021-06-01 +// Generated from API version 2022-06-01 // - scope - The scope of the policy assignment. Valid scopes are: management group (format: '/providers/Microsoft.Management/managementGroups/{managementGroup}'), // subscription (format: // '/subscriptions/{subscriptionId}'), resource group (format: '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}', @@ -87,7 +87,7 @@ func (client *AssignmentsClient) createCreateRequest(ctx context.Context, scope return nil, err } reqQP := req.Raw().URL.Query() - reqQP.Set("api-version", "2021-06-01") + reqQP.Set("api-version", "2022-06-01") req.Raw().URL.RawQuery = reqQP.Encode() req.Raw().Header["Accept"] = []string{"application/json"} return req, runtime.MarshalAsJSON(req, parameters) @@ -112,7 +112,7 @@ func (client *AssignmentsClient) createHandleResponse(resp *http.Response) (Assi // '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}'. // If the operation fails it returns an *azcore.ResponseError type. // -// Generated from API version 2021-06-01 +// Generated from API version 2022-06-01 // - policyAssignmentID - The ID of the policy assignment to create. Use the format '{scope}/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}'. // - parameters - Parameters for policy assignment. // - options - AssignmentsClientCreateByIDOptions contains the optional parameters for the AssignmentsClient.CreateByID method. @@ -140,7 +140,7 @@ func (client *AssignmentsClient) createByIDCreateRequest(ctx context.Context, po return nil, err } reqQP := req.Raw().URL.Query() - reqQP.Set("api-version", "2021-06-01") + reqQP.Set("api-version", "2022-06-01") req.Raw().URL.RawQuery = reqQP.Encode() req.Raw().Header["Accept"] = []string{"application/json"} return req, runtime.MarshalAsJSON(req, parameters) @@ -160,7 +160,7 @@ func (client *AssignmentsClient) createByIDHandleResponse(resp *http.Response) ( // '/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}'. // If the operation fails it returns an *azcore.ResponseError type. // -// Generated from API version 2021-06-01 +// Generated from API version 2022-06-01 // - scope - The scope of the policy assignment. Valid scopes are: management group (format: '/providers/Microsoft.Management/managementGroups/{managementGroup}'), // subscription (format: // '/subscriptions/{subscriptionId}'), resource group (format: '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}', @@ -196,7 +196,7 @@ func (client *AssignmentsClient) deleteCreateRequest(ctx context.Context, scope return nil, err } reqQP := req.Raw().URL.Query() - reqQP.Set("api-version", "2021-06-01") + reqQP.Set("api-version", "2022-06-01") req.Raw().URL.RawQuery = reqQP.Encode() req.Raw().Header["Accept"] = []string{"application/json"} return req, nil @@ -220,7 +220,7 @@ func (client *AssignmentsClient) deleteHandleResponse(resp *http.Response) (Assi // (resource). // If the operation fails it returns an *azcore.ResponseError type. // -// Generated from API version 2021-06-01 +// Generated from API version 2022-06-01 // - policyAssignmentID - The ID of the policy assignment to delete. Use the format '{scope}/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}'. // - options - AssignmentsClientDeleteByIDOptions contains the optional parameters for the AssignmentsClient.DeleteByID method. func (client *AssignmentsClient) DeleteByID(ctx context.Context, policyAssignmentID string, options *AssignmentsClientDeleteByIDOptions) (AssignmentsClientDeleteByIDResponse, error) { @@ -247,7 +247,7 @@ func (client *AssignmentsClient) deleteByIDCreateRequest(ctx context.Context, po return nil, err } reqQP := req.Raw().URL.Query() - reqQP.Set("api-version", "2021-06-01") + reqQP.Set("api-version", "2022-06-01") req.Raw().URL.RawQuery = reqQP.Encode() req.Raw().Header["Accept"] = []string{"application/json"} return req, nil @@ -265,7 +265,7 @@ func (client *AssignmentsClient) deleteByIDHandleResponse(resp *http.Response) ( // Get - This operation retrieves a single policy assignment, given its name and the scope it was created at. // If the operation fails it returns an *azcore.ResponseError type. // -// Generated from API version 2021-06-01 +// Generated from API version 2022-06-01 // - scope - The scope of the policy assignment. Valid scopes are: management group (format: '/providers/Microsoft.Management/managementGroups/{managementGroup}'), // subscription (format: // '/subscriptions/{subscriptionId}'), resource group (format: '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}', @@ -301,7 +301,7 @@ func (client *AssignmentsClient) getCreateRequest(ctx context.Context, scope str return nil, err } reqQP := req.Raw().URL.Query() - reqQP.Set("api-version", "2021-06-01") + reqQP.Set("api-version", "2022-06-01") req.Raw().URL.RawQuery = reqQP.Encode() req.Raw().Header["Accept"] = []string{"application/json"} return req, nil @@ -324,7 +324,7 @@ func (client *AssignmentsClient) getHandleResponse(resp *http.Response) (Assignm // '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}'. // If the operation fails it returns an *azcore.ResponseError type. // -// Generated from API version 2021-06-01 +// Generated from API version 2022-06-01 // - policyAssignmentID - The ID of the policy assignment to get. Use the format '{scope}/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}'. // - options - AssignmentsClientGetByIDOptions contains the optional parameters for the AssignmentsClient.GetByID method. func (client *AssignmentsClient) GetByID(ctx context.Context, policyAssignmentID string, options *AssignmentsClientGetByIDOptions) (AssignmentsClientGetByIDResponse, error) { @@ -351,7 +351,7 @@ func (client *AssignmentsClient) getByIDCreateRequest(ctx context.Context, polic return nil, err } reqQP := req.Raw().URL.Query() - reqQP.Set("api-version", "2021-06-01") + reqQP.Set("api-version", "2022-06-01") req.Raw().URL.RawQuery = reqQP.Encode() req.Raw().Header["Accept"] = []string{"application/json"} return req, nil @@ -378,7 +378,7 @@ func (client *AssignmentsClient) getByIDHandleResponse(resp *http.Response) (Ass // is provided, the returned list includes all policy assignments of the policy // definition whose id is {value}. // -// Generated from API version 2021-06-01 +// Generated from API version 2022-06-01 // - options - AssignmentsClientListOptions contains the optional parameters for the AssignmentsClient.NewListPager method. func (client *AssignmentsClient) NewListPager(options *AssignmentsClientListOptions) *runtime.Pager[AssignmentsClientListResponse] { return runtime.NewPager(runtime.PagingHandler[AssignmentsClientListResponse]{ @@ -423,7 +423,7 @@ func (client *AssignmentsClient) listCreateRequest(ctx context.Context, options if options != nil && options.Top != nil { reqQP.Set("$top", strconv.FormatInt(int64(*options.Top), 10)) } - reqQP.Set("api-version", "2021-06-01") + reqQP.Set("api-version", "2022-06-01") req.Raw().URL.RawQuery = reqQP.Encode() unencodedParams := []string{req.Raw().URL.RawQuery} if options != nil && options.Filter != nil { @@ -451,7 +451,7 @@ func (client *AssignmentsClient) listHandleResponse(resp *http.Response) (Assign // If $filter=policyDefinitionId eq '{value}' is provided, the returned list // includes all policy assignments of the policy definition whose id is {value} that apply to the management group. // -// Generated from API version 2021-06-01 +// Generated from API version 2022-06-01 // - managementGroupID - The ID of the management group. // - options - AssignmentsClientListForManagementGroupOptions contains the optional parameters for the AssignmentsClient.NewListForManagementGroupPager // method. @@ -498,7 +498,7 @@ func (client *AssignmentsClient) listForManagementGroupCreateRequest(ctx context if options != nil && options.Top != nil { reqQP.Set("$top", strconv.FormatInt(int64(*options.Top), 10)) } - reqQP.Set("api-version", "2021-06-01") + reqQP.Set("api-version", "2022-06-01") req.Raw().URL.RawQuery = reqQP.Encode() unencodedParams := []string{req.Raw().URL.RawQuery} if options != nil && options.Filter != nil { @@ -540,7 +540,7 @@ func (client *AssignmentsClient) listForManagementGroupHandleResponse(resp *http // format: ({resourceProviderNamespace} == ”, {parentResourcePath} == ”, // {resourceType} == 'Microsoft.Web/sites', {resourceName} == 'MyWebApp'). // -// Generated from API version 2021-06-01 +// Generated from API version 2022-06-01 // - resourceGroupName - The name of the resource group containing the resource. // - resourceProviderNamespace - The namespace of the resource provider. For example, the namespace of a virtual machine is // Microsoft.Compute (from Microsoft.Compute/virtualMachines) @@ -606,7 +606,7 @@ func (client *AssignmentsClient) listForResourceCreateRequest(ctx context.Contex if options != nil && options.Top != nil { reqQP.Set("$top", strconv.FormatInt(int64(*options.Top), 10)) } - reqQP.Set("api-version", "2021-06-01") + reqQP.Set("api-version", "2022-06-01") req.Raw().URL.RawQuery = reqQP.Encode() unencodedParams := []string{req.Raw().URL.RawQuery} if options != nil && options.Filter != nil { @@ -638,7 +638,7 @@ func (client *AssignmentsClient) listForResourceHandleResponse(resp *http.Respon // is provided, the returned list includes all policy assignments of the // policy definition whose id is {value} that apply to the resource group. // -// Generated from API version 2021-06-01 +// Generated from API version 2022-06-01 // - resourceGroupName - The name of the resource group that contains policy assignments. // - options - AssignmentsClientListForResourceGroupOptions contains the optional parameters for the AssignmentsClient.NewListForResourceGroupPager // method. @@ -689,7 +689,7 @@ func (client *AssignmentsClient) listForResourceGroupCreateRequest(ctx context.C if options != nil && options.Top != nil { reqQP.Set("$top", strconv.FormatInt(int64(*options.Top), 10)) } - reqQP.Set("api-version", "2021-06-01") + reqQP.Set("api-version", "2022-06-01") req.Raw().URL.RawQuery = reqQP.Encode() unencodedParams := []string{req.Raw().URL.RawQuery} if options != nil && options.Filter != nil { @@ -714,7 +714,7 @@ func (client *AssignmentsClient) listForResourceGroupHandleResponse(resp *http.R // group scope, that policy applies to all resources in the group. // If the operation fails it returns an *azcore.ResponseError type. // -// Generated from API version 2021-06-01 +// Generated from API version 2022-06-01 // - scope - The scope of the policy assignment. Valid scopes are: management group (format: '/providers/Microsoft.Management/managementGroups/{managementGroup}'), // subscription (format: // '/subscriptions/{subscriptionId}'), resource group (format: '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}', @@ -751,7 +751,7 @@ func (client *AssignmentsClient) updateCreateRequest(ctx context.Context, scope return nil, err } reqQP := req.Raw().URL.Query() - reqQP.Set("api-version", "2021-06-01") + reqQP.Set("api-version", "2022-06-01") req.Raw().URL.RawQuery = reqQP.Encode() req.Raw().Header["Accept"] = []string{"application/json"} return req, runtime.MarshalAsJSON(req, parameters) @@ -776,7 +776,7 @@ func (client *AssignmentsClient) updateHandleResponse(resp *http.Response) (Assi // '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}'. // If the operation fails it returns an *azcore.ResponseError type. // -// Generated from API version 2021-06-01 +// Generated from API version 2022-06-01 // - policyAssignmentID - The ID of the policy assignment to update. Use the format '{scope}/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}'. // - parameters - Parameters for policy assignment patch request. // - options - AssignmentsClientUpdateByIDOptions contains the optional parameters for the AssignmentsClient.UpdateByID method. @@ -804,7 +804,7 @@ func (client *AssignmentsClient) updateByIDCreateRequest(ctx context.Context, po return nil, err } reqQP := req.Raw().URL.Query() - reqQP.Set("api-version", "2021-06-01") + reqQP.Set("api-version", "2022-06-01") req.Raw().URL.RawQuery = reqQP.Encode() req.Raw().Header["Accept"] = []string{"application/json"} return req, runtime.MarshalAsJSON(req, parameters) diff --git a/sdk/resourcemanager/resources/armpolicy/assignments_client_example_test.go b/sdk/resourcemanager/resources/armpolicy/assignments_client_example_test.go deleted file mode 100644 index ab4475d173e9..000000000000 --- a/sdk/resourcemanager/resources/armpolicy/assignments_client_example_test.go +++ /dev/null @@ -1,1067 +0,0 @@ -//go:build go1.18 -// +build go1.18 - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See License.txt in the project root for license information. -// Code generated by Microsoft (R) AutoRest Code Generator. -// Changes may cause incorrect behavior and will be lost if the code is regenerated. -// DO NOT EDIT. - -package armpolicy_test - -import ( - "context" - "log" - - "github.com/Azure/azure-sdk-for-go/sdk/azcore/to" - "github.com/Azure/azure-sdk-for-go/sdk/azidentity" - "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armpolicy" -) - -// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/d55b8005f05b040b852c15e74a0f3e36494a15e1/specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/deletePolicyAssignment.json -func ExampleAssignmentsClient_Delete() { - cred, err := azidentity.NewDefaultAzureCredential(nil) - if err != nil { - log.Fatalf("failed to obtain a credential: %v", err) - } - ctx := context.Background() - clientFactory, err := armpolicy.NewClientFactory("", cred, nil) - if err != nil { - log.Fatalf("failed to create client: %v", err) - } - res, err := clientFactory.NewAssignmentsClient().Delete(ctx, "subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2", "EnforceNaming", nil) - if err != nil { - log.Fatalf("failed to finish the request: %v", err) - } - // You could use response here. We use blank identifier for just demo purposes. - _ = res - // If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes. - // res.Assignment = armpolicy.Assignment{ - // Name: to.Ptr("EnforceNaming"), - // Type: to.Ptr("Microsoft.Authorization/policyAssignments"), - // ID: to.Ptr("/subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2/providers/Microsoft.Authorization/policyAssignments/EnforceNaming"), - // Properties: &armpolicy.AssignmentProperties{ - // Description: to.Ptr("Force resource names to begin with given DeptA and end with -LC"), - // DisplayName: to.Ptr("Enforce resource naming rules"), - // Metadata: map[string]any{ - // "assignedBy": "Special Someone", - // }, - // NotScopes: []*string{ - // }, - // Parameters: map[string]*armpolicy.ParameterValuesValue{ - // "prefix": &armpolicy.ParameterValuesValue{ - // Value: "DeptA", - // }, - // "suffix": &armpolicy.ParameterValuesValue{ - // Value: "-LC", - // }, - // }, - // PolicyDefinitionID: to.Ptr("/subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2/providers/Microsoft.Authorization/policyDefinitions/ResourceNaming"), - // Scope: to.Ptr("/subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2"), - // }, - // } -} - -// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/d55b8005f05b040b852c15e74a0f3e36494a15e1/specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/createPolicyAssignment.json -func ExampleAssignmentsClient_Create_createOrUpdateAPolicyAssignment() { - cred, err := azidentity.NewDefaultAzureCredential(nil) - if err != nil { - log.Fatalf("failed to obtain a credential: %v", err) - } - ctx := context.Background() - clientFactory, err := armpolicy.NewClientFactory("", cred, nil) - if err != nil { - log.Fatalf("failed to create client: %v", err) - } - _, err = clientFactory.NewAssignmentsClient().Create(ctx, "subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2", "EnforceNaming", armpolicy.Assignment{ - Properties: &armpolicy.AssignmentProperties{ - Description: to.Ptr("Force resource names to begin with given DeptA and end with -LC"), - DisplayName: to.Ptr("Enforce resource naming rules"), - Metadata: map[string]any{ - "assignedBy": "Special Someone", - }, - NonComplianceMessages: []*armpolicy.NonComplianceMessage{ - { - Message: to.Ptr("Resource names must start with 'DeptA' and end with '-LC'."), - }}, - Parameters: map[string]*armpolicy.ParameterValuesValue{ - "prefix": { - Value: "DeptA", - }, - "suffix": { - Value: "-LC", - }, - }, - PolicyDefinitionID: to.Ptr("/subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2/providers/Microsoft.Authorization/policyDefinitions/ResourceNaming"), - }, - }, nil) - if err != nil { - log.Fatalf("failed to finish the request: %v", err) - } -} - -// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/d55b8005f05b040b852c15e74a0f3e36494a15e1/specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/createPolicyAssignmentWithIdentity.json -func ExampleAssignmentsClient_Create_createOrUpdateAPolicyAssignmentWithASystemAssignedIdentity() { - cred, err := azidentity.NewDefaultAzureCredential(nil) - if err != nil { - log.Fatalf("failed to obtain a credential: %v", err) - } - ctx := context.Background() - clientFactory, err := armpolicy.NewClientFactory("", cred, nil) - if err != nil { - log.Fatalf("failed to create client: %v", err) - } - _, err = clientFactory.NewAssignmentsClient().Create(ctx, "subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2", "EnforceNaming", armpolicy.Assignment{ - Identity: &armpolicy.Identity{ - Type: to.Ptr(armpolicy.ResourceIdentityTypeSystemAssigned), - }, - Location: to.Ptr("eastus"), - Properties: &armpolicy.AssignmentProperties{ - Description: to.Ptr("Force resource names to begin with given DeptA and end with -LC"), - DisplayName: to.Ptr("Enforce resource naming rules"), - EnforcementMode: to.Ptr(armpolicy.EnforcementModeDefault), - Metadata: map[string]any{ - "assignedBy": "Foo Bar", - }, - Parameters: map[string]*armpolicy.ParameterValuesValue{ - "prefix": { - Value: "DeptA", - }, - "suffix": { - Value: "-LC", - }, - }, - PolicyDefinitionID: to.Ptr("/subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2/providers/Microsoft.Authorization/policyDefinitions/ResourceNaming"), - }, - }, nil) - if err != nil { - log.Fatalf("failed to finish the request: %v", err) - } -} - -// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/d55b8005f05b040b852c15e74a0f3e36494a15e1/specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/createPolicyAssignmentWithUserAssignedIdentity.json -func ExampleAssignmentsClient_Create_createOrUpdateAPolicyAssignmentWithAUserAssignedIdentity() { - cred, err := azidentity.NewDefaultAzureCredential(nil) - if err != nil { - log.Fatalf("failed to obtain a credential: %v", err) - } - ctx := context.Background() - clientFactory, err := armpolicy.NewClientFactory("", cred, nil) - if err != nil { - log.Fatalf("failed to create client: %v", err) - } - _, err = clientFactory.NewAssignmentsClient().Create(ctx, "subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2", "EnforceNaming", armpolicy.Assignment{ - Identity: &armpolicy.Identity{ - Type: to.Ptr(armpolicy.ResourceIdentityTypeUserAssigned), - UserAssignedIdentities: map[string]*armpolicy.UserAssignedIdentitiesValue{ - "/subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2/resourceGroups/testResourceGroup/providers/Microsoft.ManagedIdentity/userAssignedIdentities/test-identity": {}, - }, - }, - Location: to.Ptr("eastus"), - Properties: &armpolicy.AssignmentProperties{ - Description: to.Ptr("Force resource names to begin with given DeptA and end with -LC"), - DisplayName: to.Ptr("Enforce resource naming rules"), - EnforcementMode: to.Ptr(armpolicy.EnforcementModeDefault), - Metadata: map[string]any{ - "assignedBy": "Foo Bar", - }, - Parameters: map[string]*armpolicy.ParameterValuesValue{ - "prefix": { - Value: "DeptA", - }, - "suffix": { - Value: "-LC", - }, - }, - PolicyDefinitionID: to.Ptr("/subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2/providers/Microsoft.Authorization/policyDefinitions/ResourceNaming"), - }, - }, nil) - if err != nil { - log.Fatalf("failed to finish the request: %v", err) - } -} - -// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/d55b8005f05b040b852c15e74a0f3e36494a15e1/specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/createPolicyAssignmentNonComplianceMessages.json -func ExampleAssignmentsClient_Create_createOrUpdateAPolicyAssignmentWithMultipleNonComplianceMessages() { - cred, err := azidentity.NewDefaultAzureCredential(nil) - if err != nil { - log.Fatalf("failed to obtain a credential: %v", err) - } - ctx := context.Background() - clientFactory, err := armpolicy.NewClientFactory("", cred, nil) - if err != nil { - log.Fatalf("failed to create client: %v", err) - } - _, err = clientFactory.NewAssignmentsClient().Create(ctx, "subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2", "securityInitAssignment", armpolicy.Assignment{ - Properties: &armpolicy.AssignmentProperties{ - DisplayName: to.Ptr("Enforce security policies"), - NonComplianceMessages: []*armpolicy.NonComplianceMessage{ - { - Message: to.Ptr("Resources must comply with all internal security policies. See for more info."), - }, - { - Message: to.Ptr("Resource names must start with 'DeptA' and end with '-LC'."), - PolicyDefinitionReferenceID: to.Ptr("10420126870854049575"), - }, - { - Message: to.Ptr("Storage accounts must have firewall rules configured."), - PolicyDefinitionReferenceID: to.Ptr("8572513655450389710"), - }}, - PolicyDefinitionID: to.Ptr("/subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2/providers/Microsoft.Authorization/policySetDefinitions/securityInitiative"), - }, - }, nil) - if err != nil { - log.Fatalf("failed to finish the request: %v", err) - } -} - -// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/d55b8005f05b040b852c15e74a0f3e36494a15e1/specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/createPolicyAssignmentWithoutEnforcement.json -func ExampleAssignmentsClient_Create_createOrUpdateAPolicyAssignmentWithoutEnforcingPolicyEffectDuringResourceCreationOrUpdate() { - cred, err := azidentity.NewDefaultAzureCredential(nil) - if err != nil { - log.Fatalf("failed to obtain a credential: %v", err) - } - ctx := context.Background() - clientFactory, err := armpolicy.NewClientFactory("", cred, nil) - if err != nil { - log.Fatalf("failed to create client: %v", err) - } - _, err = clientFactory.NewAssignmentsClient().Create(ctx, "subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2", "EnforceNaming", armpolicy.Assignment{ - Properties: &armpolicy.AssignmentProperties{ - Description: to.Ptr("Force resource names to begin with given DeptA and end with -LC"), - DisplayName: to.Ptr("Enforce resource naming rules"), - EnforcementMode: to.Ptr(armpolicy.EnforcementModeDoNotEnforce), - Metadata: map[string]any{ - "assignedBy": "Special Someone", - }, - Parameters: map[string]*armpolicy.ParameterValuesValue{ - "prefix": { - Value: "DeptA", - }, - "suffix": { - Value: "-LC", - }, - }, - PolicyDefinitionID: to.Ptr("/subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2/providers/Microsoft.Authorization/policyDefinitions/ResourceNaming"), - }, - }, nil) - if err != nil { - log.Fatalf("failed to finish the request: %v", err) - } -} - -// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/d55b8005f05b040b852c15e74a0f3e36494a15e1/specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/getPolicyAssignment.json -func ExampleAssignmentsClient_Get_retrieveAPolicyAssignment() { - cred, err := azidentity.NewDefaultAzureCredential(nil) - if err != nil { - log.Fatalf("failed to obtain a credential: %v", err) - } - ctx := context.Background() - clientFactory, err := armpolicy.NewClientFactory("", cred, nil) - if err != nil { - log.Fatalf("failed to create client: %v", err) - } - res, err := clientFactory.NewAssignmentsClient().Get(ctx, "subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2", "EnforceNaming", nil) - if err != nil { - log.Fatalf("failed to finish the request: %v", err) - } - // You could use response here. We use blank identifier for just demo purposes. - _ = res - // If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes. - // res.Assignment = armpolicy.Assignment{ - // Name: to.Ptr("EnforceNaming"), - // Type: to.Ptr("Microsoft.Authorization/policyAssignments"), - // ID: to.Ptr("/subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2/providers/Microsoft.Authorization/policyAssignments/EnforceNaming"), - // Properties: &armpolicy.AssignmentProperties{ - // Description: to.Ptr("Force resource names to begin with given DeptA and end with -LC"), - // DisplayName: to.Ptr("Enforce resource naming rules"), - // EnforcementMode: to.Ptr(armpolicy.EnforcementModeDefault), - // Metadata: map[string]any{ - // "assignedBy": "Special Someone", - // }, - // NotScopes: []*string{ - // }, - // Parameters: map[string]*armpolicy.ParameterValuesValue{ - // "prefix": &armpolicy.ParameterValuesValue{ - // Value: "DeptA", - // }, - // "suffix": &armpolicy.ParameterValuesValue{ - // Value: "-LC", - // }, - // }, - // PolicyDefinitionID: to.Ptr("/subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2/providers/Microsoft.Authorization/policyDefinitions/ResourceNaming"), - // Scope: to.Ptr("/subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2"), - // }, - // } -} - -// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/d55b8005f05b040b852c15e74a0f3e36494a15e1/specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/getPolicyAssignmentWithIdentity.json -func ExampleAssignmentsClient_Get_retrieveAPolicyAssignmentWithASystemAssignedIdentity() { - cred, err := azidentity.NewDefaultAzureCredential(nil) - if err != nil { - log.Fatalf("failed to obtain a credential: %v", err) - } - ctx := context.Background() - clientFactory, err := armpolicy.NewClientFactory("", cred, nil) - if err != nil { - log.Fatalf("failed to create client: %v", err) - } - res, err := clientFactory.NewAssignmentsClient().Get(ctx, "subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2", "EnforceNaming", nil) - if err != nil { - log.Fatalf("failed to finish the request: %v", err) - } - // You could use response here. We use blank identifier for just demo purposes. - _ = res - // If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes. - // res.Assignment = armpolicy.Assignment{ - // Name: to.Ptr("EnforceNaming"), - // Type: to.Ptr("Microsoft.Authorization/policyAssignments"), - // ID: to.Ptr("/subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2/providers/Microsoft.Authorization/policyAssignments/EnforceNaming"), - // Identity: &armpolicy.Identity{ - // Type: to.Ptr(armpolicy.ResourceIdentityTypeSystemAssigned), - // PrincipalID: to.Ptr("e6d23f8d-af97-4fbc-bda6-00604e4e3d0a"), - // TenantID: to.Ptr("4bee2b8a-1bee-47c2-90e9-404241551135"), - // }, - // Location: to.Ptr("westus"), - // Properties: &armpolicy.AssignmentProperties{ - // Description: to.Ptr("Force resource names to begin with given DeptA and end with -LC"), - // DisplayName: to.Ptr("Enforce resource naming rules"), - // EnforcementMode: to.Ptr(armpolicy.EnforcementModeDefault), - // Metadata: map[string]any{ - // "assignedBy": "Special Someone", - // }, - // NotScopes: []*string{ - // }, - // Parameters: map[string]*armpolicy.ParameterValuesValue{ - // "prefix": &armpolicy.ParameterValuesValue{ - // Value: "DeptA", - // }, - // "suffix": &armpolicy.ParameterValuesValue{ - // Value: "-LC", - // }, - // }, - // PolicyDefinitionID: to.Ptr("/subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2/providers/Microsoft.Authorization/policyDefinitions/ResourceNaming"), - // Scope: to.Ptr("/subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2"), - // }, - // } -} - -// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/d55b8005f05b040b852c15e74a0f3e36494a15e1/specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/getPolicyAssignmentWithUserAssignedIdentity.json -func ExampleAssignmentsClient_Get_retrieveAPolicyAssignmentWithAUserAssignedIdentity() { - cred, err := azidentity.NewDefaultAzureCredential(nil) - if err != nil { - log.Fatalf("failed to obtain a credential: %v", err) - } - ctx := context.Background() - clientFactory, err := armpolicy.NewClientFactory("", cred, nil) - if err != nil { - log.Fatalf("failed to create client: %v", err) - } - res, err := clientFactory.NewAssignmentsClient().Get(ctx, "subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2", "EnforceNaming", nil) - if err != nil { - log.Fatalf("failed to finish the request: %v", err) - } - // You could use response here. We use blank identifier for just demo purposes. - _ = res - // If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes. - // res.Assignment = armpolicy.Assignment{ - // Name: to.Ptr("EnforceNaming"), - // Type: to.Ptr("Microsoft.Authorization/policyAssignments"), - // ID: to.Ptr("/subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2/providers/Microsoft.Authorization/policyAssignments/EnforceNaming"), - // Identity: &armpolicy.Identity{ - // Type: to.Ptr(armpolicy.ResourceIdentityTypeUserAssigned), - // UserAssignedIdentities: map[string]*armpolicy.UserAssignedIdentitiesValue{ - // "/subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2/resourceGroups/testResourceGroup/providers/Microsoft.ManagedIdentity/userAssignedIdentities/test-identity": &armpolicy.UserAssignedIdentitiesValue{ - // ClientID: to.Ptr("4bee2b8a-1bee-47c2-90e9-404241551135"), - // PrincipalID: to.Ptr("e6d23f8d-af97-4fbc-bda6-00604e4e3d0a"), - // }, - // }, - // }, - // Location: to.Ptr("westus"), - // Properties: &armpolicy.AssignmentProperties{ - // Description: to.Ptr("Force resource names to begin with given DeptA and end with -LC"), - // DisplayName: to.Ptr("Enforce resource naming rules"), - // EnforcementMode: to.Ptr(armpolicy.EnforcementModeDefault), - // Metadata: map[string]any{ - // "assignedBy": "Special Someone", - // }, - // NotScopes: []*string{ - // }, - // Parameters: map[string]*armpolicy.ParameterValuesValue{ - // "prefix": &armpolicy.ParameterValuesValue{ - // Value: "DeptA", - // }, - // "suffix": &armpolicy.ParameterValuesValue{ - // Value: "-LC", - // }, - // }, - // PolicyDefinitionID: to.Ptr("/subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2/providers/Microsoft.Authorization/policyDefinitions/ResourceNaming"), - // Scope: to.Ptr("/subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2"), - // }, - // } -} - -// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/d55b8005f05b040b852c15e74a0f3e36494a15e1/specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/updatePolicyAssignmentWithIdentity.json -func ExampleAssignmentsClient_Update_updateAPolicyAssignmentWithASystemAssignedIdentity() { - cred, err := azidentity.NewDefaultAzureCredential(nil) - if err != nil { - log.Fatalf("failed to obtain a credential: %v", err) - } - ctx := context.Background() - clientFactory, err := armpolicy.NewClientFactory("", cred, nil) - if err != nil { - log.Fatalf("failed to create client: %v", err) - } - res, err := clientFactory.NewAssignmentsClient().Update(ctx, "subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2", "EnforceNaming", armpolicy.AssignmentUpdate{ - Identity: &armpolicy.Identity{ - Type: to.Ptr(armpolicy.ResourceIdentityTypeSystemAssigned), - }, - Location: to.Ptr("eastus"), - }, nil) - if err != nil { - log.Fatalf("failed to finish the request: %v", err) - } - // You could use response here. We use blank identifier for just demo purposes. - _ = res - // If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes. - // res.Assignment = armpolicy.Assignment{ - // Name: to.Ptr("EnforceNaming"), - // Type: to.Ptr("Microsoft.Authorization/policyAssignments"), - // ID: to.Ptr("/subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2/providers/Microsoft.Authorization/policyAssignments/EnforceNaming"), - // Identity: &armpolicy.Identity{ - // Type: to.Ptr(armpolicy.ResourceIdentityTypeSystemAssigned), - // PrincipalID: to.Ptr("e6d23f8d-af97-4fbc-bda6-00604e4e3d0a"), - // TenantID: to.Ptr("4bee2b8a-1bee-47c2-90e9-404241551135"), - // }, - // Location: to.Ptr("eastus"), - // Properties: &armpolicy.AssignmentProperties{ - // Description: to.Ptr("Force resource names to begin with given DeptA and end with -LC"), - // DisplayName: to.Ptr("Enforce resource naming rules"), - // EnforcementMode: to.Ptr(armpolicy.EnforcementModeDefault), - // Metadata: map[string]any{ - // "assignedBy": "Special Someone", - // }, - // NotScopes: []*string{ - // }, - // Parameters: map[string]*armpolicy.ParameterValuesValue{ - // "prefix": &armpolicy.ParameterValuesValue{ - // Value: "DeptA", - // }, - // "suffix": &armpolicy.ParameterValuesValue{ - // Value: "-LC", - // }, - // }, - // PolicyDefinitionID: to.Ptr("/subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2/providers/Microsoft.Authorization/policyDefinitions/ResourceNaming"), - // Scope: to.Ptr("/subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2"), - // }, - // } -} - -// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/d55b8005f05b040b852c15e74a0f3e36494a15e1/specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/updatePolicyAssignmentWithUserAssignedIdentity.json -func ExampleAssignmentsClient_Update_updateAPolicyAssignmentWithAUserAssignedIdentity() { - cred, err := azidentity.NewDefaultAzureCredential(nil) - if err != nil { - log.Fatalf("failed to obtain a credential: %v", err) - } - ctx := context.Background() - clientFactory, err := armpolicy.NewClientFactory("", cred, nil) - if err != nil { - log.Fatalf("failed to create client: %v", err) - } - res, err := clientFactory.NewAssignmentsClient().Update(ctx, "subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2", "EnforceNaming", armpolicy.AssignmentUpdate{ - Identity: &armpolicy.Identity{ - Type: to.Ptr(armpolicy.ResourceIdentityTypeUserAssigned), - UserAssignedIdentities: map[string]*armpolicy.UserAssignedIdentitiesValue{ - "/subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2/resourceGroups/testResourceGroup/providers/Microsoft.ManagedIdentity/userAssignedIdentities/test-identity": {}, - }, - }, - Location: to.Ptr("eastus"), - }, nil) - if err != nil { - log.Fatalf("failed to finish the request: %v", err) - } - // You could use response here. We use blank identifier for just demo purposes. - _ = res - // If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes. - // res.Assignment = armpolicy.Assignment{ - // Name: to.Ptr("EnforceNaming"), - // Type: to.Ptr("Microsoft.Authorization/policyAssignments"), - // ID: to.Ptr("/subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2/providers/Microsoft.Authorization/policyAssignments/EnforceNaming"), - // Identity: &armpolicy.Identity{ - // Type: to.Ptr(armpolicy.ResourceIdentityTypeUserAssigned), - // UserAssignedIdentities: map[string]*armpolicy.UserAssignedIdentitiesValue{ - // "/subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2/resourceGroups/testResourceGroup/providers/Microsoft.ManagedIdentity/userAssignedIdentities/test-identity": &armpolicy.UserAssignedIdentitiesValue{ - // ClientID: to.Ptr("4bee2b8a-1bee-47c2-90e9-404241551135"), - // PrincipalID: to.Ptr("e6d23f8d-af97-4fbc-bda6-00604e4e3d0a"), - // }, - // }, - // }, - // Location: to.Ptr("eastus"), - // Properties: &armpolicy.AssignmentProperties{ - // Description: to.Ptr("Force resource names to begin with given DeptA and end with -LC"), - // DisplayName: to.Ptr("Enforce resource naming rules"), - // EnforcementMode: to.Ptr(armpolicy.EnforcementModeDefault), - // Metadata: map[string]any{ - // "assignedBy": "Special Someone", - // }, - // NotScopes: []*string{ - // }, - // Parameters: map[string]*armpolicy.ParameterValuesValue{ - // "prefix": &armpolicy.ParameterValuesValue{ - // Value: "DeptA", - // }, - // "suffix": &armpolicy.ParameterValuesValue{ - // Value: "-LC", - // }, - // }, - // PolicyDefinitionID: to.Ptr("/subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2/providers/Microsoft.Authorization/policyDefinitions/ResourceNaming"), - // Scope: to.Ptr("/subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2"), - // }, - // } -} - -// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/d55b8005f05b040b852c15e74a0f3e36494a15e1/specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/listPolicyAssignmentsForResourceGroup.json -func ExampleAssignmentsClient_NewListForResourceGroupPager() { - cred, err := azidentity.NewDefaultAzureCredential(nil) - if err != nil { - log.Fatalf("failed to obtain a credential: %v", err) - } - ctx := context.Background() - clientFactory, err := armpolicy.NewClientFactory("", cred, nil) - if err != nil { - log.Fatalf("failed to create client: %v", err) - } - pager := clientFactory.NewAssignmentsClient().NewListForResourceGroupPager("TestResourceGroup", &armpolicy.AssignmentsClientListForResourceGroupOptions{Filter: to.Ptr("atScope()"), - Top: nil, - }) - for pager.More() { - page, err := pager.NextPage(ctx) - if err != nil { - log.Fatalf("failed to advance page: %v", err) - } - for _, v := range page.Value { - // You could use page here. We use blank identifier for just demo purposes. - _ = v - } - // If the HTTP response code is 200 as defined in example definition, your page structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes. - // page.AssignmentListResult = armpolicy.AssignmentListResult{ - // Value: []*armpolicy.Assignment{ - // { - // Name: to.Ptr("TestCostManagement"), - // Type: to.Ptr("Microsoft.Authorization/policyAssignments"), - // ID: to.Ptr("/subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2/resourceGroups/TestResourceGroup/providers/Microsoft.Authorization/policyAssignments/TestCostManagement"), - // Identity: &armpolicy.Identity{ - // Type: to.Ptr(armpolicy.ResourceIdentityTypeSystemAssigned), - // PrincipalID: to.Ptr("e6d23f8d-af97-4fbc-bda6-00604e4e3d0a"), - // TenantID: to.Ptr("4bee2b8a-1bee-47c2-90e9-404241551135"), - // }, - // Location: to.Ptr("eastus"), - // Properties: &armpolicy.AssignmentProperties{ - // Description: to.Ptr("Minimize the risk of accidental cost overruns"), - // DisplayName: to.Ptr("Storage Cost Management"), - // Metadata: map[string]any{ - // "category": "Cost Management", - // }, - // NotScopes: []*string{ - // }, - // Parameters: map[string]*armpolicy.ParameterValuesValue{ - // "allowedSkus": &armpolicy.ParameterValuesValue{ - // Value: "Standard_A1", - // }, - // }, - // PolicyDefinitionID: to.Ptr("/subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2/providers/Microsoft.Authorization/policyDefinitions/storageSkus"), - // Scope: to.Ptr("/subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2/resourceGroups/TestResourceGroup"), - // }, - // }, - // { - // Name: to.Ptr("TestTagEnforcement"), - // Type: to.Ptr("Microsoft.Authorization/policyAssignments"), - // ID: to.Ptr("/subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2/resourceGroups/TestResourceGroup/providers/Microsoft.Authorization/policyAssignments/TestTagEnforcement"), - // Properties: &armpolicy.AssignmentProperties{ - // Description: to.Ptr("Ensure a given tag key and value are present on all resources"), - // DisplayName: to.Ptr("Enforces a tag key and value"), - // NotScopes: []*string{ - // }, - // PolicyDefinitionID: to.Ptr("/subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2/providers/Microsoft.Authorization/policyDefinitions/TagKeyValue"), - // Scope: to.Ptr("/subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2/resourceGroups/TestResourceGroup"), - // }, - // }}, - // } - } -} - -// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/d55b8005f05b040b852c15e74a0f3e36494a15e1/specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/listPolicyAssignmentsForResource.json -func ExampleAssignmentsClient_NewListForResourcePager() { - cred, err := azidentity.NewDefaultAzureCredential(nil) - if err != nil { - log.Fatalf("failed to obtain a credential: %v", err) - } - ctx := context.Background() - clientFactory, err := armpolicy.NewClientFactory("", cred, nil) - if err != nil { - log.Fatalf("failed to create client: %v", err) - } - pager := clientFactory.NewAssignmentsClient().NewListForResourcePager("TestResourceGroup", "Microsoft.Compute", "virtualMachines/MyTestVm", "domainNames", "MyTestComputer.cloudapp.net", &armpolicy.AssignmentsClientListForResourceOptions{Filter: nil, - Top: nil, - }) - for pager.More() { - page, err := pager.NextPage(ctx) - if err != nil { - log.Fatalf("failed to advance page: %v", err) - } - for _, v := range page.Value { - // You could use page here. We use blank identifier for just demo purposes. - _ = v - } - // If the HTTP response code is 200 as defined in example definition, your page structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes. - // page.AssignmentListResult = armpolicy.AssignmentListResult{ - // Value: []*armpolicy.Assignment{ - // { - // Name: to.Ptr("TestCostManagement"), - // Type: to.Ptr("Microsoft.Authorization/policyAssignments"), - // ID: to.Ptr("/subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2/resourceGroups/TestResourceGroup/providers/Microsoft.Authorization/policyAssignments/TestCostManagement"), - // Identity: &armpolicy.Identity{ - // Type: to.Ptr(armpolicy.ResourceIdentityTypeSystemAssigned), - // PrincipalID: to.Ptr("e6d23f8d-af97-4fbc-bda6-00604e4e3d0a"), - // TenantID: to.Ptr("4bee2b8a-1bee-47c2-90e9-404241551135"), - // }, - // Location: to.Ptr("eastus"), - // Properties: &armpolicy.AssignmentProperties{ - // Description: to.Ptr("Minimize the risk of accidental cost overruns"), - // DisplayName: to.Ptr("VM Cost Management"), - // Metadata: map[string]any{ - // "category": "Cost Management", - // }, - // NotScopes: []*string{ - // }, - // Parameters: map[string]*armpolicy.ParameterValuesValue{ - // "allowedSkus": &armpolicy.ParameterValuesValue{ - // Value: "Standard_A1", - // }, - // }, - // PolicyDefinitionID: to.Ptr("/subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2/providers/Microsoft.Authorization/policyDefinitions/vmSkus"), - // Scope: to.Ptr("/subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2/resourceGroups/TestResourceGroup"), - // }, - // }, - // { - // Name: to.Ptr("TestTagEnforcement"), - // Type: to.Ptr("Microsoft.Authorization/policyAssignments"), - // ID: to.Ptr("/subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2/resourceGroups/TestResourceGroup/providers/Microsoft.Authorization/policyAssignments/TestTagEnforcement"), - // Properties: &armpolicy.AssignmentProperties{ - // Description: to.Ptr("Ensure a given tag key and value are present on all resources"), - // DisplayName: to.Ptr("Enforces a tag key and value"), - // NotScopes: []*string{ - // }, - // PolicyDefinitionID: to.Ptr("/subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2/providers/Microsoft.Authorization/policyDefinitions/TagKeyValue"), - // Scope: to.Ptr("/subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2/resourceGroups/TestResourceGroup"), - // }, - // }}, - // } - } -} - -// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/d55b8005f05b040b852c15e74a0f3e36494a15e1/specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/listPolicyAssignmentsForManagementGroup.json -func ExampleAssignmentsClient_NewListForManagementGroupPager() { - cred, err := azidentity.NewDefaultAzureCredential(nil) - if err != nil { - log.Fatalf("failed to obtain a credential: %v", err) - } - ctx := context.Background() - clientFactory, err := armpolicy.NewClientFactory("", cred, nil) - if err != nil { - log.Fatalf("failed to create client: %v", err) - } - pager := clientFactory.NewAssignmentsClient().NewListForManagementGroupPager("TestManagementGroup", &armpolicy.AssignmentsClientListForManagementGroupOptions{Filter: to.Ptr("atScope()"), - Top: nil, - }) - for pager.More() { - page, err := pager.NextPage(ctx) - if err != nil { - log.Fatalf("failed to advance page: %v", err) - } - for _, v := range page.Value { - // You could use page here. We use blank identifier for just demo purposes. - _ = v - } - // If the HTTP response code is 200 as defined in example definition, your page structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes. - // page.AssignmentListResult = armpolicy.AssignmentListResult{ - // Value: []*armpolicy.Assignment{ - // { - // Name: to.Ptr("TestCostManagement"), - // Type: to.Ptr("Microsoft.Authorization/policyAssignments"), - // ID: to.Ptr("/providers/Microsoft.Management/managementGroups/TestManagementGroup/providers/Microsoft.Authorization/policyAssignments/TestCostManagement"), - // Identity: &armpolicy.Identity{ - // Type: to.Ptr(armpolicy.ResourceIdentityTypeSystemAssigned), - // PrincipalID: to.Ptr("e6d23f8d-af97-4fbc-bda6-00604e4e3d0a"), - // TenantID: to.Ptr("4bee2b8a-1bee-47c2-90e9-404241551135"), - // }, - // Location: to.Ptr("eastus"), - // Properties: &armpolicy.AssignmentProperties{ - // Description: to.Ptr("Minimize the risk of accidental cost overruns"), - // DisplayName: to.Ptr("Storage Cost Management"), - // Metadata: map[string]any{ - // "category": "Cost Management", - // }, - // NotScopes: []*string{ - // }, - // Parameters: map[string]*armpolicy.ParameterValuesValue{ - // "allowedSkus": &armpolicy.ParameterValuesValue{ - // Value: "Standard_A1", - // }, - // }, - // PolicyDefinitionID: to.Ptr("/providers/Microsoft.Management/managementGroups/TestManagementGroup/providers/Microsoft.Authorization/policyDefinitions/storageSkus"), - // Scope: to.Ptr("/providers/Microsoft.Management/managementGroups/TestManagementGroup"), - // }, - // }, - // { - // Name: to.Ptr("TestTagEnforcement"), - // Type: to.Ptr("Microsoft.Authorization/policyAssignments"), - // ID: to.Ptr("/providers/Microsoft.Management/managementGroups/TestManagementGroup/providers/Microsoft.Authorization/policyAssignments/TestTagEnforcement"), - // Properties: &armpolicy.AssignmentProperties{ - // Description: to.Ptr("Ensure a given tag key and value are present on all resources"), - // DisplayName: to.Ptr("Enforces a tag key and value"), - // NotScopes: []*string{ - // }, - // PolicyDefinitionID: to.Ptr("/providers/Microsoft.Management/managementGroups/TestManagementGroup/providers/Microsoft.Authorization/policyDefinitions/TagKeyValue"), - // Scope: to.Ptr("/providers/Microsoft.Management/managementGroups/TestManagementGroup"), - // }, - // }}, - // } - } -} - -// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/d55b8005f05b040b852c15e74a0f3e36494a15e1/specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/listPolicyAssignments.json -func ExampleAssignmentsClient_NewListPager() { - cred, err := azidentity.NewDefaultAzureCredential(nil) - if err != nil { - log.Fatalf("failed to obtain a credential: %v", err) - } - ctx := context.Background() - clientFactory, err := armpolicy.NewClientFactory("", cred, nil) - if err != nil { - log.Fatalf("failed to create client: %v", err) - } - pager := clientFactory.NewAssignmentsClient().NewListPager(&armpolicy.AssignmentsClientListOptions{Filter: to.Ptr("atScope()"), - Top: nil, - }) - for pager.More() { - page, err := pager.NextPage(ctx) - if err != nil { - log.Fatalf("failed to advance page: %v", err) - } - for _, v := range page.Value { - // You could use page here. We use blank identifier for just demo purposes. - _ = v - } - // If the HTTP response code is 200 as defined in example definition, your page structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes. - // page.AssignmentListResult = armpolicy.AssignmentListResult{ - // Value: []*armpolicy.Assignment{ - // { - // Name: to.Ptr("CostManagement"), - // Type: to.Ptr("Microsoft.Authorization/policyAssignments"), - // ID: to.Ptr("/subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2/providers/Microsoft.Authorization/policyAssignments/CostManagement"), - // Identity: &armpolicy.Identity{ - // Type: to.Ptr(armpolicy.ResourceIdentityTypeSystemAssigned), - // PrincipalID: to.Ptr("e6d23f8d-af97-4fbc-bda6-00604e4e3d0a"), - // TenantID: to.Ptr("4bee2b8a-1bee-47c2-90e9-404241551135"), - // }, - // Location: to.Ptr("eastus"), - // Properties: &armpolicy.AssignmentProperties{ - // Description: to.Ptr("Minimize the risk of accidental cost overruns"), - // DisplayName: to.Ptr("Storage Cost Management"), - // Metadata: map[string]any{ - // "category": "Cost Management", - // }, - // NotScopes: []*string{ - // }, - // Parameters: map[string]*armpolicy.ParameterValuesValue{ - // "allowedSkus": &armpolicy.ParameterValuesValue{ - // Value: "Standard_A1", - // }, - // }, - // PolicyDefinitionID: to.Ptr("/subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2/providers/Microsoft.Authorization/policyDefinitions/storageSkus"), - // Scope: to.Ptr("/subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2"), - // }, - // }, - // { - // Name: to.Ptr("TagEnforcement"), - // Type: to.Ptr("Microsoft.Authorization/policyAssignments"), - // ID: to.Ptr("/subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2/providers/Microsoft.Authorization/policyAssignments/TagEnforcement"), - // Properties: &armpolicy.AssignmentProperties{ - // Description: to.Ptr("Ensure a given tag key and value are present on all resources"), - // DisplayName: to.Ptr("Enforces a tag key and value"), - // NotScopes: []*string{ - // }, - // PolicyDefinitionID: to.Ptr("/subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2/providers/Microsoft.Authorization/policyDefinitions/TagKeyValue"), - // Scope: to.Ptr("/subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2"), - // }, - // }}, - // } - } -} - -// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/d55b8005f05b040b852c15e74a0f3e36494a15e1/specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/deletePolicyAssignmentById.json -func ExampleAssignmentsClient_DeleteByID() { - cred, err := azidentity.NewDefaultAzureCredential(nil) - if err != nil { - log.Fatalf("failed to obtain a credential: %v", err) - } - ctx := context.Background() - clientFactory, err := armpolicy.NewClientFactory("", cred, nil) - if err != nil { - log.Fatalf("failed to create client: %v", err) - } - res, err := clientFactory.NewAssignmentsClient().DeleteByID(ctx, "providers/Microsoft.Management/managementGroups/MyManagementGroup/providers/Microsoft.Authorization/policyAssignments/LowCostStorage", nil) - if err != nil { - log.Fatalf("failed to finish the request: %v", err) - } - // You could use response here. We use blank identifier for just demo purposes. - _ = res - // If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes. - // res.Assignment = armpolicy.Assignment{ - // Name: to.Ptr("LowCostStorage"), - // Type: to.Ptr("Microsoft.Authorization/policyAssignments"), - // ID: to.Ptr("/providers/Microsoft.Management/managementGroups/MyManagementGroup/providers/Microsoft.Authorization/policyAssignments/LowCostStorage"), - // Properties: &armpolicy.AssignmentProperties{ - // Description: to.Ptr("Allow only storage accounts of SKU Standard_GRS or Standard_LRS to be created"), - // DisplayName: to.Ptr("Enforce storage account SKU"), - // Metadata: map[string]any{ - // "assignedBy": "Cheapskate Boss", - // }, - // NotScopes: []*string{ - // }, - // Parameters: map[string]*armpolicy.ParameterValuesValue{ - // "listOfAllowedSKUs": &armpolicy.ParameterValuesValue{ - // Value: []any{ - // "Standard_GRS", - // "Standard_LRS", - // }, - // }, - // }, - // PolicyDefinitionID: to.Ptr("/providers/Microsoft.Authorization/policyDefinitions/7433c107-6db4-4ad1-b57a-a76dce0154a1"), - // }, - // } -} - -// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/d55b8005f05b040b852c15e74a0f3e36494a15e1/specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/createPolicyAssignmentById.json -func ExampleAssignmentsClient_CreateByID_createOrUpdatePolicyAssignmentById() { - cred, err := azidentity.NewDefaultAzureCredential(nil) - if err != nil { - log.Fatalf("failed to obtain a credential: %v", err) - } - ctx := context.Background() - clientFactory, err := armpolicy.NewClientFactory("", cred, nil) - if err != nil { - log.Fatalf("failed to create client: %v", err) - } - _, err = clientFactory.NewAssignmentsClient().CreateByID(ctx, "providers/Microsoft.Management/managementGroups/MyManagementGroup/providers/Microsoft.Authorization/policyAssignments/LowCostStorage", armpolicy.Assignment{ - Properties: &armpolicy.AssignmentProperties{ - Description: to.Ptr("Allow only storage accounts of SKU Standard_GRS or Standard_LRS to be created"), - DisplayName: to.Ptr("Enforce storage account SKU"), - EnforcementMode: to.Ptr(armpolicy.EnforcementModeDefault), - Metadata: map[string]any{ - "assignedBy": "Cheapskate Boss", - }, - Parameters: map[string]*armpolicy.ParameterValuesValue{ - "listOfAllowedSKUs": { - Value: []any{ - "Standard_GRS", - "Standard_LRS", - }, - }, - }, - PolicyDefinitionID: to.Ptr("/providers/Microsoft.Authorization/policyDefinitions/7433c107-6db4-4ad1-b57a-a76dce0154a1"), - }, - }, nil) - if err != nil { - log.Fatalf("failed to finish the request: %v", err) - } -} - -// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/d55b8005f05b040b852c15e74a0f3e36494a15e1/specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/createPolicyAssignmentWithIdentityById.json -func ExampleAssignmentsClient_CreateByID_createOrUpdatePolicyAssignmentWithAManagedIdentityById() { - cred, err := azidentity.NewDefaultAzureCredential(nil) - if err != nil { - log.Fatalf("failed to obtain a credential: %v", err) - } - ctx := context.Background() - clientFactory, err := armpolicy.NewClientFactory("", cred, nil) - if err != nil { - log.Fatalf("failed to create client: %v", err) - } - _, err = clientFactory.NewAssignmentsClient().CreateByID(ctx, "providers/Microsoft.Management/managementGroups/MyManagementGroup/providers/Microsoft.Authorization/policyAssignments/LowCostStorage", armpolicy.Assignment{ - Identity: &armpolicy.Identity{ - Type: to.Ptr(armpolicy.ResourceIdentityTypeSystemAssigned), - }, - Location: to.Ptr("eastus"), - Properties: &armpolicy.AssignmentProperties{ - Description: to.Ptr("Allow only storage accounts of SKU Standard_GRS or Standard_LRS to be created"), - DisplayName: to.Ptr("Enforce storage account SKU"), - EnforcementMode: to.Ptr(armpolicy.EnforcementModeDefault), - Metadata: map[string]any{ - "assignedBy": "Cheapskate Boss", - }, - Parameters: map[string]*armpolicy.ParameterValuesValue{ - "listOfAllowedSKUs": { - Value: []any{ - "Standard_GRS", - "Standard_LRS", - }, - }, - }, - PolicyDefinitionID: to.Ptr("/providers/Microsoft.Authorization/policyDefinitions/7433c107-6db4-4ad1-b57a-a76dce0154a1"), - }, - }, nil) - if err != nil { - log.Fatalf("failed to finish the request: %v", err) - } -} - -// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/d55b8005f05b040b852c15e74a0f3e36494a15e1/specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/getPolicyAssignmentById.json -func ExampleAssignmentsClient_GetByID_retrieveAPolicyAssignmentById() { - cred, err := azidentity.NewDefaultAzureCredential(nil) - if err != nil { - log.Fatalf("failed to obtain a credential: %v", err) - } - ctx := context.Background() - clientFactory, err := armpolicy.NewClientFactory("", cred, nil) - if err != nil { - log.Fatalf("failed to create client: %v", err) - } - res, err := clientFactory.NewAssignmentsClient().GetByID(ctx, "providers/Microsoft.Management/managementGroups/MyManagementGroup/providers/Microsoft.Authorization/policyAssignments/LowCostStorage", nil) - if err != nil { - log.Fatalf("failed to finish the request: %v", err) - } - // You could use response here. We use blank identifier for just demo purposes. - _ = res - // If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes. - // res.Assignment = armpolicy.Assignment{ - // Name: to.Ptr("LowCostStorage"), - // Type: to.Ptr("Microsoft.Authorization/policyAssignments"), - // ID: to.Ptr("/providers/Microsoft.Management/managementGroups/MyManagementGroup/providers/Microsoft.Authorization/policyAssignments/LowCostStorage"), - // Properties: &armpolicy.AssignmentProperties{ - // Description: to.Ptr("Allow only storage accounts of SKU Standard_GRS or Standard_LRS to be created"), - // DisplayName: to.Ptr("Enforce storage account SKU"), - // EnforcementMode: to.Ptr(armpolicy.EnforcementModeDefault), - // Metadata: map[string]any{ - // "assignedBy": "Cheapskate Boss", - // }, - // NotScopes: []*string{ - // }, - // Parameters: map[string]*armpolicy.ParameterValuesValue{ - // "listOfAllowedSKUs": &armpolicy.ParameterValuesValue{ - // Value: []any{ - // "Standard_GRS", - // "Standard_LRS", - // }, - // }, - // }, - // PolicyDefinitionID: to.Ptr("/providers/Microsoft.Authorization/policyDefinitions/7433c107-6db4-4ad1-b57a-a76dce0154a1"), - // }, - // } -} - -// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/d55b8005f05b040b852c15e74a0f3e36494a15e1/specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/getPolicyAssignmentWithIdentityById.json -func ExampleAssignmentsClient_GetByID_retrieveAPolicyAssignmentWithAManagedIdentityById() { - cred, err := azidentity.NewDefaultAzureCredential(nil) - if err != nil { - log.Fatalf("failed to obtain a credential: %v", err) - } - ctx := context.Background() - clientFactory, err := armpolicy.NewClientFactory("", cred, nil) - if err != nil { - log.Fatalf("failed to create client: %v", err) - } - res, err := clientFactory.NewAssignmentsClient().GetByID(ctx, "providers/Microsoft.Management/managementGroups/MyManagementGroup/providers/Microsoft.Authorization/policyAssignments/LowCostStorage", nil) - if err != nil { - log.Fatalf("failed to finish the request: %v", err) - } - // You could use response here. We use blank identifier for just demo purposes. - _ = res - // If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes. - // res.Assignment = armpolicy.Assignment{ - // Name: to.Ptr("LowCostStorage"), - // Type: to.Ptr("Microsoft.Authorization/policyAssignments"), - // ID: to.Ptr("/providers/Microsoft.Management/managementGroups/MyManagementGroup/providers/Microsoft.Authorization/policyAssignments/LowCostStorage"), - // Identity: &armpolicy.Identity{ - // Type: to.Ptr(armpolicy.ResourceIdentityTypeSystemAssigned), - // PrincipalID: to.Ptr("e6d23f8d-af97-4fbc-bda6-00604e4e3d0a"), - // TenantID: to.Ptr("4bee2b8a-1bee-47c2-90e9-404241551135"), - // }, - // Location: to.Ptr("westus"), - // Properties: &armpolicy.AssignmentProperties{ - // Description: to.Ptr("Allow only storage accounts of SKU Standard_GRS or Standard_LRS to be created"), - // DisplayName: to.Ptr("Enforce storage account SKU"), - // EnforcementMode: to.Ptr(armpolicy.EnforcementModeDefault), - // Metadata: map[string]any{ - // "assignedBy": "Cheapskate Boss", - // }, - // NotScopes: []*string{ - // }, - // Parameters: map[string]*armpolicy.ParameterValuesValue{ - // "listOfAllowedSKUs": &armpolicy.ParameterValuesValue{ - // Value: []any{ - // "Standard_GRS", - // "Standard_LRS", - // }, - // }, - // }, - // PolicyDefinitionID: to.Ptr("/providers/Microsoft.Authorization/policyDefinitions/7433c107-6db4-4ad1-b57a-a76dce0154a1"), - // }, - // } -} - -// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/d55b8005f05b040b852c15e74a0f3e36494a15e1/specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/updatePolicyAssignmentWithIdentityById.json -func ExampleAssignmentsClient_UpdateByID() { - cred, err := azidentity.NewDefaultAzureCredential(nil) - if err != nil { - log.Fatalf("failed to obtain a credential: %v", err) - } - ctx := context.Background() - clientFactory, err := armpolicy.NewClientFactory("", cred, nil) - if err != nil { - log.Fatalf("failed to create client: %v", err) - } - res, err := clientFactory.NewAssignmentsClient().UpdateByID(ctx, "providers/Microsoft.Management/managementGroups/MyManagementGroup/providers/Microsoft.Authorization/policyAssignments/LowCostStorage", armpolicy.AssignmentUpdate{ - Identity: &armpolicy.Identity{ - Type: to.Ptr(armpolicy.ResourceIdentityTypeSystemAssigned), - }, - Location: to.Ptr("eastus"), - }, nil) - if err != nil { - log.Fatalf("failed to finish the request: %v", err) - } - // You could use response here. We use blank identifier for just demo purposes. - _ = res - // If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes. - // res.Assignment = armpolicy.Assignment{ - // Name: to.Ptr("LowCostStorage"), - // Type: to.Ptr("Microsoft.Authorization/policyAssignments"), - // ID: to.Ptr("/providers/Microsoft.Management/managementGroups/MyManagementGroup/providers/Microsoft.Authorization/policyAssignments/LowCostStorage"), - // Identity: &armpolicy.Identity{ - // Type: to.Ptr(armpolicy.ResourceIdentityTypeSystemAssigned), - // PrincipalID: to.Ptr("e6d23f8d-af97-4fbc-bda6-00604e4e3d0a"), - // TenantID: to.Ptr("4bee2b8a-1bee-47c2-90e9-404241551135"), - // }, - // Location: to.Ptr("eastus"), - // Properties: &armpolicy.AssignmentProperties{ - // Description: to.Ptr("Allow only storage accounts of SKU Standard_GRS or Standard_LRS to be created"), - // DisplayName: to.Ptr("Enforce storage account SKU"), - // EnforcementMode: to.Ptr(armpolicy.EnforcementModeDefault), - // Metadata: map[string]any{ - // "assignedBy": "Cheapskate Boss", - // }, - // NotScopes: []*string{ - // }, - // Parameters: map[string]*armpolicy.ParameterValuesValue{ - // "listOfAllowedSKUs": &armpolicy.ParameterValuesValue{ - // Value: []any{ - // "Standard_GRS", - // "Standard_LRS", - // }, - // }, - // }, - // PolicyDefinitionID: to.Ptr("/providers/Microsoft.Authorization/policyDefinitions/7433c107-6db4-4ad1-b57a-a76dce0154a1"), - // }, - // } -} diff --git a/sdk/resourcemanager/resources/armpolicy/autorest.md b/sdk/resourcemanager/resources/armpolicy/autorest.md index 2a17980c1ad9..79789a879d26 100644 --- a/sdk/resourcemanager/resources/armpolicy/autorest.md +++ b/sdk/resourcemanager/resources/armpolicy/autorest.md @@ -5,9 +5,9 @@ ``` yaml azure-arm: true require: -- https://github.com/Azure/azure-rest-api-specs/blob/d55b8005f05b040b852c15e74a0f3e36494a15e1/specification/resources/resource-manager/readme.md -- https://github.com/Azure/azure-rest-api-specs/blob/d55b8005f05b040b852c15e74a0f3e36494a15e1/specification/resources/resource-manager/readme.go.md +- /mnt/vss/_work/1/s/azure-rest-api-specs/specification/resources/resource-manager/readme.md +- /mnt/vss/_work/1/s/azure-rest-api-specs/specification/resources/resource-manager/readme.go.md license-header: MICROSOFT_MIT_NO_VERSION -module-version: 0.7.1 +module-version: 0.8.0 package-policy: true ``` \ No newline at end of file diff --git a/sdk/resourcemanager/resources/armpolicy/client_factory.go b/sdk/resourcemanager/resources/armpolicy/client_factory.go index 30a6d2e1e6fa..48162b50c005 100644 --- a/sdk/resourcemanager/resources/armpolicy/client_factory.go +++ b/sdk/resourcemanager/resources/armpolicy/client_factory.go @@ -43,11 +43,6 @@ func (c *ClientFactory) NewDataPolicyManifestsClient() *DataPolicyManifestsClien return subClient } -func (c *ClientFactory) NewAssignmentsClient() *AssignmentsClient { - subClient, _ := NewAssignmentsClient(c.subscriptionID, c.credential, c.options) - return subClient -} - func (c *ClientFactory) NewDefinitionsClient() *DefinitionsClient { subClient, _ := NewDefinitionsClient(c.subscriptionID, c.credential, c.options) return subClient @@ -58,7 +53,22 @@ func (c *ClientFactory) NewSetDefinitionsClient() *SetDefinitionsClient { return subClient } +func (c *ClientFactory) NewAssignmentsClient() *AssignmentsClient { + subClient, _ := NewAssignmentsClient(c.subscriptionID, c.credential, c.options) + return subClient +} + func (c *ClientFactory) NewExemptionsClient() *ExemptionsClient { subClient, _ := NewExemptionsClient(c.subscriptionID, c.credential, c.options) return subClient } + +func (c *ClientFactory) NewVariablesClient() *VariablesClient { + subClient, _ := NewVariablesClient(c.subscriptionID, c.credential, c.options) + return subClient +} + +func (c *ClientFactory) NewVariableValuesClient() *VariableValuesClient { + subClient, _ := NewVariableValuesClient(c.subscriptionID, c.credential, c.options) + return subClient +} diff --git a/sdk/resourcemanager/resources/armpolicy/constants.go b/sdk/resourcemanager/resources/armpolicy/constants.go index c65091adc04e..89339055e28e 100644 --- a/sdk/resourcemanager/resources/armpolicy/constants.go +++ b/sdk/resourcemanager/resources/armpolicy/constants.go @@ -11,7 +11,7 @@ package armpolicy const ( moduleName = "armpolicy" - moduleVersion = "v0.7.1" + moduleVersion = "v0.8.0" ) // AliasPathAttributes - The attributes of the token that the alias path is referring to. @@ -107,6 +107,25 @@ func PossibleAliasTypeValues() []AliasType { } } +// AssignmentScopeValidation - The option whether validate the exemption is at or under the assignment scope. +type AssignmentScopeValidation string + +const ( + // AssignmentScopeValidationDefault - This option will validate the exemption is at or under the assignment scope. + AssignmentScopeValidationDefault AssignmentScopeValidation = "Default" + // AssignmentScopeValidationDoNotValidate - This option will bypass the validation the exemption scope is at or under the + // policy assignment scope. + AssignmentScopeValidationDoNotValidate AssignmentScopeValidation = "DoNotValidate" +) + +// PossibleAssignmentScopeValidationValues returns the possible values for the AssignmentScopeValidation const type. +func PossibleAssignmentScopeValidationValues() []AssignmentScopeValidation { + return []AssignmentScopeValidation{ + AssignmentScopeValidationDefault, + AssignmentScopeValidationDoNotValidate, + } +} + // CreatedByType - The type of identity that created the resource. type CreatedByType string @@ -164,6 +183,21 @@ func PossibleExemptionCategoryValues() []ExemptionCategory { } } +// OverrideKind - The override kind. +type OverrideKind string + +const ( + // OverrideKindPolicyEffect - It will override the policy effect type. + OverrideKindPolicyEffect OverrideKind = "policyEffect" +) + +// PossibleOverrideKindValues returns the possible values for the OverrideKind const type. +func PossibleOverrideKindValues() []OverrideKind { + return []OverrideKind{ + OverrideKindPolicyEffect, + } +} + // ParameterType - The data type of the parameter. type ParameterType string @@ -232,3 +266,27 @@ func PossibleResourceIdentityTypeValues() []ResourceIdentityType { ResourceIdentityTypeNone, } } + +// SelectorKind - The selector kind. +type SelectorKind string + +const ( + // SelectorKindPolicyDefinitionReferenceID - The selector kind to filter policies by the policy definition reference ID. + SelectorKindPolicyDefinitionReferenceID SelectorKind = "policyDefinitionReferenceId" + // SelectorKindResourceLocation - The selector kind to filter policies by the resource location. + SelectorKindResourceLocation SelectorKind = "resourceLocation" + // SelectorKindResourceType - The selector kind to filter policies by the resource type. + SelectorKindResourceType SelectorKind = "resourceType" + // SelectorKindResourceWithoutLocation - The selector kind to filter policies by the resource without location. + SelectorKindResourceWithoutLocation SelectorKind = "resourceWithoutLocation" +) + +// PossibleSelectorKindValues returns the possible values for the SelectorKind const type. +func PossibleSelectorKindValues() []SelectorKind { + return []SelectorKind{ + SelectorKindPolicyDefinitionReferenceID, + SelectorKindResourceLocation, + SelectorKindResourceType, + SelectorKindResourceWithoutLocation, + } +} diff --git a/sdk/resourcemanager/resources/armpolicy/datapolicymanifests_client_example_test.go b/sdk/resourcemanager/resources/armpolicy/datapolicymanifests_client_example_test.go deleted file mode 100644 index d893eddbcb04..000000000000 --- a/sdk/resourcemanager/resources/armpolicy/datapolicymanifests_client_example_test.go +++ /dev/null @@ -1,278 +0,0 @@ -//go:build go1.18 -// +build go1.18 - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See License.txt in the project root for license information. -// Code generated by Microsoft (R) AutoRest Code Generator. -// Changes may cause incorrect behavior and will be lost if the code is regenerated. -// DO NOT EDIT. - -package armpolicy_test - -import ( - "context" - "log" - - "github.com/Azure/azure-sdk-for-go/sdk/azcore/to" - "github.com/Azure/azure-sdk-for-go/sdk/azidentity" - "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armpolicy" -) - -// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/d55b8005f05b040b852c15e74a0f3e36494a15e1/specification/resources/resource-manager/Microsoft.Authorization/stable/2020-09-01/examples/getDataPolicyManifest.json -func ExampleDataPolicyManifestsClient_GetByPolicyMode() { - cred, err := azidentity.NewDefaultAzureCredential(nil) - if err != nil { - log.Fatalf("failed to obtain a credential: %v", err) - } - ctx := context.Background() - clientFactory, err := armpolicy.NewClientFactory("", cred, nil) - if err != nil { - log.Fatalf("failed to create client: %v", err) - } - res, err := clientFactory.NewDataPolicyManifestsClient().GetByPolicyMode(ctx, "Microsoft.KeyVault.Data", nil) - if err != nil { - log.Fatalf("failed to finish the request: %v", err) - } - // You could use response here. We use blank identifier for just demo purposes. - _ = res - // If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes. - // res.DataPolicyManifest = armpolicy.DataPolicyManifest{ - // Name: to.Ptr("Microsoft.KeyVault.Data"), - // Type: to.Ptr("Microsoft.Authorization/dataPolicyManifests"), - // ID: to.Ptr("/providers/Microsoft.Authorization/dataPolicyManifests/Microsoft.KeyVault.Data"), - // Properties: &armpolicy.DataPolicyManifestProperties{ - // Effects: []*armpolicy.DataEffect{ - // { - // Name: to.Ptr("Audit"), - // }, - // { - // Name: to.Ptr("Deny"), - // }}, - // FieldValues: []*string{ - // to.Ptr("type")}, - // IsBuiltInOnly: to.Ptr(true), - // Namespaces: []*string{ - // to.Ptr("Microsoft.KeyVault")}, - // PolicyMode: to.Ptr("Microsoft.KeyVault.Data"), - // ResourceFunctions: &armpolicy.DataManifestResourceFunctionsDefinition{ - // Custom: []*armpolicy.DataManifestCustomResourceFunctionDefinition{ - // { - // Name: to.Ptr("vault"), - // AllowCustomProperties: to.Ptr(false), - // DefaultProperties: []*string{ - // to.Ptr("location"), - // to.Ptr("tags")}, - // FullyQualifiedResourceType: to.Ptr("Microsoft.KeyVault/vaults"), - // }}, - // Standard: []*string{ - // to.Ptr("subscription"), - // to.Ptr("resourceGroup")}, - // }, - // ResourceTypeAliases: []*armpolicy.ResourceTypeAliases{ - // { - // Aliases: []*armpolicy.Alias{ - // { - // Name: to.Ptr("Microsoft.KeyVault.Data/vaults/certificates/keyProperties.keyType"), - // Paths: []*armpolicy.AliasPath{ - // { - // Path: to.Ptr("keyProperties.keyType"), - // APIVersions: []*string{ - // to.Ptr("2019-01-01")}, - // }}, - // }}, - // ResourceType: to.Ptr("vaults/certificates"), - // }}, - // }, - // } -} - -// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/d55b8005f05b040b852c15e74a0f3e36494a15e1/specification/resources/resource-manager/Microsoft.Authorization/stable/2020-09-01/examples/listDataPolicyManifests.json -func ExampleDataPolicyManifestsClient_NewListPager_listDataPolicyManifests() { - cred, err := azidentity.NewDefaultAzureCredential(nil) - if err != nil { - log.Fatalf("failed to obtain a credential: %v", err) - } - ctx := context.Background() - clientFactory, err := armpolicy.NewClientFactory("", cred, nil) - if err != nil { - log.Fatalf("failed to create client: %v", err) - } - pager := clientFactory.NewDataPolicyManifestsClient().NewListPager(&armpolicy.DataPolicyManifestsClientListOptions{Filter: nil}) - for pager.More() { - page, err := pager.NextPage(ctx) - if err != nil { - log.Fatalf("failed to advance page: %v", err) - } - for _, v := range page.Value { - // You could use page here. We use blank identifier for just demo purposes. - _ = v - } - // If the HTTP response code is 200 as defined in example definition, your page structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes. - // page.DataPolicyManifestListResult = armpolicy.DataPolicyManifestListResult{ - // Value: []*armpolicy.DataPolicyManifest{ - // { - // Name: to.Ptr("Microsoft.KeyVault.Data"), - // Type: to.Ptr("Microsoft.Authorization/dataPolicyManifests"), - // ID: to.Ptr("/providers/Microsoft.Authorization/dataPolicyManifests/Microsoft.KeyVault.Data"), - // Properties: &armpolicy.DataPolicyManifestProperties{ - // Effects: []*armpolicy.DataEffect{ - // { - // Name: to.Ptr("audit"), - // }, - // { - // Name: to.Ptr("deny"), - // }}, - // FieldValues: []*string{ - // to.Ptr("type")}, - // IsBuiltInOnly: to.Ptr(true), - // Namespaces: []*string{ - // to.Ptr("Microsoft.KeyVault")}, - // PolicyMode: to.Ptr("Microsoft.KeyVault.Data"), - // ResourceFunctions: &armpolicy.DataManifestResourceFunctionsDefinition{ - // Custom: []*armpolicy.DataManifestCustomResourceFunctionDefinition{ - // { - // Name: to.Ptr("vault"), - // AllowCustomProperties: to.Ptr(false), - // DefaultProperties: []*string{ - // to.Ptr("location"), - // to.Ptr("tags")}, - // FullyQualifiedResourceType: to.Ptr("Microsoft.KeyVault/vaults"), - // }}, - // Standard: []*string{ - // to.Ptr("subscription"), - // to.Ptr("resourceGroup")}, - // }, - // ResourceTypeAliases: []*armpolicy.ResourceTypeAliases{ - // { - // Aliases: []*armpolicy.Alias{ - // { - // Name: to.Ptr("Microsoft.KeyVault.Data/vaults/certificates/keyProperties.keyType"), - // Paths: []*armpolicy.AliasPath{ - // { - // Path: to.Ptr("keyProperties.keyType"), - // APIVersions: []*string{ - // to.Ptr("2019-01-01")}, - // }}, - // }}, - // ResourceType: to.Ptr("vaults/certificates"), - // }}, - // }, - // }, - // { - // Name: to.Ptr("Microsoft.Kubernetes.Data"), - // Type: to.Ptr("Microsoft.Authorization/dataPolicyManifests"), - // ID: to.Ptr("/providers/Microsoft.Authorization/dataPolicyManifests/Microsoft.Kubernetes.Data"), - // Properties: &armpolicy.DataPolicyManifestProperties{ - // Effects: []*armpolicy.DataEffect{ - // { - // Name: to.Ptr("audit"), - // DetailsSchema: map[string]any{ - // "type": "object", - // "additionalProperties": false, - // "properties":map[string]any{ - // "constraint":map[string]any{ - // "type": "string", - // "pattern": "^(?i)(https:\\/\\/raw\\.githubusercontent\\.com\\/){1}(.+)(\\.){1}(yaml|yml){1}$", - // }, - // "constraintTemplate":map[string]any{ - // "type": "string", - // "pattern": "^(?i)(https:\\/\\/raw\\.githubusercontent\\.com\\/){1}(.+)(\\.){1}(yaml|yml){1}$", - // }, - // "values":map[string]any{ - // "type": "object", - // "additionalProperties":map[string]any{ - // }, - // "maxProperties": float64(10), - // }, - // }, - // "required":[]any{ - // "constraintTemplate", - // }, - // }, - // }}, - // IsBuiltInOnly: to.Ptr(false), - // Namespaces: []*string{ - // to.Ptr("Microsoft.Kubernetes"), - // to.Ptr("Microsoft.ContainerService")}, - // PolicyMode: to.Ptr("Microsoft.Kubernetes.Data"), - // }, - // }}, - // } - } -} - -// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/d55b8005f05b040b852c15e74a0f3e36494a15e1/specification/resources/resource-manager/Microsoft.Authorization/stable/2020-09-01/examples/listDataPolicyManifestsNamespaceFilter.json -func ExampleDataPolicyManifestsClient_NewListPager_listDataPolicyManifestsWithNamespaceFilter() { - cred, err := azidentity.NewDefaultAzureCredential(nil) - if err != nil { - log.Fatalf("failed to obtain a credential: %v", err) - } - ctx := context.Background() - clientFactory, err := armpolicy.NewClientFactory("", cred, nil) - if err != nil { - log.Fatalf("failed to create client: %v", err) - } - pager := clientFactory.NewDataPolicyManifestsClient().NewListPager(&armpolicy.DataPolicyManifestsClientListOptions{Filter: to.Ptr("namespace eq 'Microsoft.KeyVault'")}) - for pager.More() { - page, err := pager.NextPage(ctx) - if err != nil { - log.Fatalf("failed to advance page: %v", err) - } - for _, v := range page.Value { - // You could use page here. We use blank identifier for just demo purposes. - _ = v - } - // If the HTTP response code is 200 as defined in example definition, your page structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes. - // page.DataPolicyManifestListResult = armpolicy.DataPolicyManifestListResult{ - // Value: []*armpolicy.DataPolicyManifest{ - // { - // Name: to.Ptr("Microsoft.KeyVault.Data"), - // Type: to.Ptr("Microsoft.Authorization/dataPolicyManifests"), - // ID: to.Ptr("/providers/Microsoft.Authorization/dataPolicyManifests/Microsoft.KeyVault.Data"), - // Properties: &armpolicy.DataPolicyManifestProperties{ - // Effects: []*armpolicy.DataEffect{ - // { - // Name: to.Ptr("audit"), - // }, - // { - // Name: to.Ptr("deny"), - // }}, - // FieldValues: []*string{ - // to.Ptr("type")}, - // IsBuiltInOnly: to.Ptr(true), - // Namespaces: []*string{ - // to.Ptr("Microsoft.KeyVault")}, - // PolicyMode: to.Ptr("Microsoft.KeyVault.Data"), - // ResourceFunctions: &armpolicy.DataManifestResourceFunctionsDefinition{ - // Custom: []*armpolicy.DataManifestCustomResourceFunctionDefinition{ - // { - // Name: to.Ptr("vault"), - // AllowCustomProperties: to.Ptr(false), - // DefaultProperties: []*string{ - // to.Ptr("location"), - // to.Ptr("tags")}, - // FullyQualifiedResourceType: to.Ptr("Microsoft.KeyVault/vaults"), - // }}, - // Standard: []*string{ - // to.Ptr("subscription"), - // to.Ptr("resourceGroup")}, - // }, - // ResourceTypeAliases: []*armpolicy.ResourceTypeAliases{ - // { - // Aliases: []*armpolicy.Alias{ - // { - // Name: to.Ptr("Microsoft.KeyVault.Data/vaults/certificates/keyProperties.keyType"), - // Paths: []*armpolicy.AliasPath{ - // { - // Path: to.Ptr("keyProperties.keyType"), - // APIVersions: []*string{ - // to.Ptr("2019-01-01")}, - // }}, - // }}, - // ResourceType: to.Ptr("vaults/certificates"), - // }}, - // }, - // }}, - // } - } -} diff --git a/sdk/resourcemanager/resources/armpolicy/definitions_client_example_test.go b/sdk/resourcemanager/resources/armpolicy/definitions_client_example_test.go deleted file mode 100644 index c60b1345b336..000000000000 --- a/sdk/resourcemanager/resources/armpolicy/definitions_client_example_test.go +++ /dev/null @@ -1,806 +0,0 @@ -//go:build go1.18 -// +build go1.18 - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See License.txt in the project root for license information. -// Code generated by Microsoft (R) AutoRest Code Generator. -// Changes may cause incorrect behavior and will be lost if the code is regenerated. -// DO NOT EDIT. - -package armpolicy_test - -import ( - "context" - "log" - - "github.com/Azure/azure-sdk-for-go/sdk/azcore/to" - "github.com/Azure/azure-sdk-for-go/sdk/azidentity" - "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armpolicy" -) - -// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/d55b8005f05b040b852c15e74a0f3e36494a15e1/specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/createOrUpdatePolicyDefinition.json -func ExampleDefinitionsClient_CreateOrUpdate_createOrUpdateAPolicyDefinition() { - cred, err := azidentity.NewDefaultAzureCredential(nil) - if err != nil { - log.Fatalf("failed to obtain a credential: %v", err) - } - ctx := context.Background() - clientFactory, err := armpolicy.NewClientFactory("", cred, nil) - if err != nil { - log.Fatalf("failed to create client: %v", err) - } - _, err = clientFactory.NewDefinitionsClient().CreateOrUpdate(ctx, "ResourceNaming", armpolicy.Definition{ - Properties: &armpolicy.DefinitionProperties{ - Description: to.Ptr("Force resource names to begin with given 'prefix' and/or end with given 'suffix'"), - DisplayName: to.Ptr("Enforce resource naming convention"), - Metadata: map[string]any{ - "category": "Naming", - }, - Mode: to.Ptr("All"), - Parameters: map[string]*armpolicy.ParameterDefinitionsValue{ - "prefix": { - Type: to.Ptr(armpolicy.ParameterTypeString), - Metadata: &armpolicy.ParameterDefinitionsValueMetadata{ - Description: to.Ptr("Resource name prefix"), - DisplayName: to.Ptr("Prefix"), - }, - }, - "suffix": { - Type: to.Ptr(armpolicy.ParameterTypeString), - Metadata: &armpolicy.ParameterDefinitionsValueMetadata{ - Description: to.Ptr("Resource name suffix"), - DisplayName: to.Ptr("Suffix"), - }, - }, - }, - PolicyRule: map[string]any{ - "if": map[string]any{ - "not": map[string]any{ - "field": "name", - "like": "[concat(parameters('prefix'), '*', parameters('suffix'))]", - }, - }, - "then": map[string]any{ - "effect": "deny", - }, - }, - }, - }, nil) - if err != nil { - log.Fatalf("failed to finish the request: %v", err) - } -} - -// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/d55b8005f05b040b852c15e74a0f3e36494a15e1/specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/createOrUpdatePolicyDefinitionAdvancedParams.json -func ExampleDefinitionsClient_CreateOrUpdate_createOrUpdateAPolicyDefinitionWithAdvancedParameters() { - cred, err := azidentity.NewDefaultAzureCredential(nil) - if err != nil { - log.Fatalf("failed to obtain a credential: %v", err) - } - ctx := context.Background() - clientFactory, err := armpolicy.NewClientFactory("", cred, nil) - if err != nil { - log.Fatalf("failed to create client: %v", err) - } - _, err = clientFactory.NewDefinitionsClient().CreateOrUpdate(ctx, "EventHubDiagnosticLogs", armpolicy.Definition{ - Properties: &armpolicy.DefinitionProperties{ - Description: to.Ptr("Audit enabling of logs and retain them up to a year. This enables recreation of activity trails for investigation purposes when a security incident occurs or your network is compromised"), - DisplayName: to.Ptr("Event Hubs should have diagnostic logging enabled"), - Metadata: map[string]any{ - "category": "Event Hub", - }, - Mode: to.Ptr("Indexed"), - Parameters: map[string]*armpolicy.ParameterDefinitionsValue{ - "requiredRetentionDays": { - Type: to.Ptr(armpolicy.ParameterTypeInteger), - AllowedValues: []any{ - float64(0), - float64(30), - float64(90), - float64(180), - float64(365)}, - DefaultValue: float64(365), - Metadata: &armpolicy.ParameterDefinitionsValueMetadata{ - Description: to.Ptr("The required diagnostic logs retention in days"), - DisplayName: to.Ptr("Required retention (days)"), - }, - }, - }, - PolicyRule: map[string]any{ - "if": map[string]any{ - "equals": "Microsoft.EventHub/namespaces", - "field": "type", - }, - "then": map[string]any{ - "effect": "AuditIfNotExists", - "details": map[string]any{ - "type": "Microsoft.Insights/diagnosticSettings", - "existenceCondition": map[string]any{ - "allOf": []any{ - map[string]any{ - "equals": "true", - "field": "Microsoft.Insights/diagnosticSettings/logs[*].retentionPolicy.enabled", - }, - map[string]any{ - "equals": "[parameters('requiredRetentionDays')]", - "field": "Microsoft.Insights/diagnosticSettings/logs[*].retentionPolicy.days", - }, - }, - }, - }, - }, - }, - }, - }, nil) - if err != nil { - log.Fatalf("failed to finish the request: %v", err) - } -} - -// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/d55b8005f05b040b852c15e74a0f3e36494a15e1/specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/deletePolicyDefinition.json -func ExampleDefinitionsClient_Delete() { - cred, err := azidentity.NewDefaultAzureCredential(nil) - if err != nil { - log.Fatalf("failed to obtain a credential: %v", err) - } - ctx := context.Background() - clientFactory, err := armpolicy.NewClientFactory("", cred, nil) - if err != nil { - log.Fatalf("failed to create client: %v", err) - } - _, err = clientFactory.NewDefinitionsClient().Delete(ctx, "ResourceNaming", nil) - if err != nil { - log.Fatalf("failed to finish the request: %v", err) - } -} - -// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/d55b8005f05b040b852c15e74a0f3e36494a15e1/specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/getPolicyDefinition.json -func ExampleDefinitionsClient_Get() { - cred, err := azidentity.NewDefaultAzureCredential(nil) - if err != nil { - log.Fatalf("failed to obtain a credential: %v", err) - } - ctx := context.Background() - clientFactory, err := armpolicy.NewClientFactory("", cred, nil) - if err != nil { - log.Fatalf("failed to create client: %v", err) - } - res, err := clientFactory.NewDefinitionsClient().Get(ctx, "ResourceNaming", nil) - if err != nil { - log.Fatalf("failed to finish the request: %v", err) - } - // You could use response here. We use blank identifier for just demo purposes. - _ = res - // If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes. - // res.Definition = armpolicy.Definition{ - // Name: to.Ptr("ResourceNaming"), - // Type: to.Ptr("Microsoft.Authorization/policyDefinitions"), - // ID: to.Ptr("/subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2/providers/Microsoft.Authorization/policyDefinitions/ResourceNaming"), - // Properties: &armpolicy.DefinitionProperties{ - // Description: to.Ptr("Force resource names to begin with 'prefix' and end with 'suffix'"), - // DisplayName: to.Ptr("Naming Convention"), - // Metadata: map[string]any{ - // "category": "Naming", - // }, - // Mode: to.Ptr("All"), - // Parameters: map[string]*armpolicy.ParameterDefinitionsValue{ - // "prefix": &armpolicy.ParameterDefinitionsValue{ - // Type: to.Ptr(armpolicy.ParameterTypeString), - // Metadata: &armpolicy.ParameterDefinitionsValueMetadata{ - // Description: to.Ptr("Resource name prefix"), - // DisplayName: to.Ptr("Prefix"), - // }, - // }, - // "suffix": &armpolicy.ParameterDefinitionsValue{ - // Type: to.Ptr(armpolicy.ParameterTypeString), - // Metadata: &armpolicy.ParameterDefinitionsValueMetadata{ - // Description: to.Ptr("Resource name suffix"), - // DisplayName: to.Ptr("Suffix"), - // }, - // }, - // }, - // PolicyRule: map[string]any{ - // "if":map[string]any{ - // "not":map[string]any{ - // "field": "name", - // "like": "[concat(parameters('prefix'), '*', parameters('suffix'))]", - // }, - // }, - // "then":map[string]any{ - // "effect": "deny", - // }, - // }, - // PolicyType: to.Ptr(armpolicy.PolicyTypeCustom), - // }, - // } -} - -// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/d55b8005f05b040b852c15e74a0f3e36494a15e1/specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/getBuiltinPolicyDefinition.json -func ExampleDefinitionsClient_GetBuiltIn() { - cred, err := azidentity.NewDefaultAzureCredential(nil) - if err != nil { - log.Fatalf("failed to obtain a credential: %v", err) - } - ctx := context.Background() - clientFactory, err := armpolicy.NewClientFactory("", cred, nil) - if err != nil { - log.Fatalf("failed to create client: %v", err) - } - res, err := clientFactory.NewDefinitionsClient().GetBuiltIn(ctx, "7433c107-6db4-4ad1-b57a-a76dce0154a1", nil) - if err != nil { - log.Fatalf("failed to finish the request: %v", err) - } - // You could use response here. We use blank identifier for just demo purposes. - _ = res - // If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes. - // res.Definition = armpolicy.Definition{ - // Name: to.Ptr("7433c107-6db4-4ad1-b57a-a76dce0154a1"), - // Type: to.Ptr("Microsoft.Authorization/policyDefinitions"), - // ID: to.Ptr("/providers/Microsoft.Authorization/policyDefinitions/7433c107-6db4-4ad1-b57a-a76dce0154a1"), - // Properties: &armpolicy.DefinitionProperties{ - // Description: to.Ptr("This policy enables you to specify a set of storage account SKUs that your organization can deploy."), - // DisplayName: to.Ptr("Allowed storage account SKUs"), - // Mode: to.Ptr("All"), - // Parameters: map[string]*armpolicy.ParameterDefinitionsValue{ - // "listOfAllowedSKUs": &armpolicy.ParameterDefinitionsValue{ - // Type: to.Ptr(armpolicy.ParameterTypeArray), - // Metadata: &armpolicy.ParameterDefinitionsValueMetadata{ - // Description: to.Ptr("The list of SKUs that can be specified for storage accounts."), - // DisplayName: to.Ptr("Allowed SKUs"), - // StrongType: to.Ptr("StorageSKUs"), - // }, - // }, - // }, - // PolicyRule: map[string]any{ - // "if":map[string]any{ - // "allOf":[]any{ - // map[string]any{ - // "equals": "Microsoft.Storage/storageAccounts", - // "field": "type", - // }, - // map[string]any{ - // "not":map[string]any{ - // "field": "Microsoft.Storage/storageAccounts/sku.name", - // "in": "[parameters('listOfAllowedSKUs')]", - // }, - // }, - // }, - // }, - // "then":map[string]any{ - // "effect": "Deny", - // }, - // }, - // PolicyType: to.Ptr(armpolicy.PolicyTypeBuiltIn), - // }, - // } -} - -// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/d55b8005f05b040b852c15e74a0f3e36494a15e1/specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/createOrUpdatePolicyDefinitionAtManagementGroup.json -func ExampleDefinitionsClient_CreateOrUpdateAtManagementGroup() { - cred, err := azidentity.NewDefaultAzureCredential(nil) - if err != nil { - log.Fatalf("failed to obtain a credential: %v", err) - } - ctx := context.Background() - clientFactory, err := armpolicy.NewClientFactory("", cred, nil) - if err != nil { - log.Fatalf("failed to create client: %v", err) - } - _, err = clientFactory.NewDefinitionsClient().CreateOrUpdateAtManagementGroup(ctx, "ResourceNaming", "MyManagementGroup", armpolicy.Definition{ - Properties: &armpolicy.DefinitionProperties{ - Description: to.Ptr("Force resource names to begin with given 'prefix' and/or end with given 'suffix'"), - DisplayName: to.Ptr("Enforce resource naming convention"), - Metadata: map[string]any{ - "category": "Naming", - }, - Mode: to.Ptr("All"), - Parameters: map[string]*armpolicy.ParameterDefinitionsValue{ - "prefix": { - Type: to.Ptr(armpolicy.ParameterTypeString), - Metadata: &armpolicy.ParameterDefinitionsValueMetadata{ - Description: to.Ptr("Resource name prefix"), - DisplayName: to.Ptr("Prefix"), - }, - }, - "suffix": { - Type: to.Ptr(armpolicy.ParameterTypeString), - Metadata: &armpolicy.ParameterDefinitionsValueMetadata{ - Description: to.Ptr("Resource name suffix"), - DisplayName: to.Ptr("Suffix"), - }, - }, - }, - PolicyRule: map[string]any{ - "if": map[string]any{ - "not": map[string]any{ - "field": "name", - "like": "[concat(parameters('prefix'), '*', parameters('suffix'))]", - }, - }, - "then": map[string]any{ - "effect": "deny", - }, - }, - }, - }, nil) - if err != nil { - log.Fatalf("failed to finish the request: %v", err) - } -} - -// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/d55b8005f05b040b852c15e74a0f3e36494a15e1/specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/deletePolicyDefinitionAtManagementGroup.json -func ExampleDefinitionsClient_DeleteAtManagementGroup() { - cred, err := azidentity.NewDefaultAzureCredential(nil) - if err != nil { - log.Fatalf("failed to obtain a credential: %v", err) - } - ctx := context.Background() - clientFactory, err := armpolicy.NewClientFactory("", cred, nil) - if err != nil { - log.Fatalf("failed to create client: %v", err) - } - _, err = clientFactory.NewDefinitionsClient().DeleteAtManagementGroup(ctx, "ResourceNaming", "MyManagementGroup", nil) - if err != nil { - log.Fatalf("failed to finish the request: %v", err) - } -} - -// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/d55b8005f05b040b852c15e74a0f3e36494a15e1/specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/getPolicyDefinitionAtManagementGroup.json -func ExampleDefinitionsClient_GetAtManagementGroup() { - cred, err := azidentity.NewDefaultAzureCredential(nil) - if err != nil { - log.Fatalf("failed to obtain a credential: %v", err) - } - ctx := context.Background() - clientFactory, err := armpolicy.NewClientFactory("", cred, nil) - if err != nil { - log.Fatalf("failed to create client: %v", err) - } - res, err := clientFactory.NewDefinitionsClient().GetAtManagementGroup(ctx, "ResourceNaming", "MyManagementGroup", nil) - if err != nil { - log.Fatalf("failed to finish the request: %v", err) - } - // You could use response here. We use blank identifier for just demo purposes. - _ = res - // If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes. - // res.Definition = armpolicy.Definition{ - // Name: to.Ptr("ResourceNaming"), - // Type: to.Ptr("Microsoft.Authorization/policyDefinitions"), - // ID: to.Ptr("/providers/Microsoft.Management/managementgroups/MyManagementGroup/providers/Microsoft.Authorization/policyDefinitions/ResourceNaming"), - // Properties: &armpolicy.DefinitionProperties{ - // Description: to.Ptr("Force resource names to begin with 'prefix' and end with 'suffix'"), - // DisplayName: to.Ptr("Naming Convention"), - // Metadata: map[string]any{ - // "category": "Naming", - // }, - // Mode: to.Ptr("All"), - // Parameters: map[string]*armpolicy.ParameterDefinitionsValue{ - // "prefix": &armpolicy.ParameterDefinitionsValue{ - // Type: to.Ptr(armpolicy.ParameterTypeString), - // Metadata: &armpolicy.ParameterDefinitionsValueMetadata{ - // Description: to.Ptr("Resource name prefix"), - // DisplayName: to.Ptr("Prefix"), - // }, - // }, - // "suffix": &armpolicy.ParameterDefinitionsValue{ - // Type: to.Ptr(armpolicy.ParameterTypeString), - // Metadata: &armpolicy.ParameterDefinitionsValueMetadata{ - // Description: to.Ptr("Resource name suffix"), - // DisplayName: to.Ptr("Suffix"), - // }, - // }, - // }, - // PolicyRule: map[string]any{ - // "if":map[string]any{ - // "not":map[string]any{ - // "field": "name", - // "like": "[concat(parameters('prefix'), '*', parameters('suffix'))]", - // }, - // }, - // "then":map[string]any{ - // "effect": "deny", - // }, - // }, - // PolicyType: to.Ptr(armpolicy.PolicyTypeCustom), - // }, - // } -} - -// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/d55b8005f05b040b852c15e74a0f3e36494a15e1/specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/listPolicyDefinitions.json -func ExampleDefinitionsClient_NewListPager() { - cred, err := azidentity.NewDefaultAzureCredential(nil) - if err != nil { - log.Fatalf("failed to obtain a credential: %v", err) - } - ctx := context.Background() - clientFactory, err := armpolicy.NewClientFactory("", cred, nil) - if err != nil { - log.Fatalf("failed to create client: %v", err) - } - pager := clientFactory.NewDefinitionsClient().NewListPager(&armpolicy.DefinitionsClientListOptions{Filter: nil, - Top: nil, - }) - for pager.More() { - page, err := pager.NextPage(ctx) - if err != nil { - log.Fatalf("failed to advance page: %v", err) - } - for _, v := range page.Value { - // You could use page here. We use blank identifier for just demo purposes. - _ = v - } - // If the HTTP response code is 200 as defined in example definition, your page structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes. - // page.DefinitionListResult = armpolicy.DefinitionListResult{ - // Value: []*armpolicy.Definition{ - // { - // Name: to.Ptr("7433c107-6db4-4ad1-b57a-a76dce0154a1"), - // Type: to.Ptr("Microsoft.Authorization/policyDefinitions"), - // ID: to.Ptr("/providers/Microsoft.Authorization/policyDefinitions/7433c107-6db4-4ad1-b57a-a76dce0154a1"), - // Properties: &armpolicy.DefinitionProperties{ - // Description: to.Ptr("This policy enables you to specify a set of storage account SKUs that your organization can deploy."), - // DisplayName: to.Ptr("Allowed storage account SKUs"), - // Mode: to.Ptr("All"), - // Parameters: map[string]*armpolicy.ParameterDefinitionsValue{ - // "listOfAllowedSKUs": &armpolicy.ParameterDefinitionsValue{ - // Type: to.Ptr(armpolicy.ParameterTypeArray), - // Metadata: &armpolicy.ParameterDefinitionsValueMetadata{ - // Description: to.Ptr("The list of SKUs that can be specified for storage accounts."), - // DisplayName: to.Ptr("Allowed SKUs"), - // StrongType: to.Ptr("StorageSKUs"), - // }, - // }, - // }, - // PolicyRule: map[string]any{ - // "if":map[string]any{ - // "allOf":[]any{ - // map[string]any{ - // "equals": "Microsoft.Storage/storageAccounts", - // "field": "type", - // }, - // map[string]any{ - // "not":map[string]any{ - // "field": "Microsoft.Storage/storageAccounts/sku.name", - // "in": "[parameters('listOfAllowedSKUs')]", - // }, - // }, - // }, - // }, - // "then":map[string]any{ - // "effect": "Deny", - // }, - // }, - // PolicyType: to.Ptr(armpolicy.PolicyTypeBuiltIn), - // }, - // }, - // { - // Name: to.Ptr("ResourceNaming"), - // Type: to.Ptr("Microsoft.Authorization/policyDefinitions"), - // ID: to.Ptr("/subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2/providers/Microsoft.Authorization/policyDefinitions/ResourceNaming"), - // Properties: &armpolicy.DefinitionProperties{ - // Description: to.Ptr("Force resource names to begin with 'prefix' and end with 'suffix'"), - // DisplayName: to.Ptr("Naming Convention"), - // Metadata: map[string]any{ - // "category": "Naming", - // }, - // Mode: to.Ptr("All"), - // Parameters: map[string]*armpolicy.ParameterDefinitionsValue{ - // "prefix": &armpolicy.ParameterDefinitionsValue{ - // Type: to.Ptr(armpolicy.ParameterTypeString), - // Metadata: &armpolicy.ParameterDefinitionsValueMetadata{ - // Description: to.Ptr("Resource name prefix"), - // DisplayName: to.Ptr("Prefix"), - // }, - // }, - // "suffix": &armpolicy.ParameterDefinitionsValue{ - // Type: to.Ptr(armpolicy.ParameterTypeString), - // Metadata: &armpolicy.ParameterDefinitionsValueMetadata{ - // Description: to.Ptr("Resource name suffix"), - // DisplayName: to.Ptr("Suffix"), - // }, - // }, - // }, - // PolicyRule: map[string]any{ - // "if":map[string]any{ - // "not":map[string]any{ - // "field": "name", - // "like": "[concat(parameters('prefix'), '*', parameters('suffix'))]", - // }, - // }, - // "then":map[string]any{ - // "effect": "deny", - // }, - // }, - // PolicyType: to.Ptr(armpolicy.PolicyTypeCustom), - // }, - // }, - // { - // Name: to.Ptr("AuditSoonToExpireCerts"), - // Type: to.Ptr("Microsoft.Authorization/policyDefinitions"), - // ID: to.Ptr("/subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2/providers/Microsoft.Authorization/policyDefinitions/AuditSoonToExpireCerts"), - // Properties: &armpolicy.DefinitionProperties{ - // Description: to.Ptr("Audit certificates that are stored in Azure Key Vault, that expire within 'X' number of days."), - // DisplayName: to.Ptr("Audit KeyVault certificates that expire within specified number of days"), - // Metadata: map[string]any{ - // "category": "KeyVault DataPlane", - // }, - // Mode: to.Ptr("Microsoft.KeyVault.Data"), - // Parameters: map[string]*armpolicy.ParameterDefinitionsValue{ - // "daysToExpire": &armpolicy.ParameterDefinitionsValue{ - // Type: to.Ptr(armpolicy.ParameterTypeInteger), - // Metadata: &armpolicy.ParameterDefinitionsValueMetadata{ - // Description: to.Ptr("The number of days for a certificate to expire."), - // DisplayName: to.Ptr("Days to expire"), - // }, - // }, - // }, - // PolicyRule: map[string]any{ - // "if":map[string]any{ - // "field": "Microsoft.KeyVault.Data/vaults/certificates/attributes/expiresOn", - // "lessOrEquals": "[addDays(utcNow(), parameters('daysToExpire'))]", - // }, - // "then":map[string]any{ - // "effect": "audit", - // }, - // }, - // PolicyType: to.Ptr(armpolicy.PolicyTypeCustom), - // }, - // }}, - // } - } -} - -// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/d55b8005f05b040b852c15e74a0f3e36494a15e1/specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/listBuiltInPolicyDefinitions.json -func ExampleDefinitionsClient_NewListBuiltInPager() { - cred, err := azidentity.NewDefaultAzureCredential(nil) - if err != nil { - log.Fatalf("failed to obtain a credential: %v", err) - } - ctx := context.Background() - clientFactory, err := armpolicy.NewClientFactory("", cred, nil) - if err != nil { - log.Fatalf("failed to create client: %v", err) - } - pager := clientFactory.NewDefinitionsClient().NewListBuiltInPager(&armpolicy.DefinitionsClientListBuiltInOptions{Filter: nil, - Top: nil, - }) - for pager.More() { - page, err := pager.NextPage(ctx) - if err != nil { - log.Fatalf("failed to advance page: %v", err) - } - for _, v := range page.Value { - // You could use page here. We use blank identifier for just demo purposes. - _ = v - } - // If the HTTP response code is 200 as defined in example definition, your page structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes. - // page.DefinitionListResult = armpolicy.DefinitionListResult{ - // Value: []*armpolicy.Definition{ - // { - // Name: to.Ptr("06a78e20-9358-41c9-923c-fb736d382a12"), - // Type: to.Ptr("Microsoft.Authorization/policyDefinitions"), - // ID: to.Ptr("/providers/Microsoft.Authorization/policyDefinitions/06a78e20-9358-41c9-923c-fb736d382a12"), - // Properties: &armpolicy.DefinitionProperties{ - // Description: to.Ptr("Audit DB level audit setting for SQL databases"), - // DisplayName: to.Ptr("Audit SQL DB Level Audit Setting"), - // Mode: to.Ptr("All"), - // Parameters: map[string]*armpolicy.ParameterDefinitionsValue{ - // "setting": &armpolicy.ParameterDefinitionsValue{ - // Type: to.Ptr(armpolicy.ParameterTypeString), - // AllowedValues: []any{ - // "enabled", - // "disabled"}, - // Metadata: &armpolicy.ParameterDefinitionsValueMetadata{ - // DisplayName: to.Ptr("Audit Setting"), - // }, - // }, - // }, - // PolicyRule: map[string]any{ - // "if":map[string]any{ - // "equals": "Microsoft.Sql/servers/databases", - // "field": "type", - // }, - // "then":map[string]any{ - // "effect": "AuditIfNotExists", - // "details":map[string]any{ - // "name": "default", - // "type": "Microsoft.Sql/servers/databases/auditingSettings", - // "existenceCondition":map[string]any{ - // "allOf":[]any{ - // map[string]any{ - // "equals": "[parameters('setting')]", - // "field": "Microsoft.Sql/auditingSettings.state", - // }, - // }, - // }, - // }, - // }, - // }, - // PolicyType: to.Ptr(armpolicy.PolicyTypeBuiltIn), - // }, - // }, - // { - // Name: to.Ptr("7433c107-6db4-4ad1-b57a-a76dce0154a1"), - // Type: to.Ptr("Microsoft.Authorization/policyDefinitions"), - // ID: to.Ptr("/providers/Microsoft.Authorization/policyDefinitions/7433c107-6db4-4ad1-b57a-a76dce0154a1"), - // Properties: &armpolicy.DefinitionProperties{ - // Description: to.Ptr("This policy enables you to specify a set of storage account SKUs that your organization can deploy."), - // DisplayName: to.Ptr("Allowed storage account SKUs"), - // Mode: to.Ptr("All"), - // Parameters: map[string]*armpolicy.ParameterDefinitionsValue{ - // "listOfAllowedSKUs": &armpolicy.ParameterDefinitionsValue{ - // Type: to.Ptr(armpolicy.ParameterTypeArray), - // Metadata: &armpolicy.ParameterDefinitionsValueMetadata{ - // Description: to.Ptr("The list of SKUs that can be specified for storage accounts."), - // DisplayName: to.Ptr("Allowed SKUs"), - // StrongType: to.Ptr("StorageSKUs"), - // }, - // }, - // }, - // PolicyRule: map[string]any{ - // "if":map[string]any{ - // "allOf":[]any{ - // map[string]any{ - // "equals": "Microsoft.Storage/storageAccounts", - // "field": "type", - // }, - // map[string]any{ - // "not":map[string]any{ - // "field": "Microsoft.Storage/storageAccounts/sku.name", - // "in": "[parameters('listOfAllowedSKUs')]", - // }, - // }, - // }, - // }, - // "then":map[string]any{ - // "effect": "Deny", - // }, - // }, - // PolicyType: to.Ptr(armpolicy.PolicyTypeStatic), - // }, - // }, - // { - // Name: to.Ptr("abeed54a-73c5-441d-8a8c-6b5e7a0c299e"), - // Type: to.Ptr("Microsoft.Authorization/policyDefinitions"), - // ID: to.Ptr("/providers/Microsoft.Authorization/policyDefinitions/abeed54a-73c5-441d-8a8c-6b5e7a0c299e"), - // Properties: &armpolicy.DefinitionProperties{ - // Description: to.Ptr("Audit certificates that are stored in Azure Key Vault, that expire within 'X' number of days."), - // DisplayName: to.Ptr("Audit KeyVault certificates that expire within specified number of days"), - // Metadata: map[string]any{ - // "category": "KeyVault DataPlane", - // }, - // Mode: to.Ptr("Microsoft.KeyVault.Data"), - // Parameters: map[string]*armpolicy.ParameterDefinitionsValue{ - // "daysToExpire": &armpolicy.ParameterDefinitionsValue{ - // Type: to.Ptr(armpolicy.ParameterTypeInteger), - // Metadata: &armpolicy.ParameterDefinitionsValueMetadata{ - // Description: to.Ptr("The number of days for a certificate to expire."), - // DisplayName: to.Ptr("Days to expire"), - // }, - // }, - // }, - // PolicyRule: map[string]any{ - // "if":map[string]any{ - // "field": "Microsoft.KeyVault.Data/vaults/certificates/attributes/expiresOn", - // "lessOrEquals": "[addDays(utcNow(), parameters('daysToExpire'))]", - // }, - // "then":map[string]any{ - // "effect": "audit", - // }, - // }, - // PolicyType: to.Ptr(armpolicy.PolicyTypeBuiltIn), - // }, - // }}, - // } - } -} - -// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/d55b8005f05b040b852c15e74a0f3e36494a15e1/specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/listPolicyDefinitionsByManagementGroup.json -func ExampleDefinitionsClient_NewListByManagementGroupPager() { - cred, err := azidentity.NewDefaultAzureCredential(nil) - if err != nil { - log.Fatalf("failed to obtain a credential: %v", err) - } - ctx := context.Background() - clientFactory, err := armpolicy.NewClientFactory("", cred, nil) - if err != nil { - log.Fatalf("failed to create client: %v", err) - } - pager := clientFactory.NewDefinitionsClient().NewListByManagementGroupPager("MyManagementGroup", &armpolicy.DefinitionsClientListByManagementGroupOptions{Filter: nil, - Top: nil, - }) - for pager.More() { - page, err := pager.NextPage(ctx) - if err != nil { - log.Fatalf("failed to advance page: %v", err) - } - for _, v := range page.Value { - // You could use page here. We use blank identifier for just demo purposes. - _ = v - } - // If the HTTP response code is 200 as defined in example definition, your page structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes. - // page.DefinitionListResult = armpolicy.DefinitionListResult{ - // Value: []*armpolicy.Definition{ - // { - // Name: to.Ptr("7433c107-6db4-4ad1-b57a-a76dce0154a1"), - // Type: to.Ptr("Microsoft.Authorization/policyDefinitions"), - // ID: to.Ptr("/providers/Microsoft.Authorization/policyDefinitions/7433c107-6db4-4ad1-b57a-a76dce0154a1"), - // Properties: &armpolicy.DefinitionProperties{ - // Description: to.Ptr("This policy enables you to specify a set of storage account SKUs that your organization can deploy."), - // DisplayName: to.Ptr("Allowed storage account SKUs"), - // Mode: to.Ptr("All"), - // Parameters: map[string]*armpolicy.ParameterDefinitionsValue{ - // "listOfAllowedSKUs": &armpolicy.ParameterDefinitionsValue{ - // Type: to.Ptr(armpolicy.ParameterTypeArray), - // Metadata: &armpolicy.ParameterDefinitionsValueMetadata{ - // Description: to.Ptr("The list of SKUs that can be specified for storage accounts."), - // DisplayName: to.Ptr("Allowed SKUs"), - // StrongType: to.Ptr("StorageSKUs"), - // }, - // }, - // }, - // PolicyRule: map[string]any{ - // "if":map[string]any{ - // "allOf":[]any{ - // map[string]any{ - // "equals": "Microsoft.Storage/storageAccounts", - // "field": "type", - // }, - // map[string]any{ - // "not":map[string]any{ - // "field": "Microsoft.Storage/storageAccounts/sku.name", - // "in": "[parameters('listOfAllowedSKUs')]", - // }, - // }, - // }, - // }, - // "then":map[string]any{ - // "effect": "Deny", - // }, - // }, - // PolicyType: to.Ptr(armpolicy.PolicyTypeBuiltIn), - // }, - // }, - // { - // Name: to.Ptr("ResourceNaming"), - // Type: to.Ptr("Microsoft.Authorization/policyDefinitions"), - // ID: to.Ptr("/providers/Microsoft.Management/managementgroups/MyManagementGroup/providers/Microsoft.Authorization/policyDefinitions/ResourceNaming"), - // Properties: &armpolicy.DefinitionProperties{ - // Description: to.Ptr("Force resource names to begin with 'prefix' and end with 'suffix'"), - // DisplayName: to.Ptr("Naming Convention"), - // Metadata: map[string]any{ - // "category": "Naming", - // }, - // Mode: to.Ptr("All"), - // Parameters: map[string]*armpolicy.ParameterDefinitionsValue{ - // "prefix": &armpolicy.ParameterDefinitionsValue{ - // Type: to.Ptr(armpolicy.ParameterTypeString), - // Metadata: &armpolicy.ParameterDefinitionsValueMetadata{ - // Description: to.Ptr("Resource name prefix"), - // DisplayName: to.Ptr("Prefix"), - // }, - // }, - // "suffix": &armpolicy.ParameterDefinitionsValue{ - // Type: to.Ptr(armpolicy.ParameterTypeString), - // Metadata: &armpolicy.ParameterDefinitionsValueMetadata{ - // Description: to.Ptr("Resource name suffix"), - // DisplayName: to.Ptr("Suffix"), - // }, - // }, - // }, - // PolicyRule: map[string]any{ - // "if":map[string]any{ - // "not":map[string]any{ - // "field": "name", - // "like": "[concat(parameters('prefix'), '*', parameters('suffix'))]", - // }, - // }, - // "then":map[string]any{ - // "effect": "deny", - // }, - // }, - // PolicyType: to.Ptr(armpolicy.PolicyTypeCustom), - // }, - // }}, - // } - } -} diff --git a/sdk/resourcemanager/resources/armpolicy/exemptions_client.go b/sdk/resourcemanager/resources/armpolicy/exemptions_client.go index 2570f46d050c..e45c1d9c102c 100644 --- a/sdk/resourcemanager/resources/armpolicy/exemptions_client.go +++ b/sdk/resourcemanager/resources/armpolicy/exemptions_client.go @@ -50,7 +50,7 @@ func NewExemptionsClient(subscriptionID string, credential azcore.TokenCredentia // resources in the resource group. // If the operation fails it returns an *azcore.ResponseError type. // -// Generated from API version 2020-07-01-preview +// Generated from API version 2022-07-01-preview // - scope - The scope of the policy exemption. Valid scopes are: management group (format: '/providers/Microsoft.Management/managementGroups/{managementGroup}'), // subscription (format: // '/subscriptions/{subscriptionId}'), resource group (format: '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}', @@ -88,7 +88,7 @@ func (client *ExemptionsClient) createOrUpdateCreateRequest(ctx context.Context, return nil, err } reqQP := req.Raw().URL.Query() - reqQP.Set("api-version", "2020-07-01-preview") + reqQP.Set("api-version", "2022-07-01-preview") req.Raw().URL.RawQuery = reqQP.Encode() req.Raw().Header["Accept"] = []string{"application/json"} return req, runtime.MarshalAsJSON(req, parameters) @@ -108,7 +108,7 @@ func (client *ExemptionsClient) createOrUpdateHandleResponse(resp *http.Response // '/providers/Microsoft.Authorization/policyExemptions/{policyExemptionName}'. // If the operation fails it returns an *azcore.ResponseError type. // -// Generated from API version 2020-07-01-preview +// Generated from API version 2022-07-01-preview // - scope - The scope of the policy exemption. Valid scopes are: management group (format: '/providers/Microsoft.Management/managementGroups/{managementGroup}'), // subscription (format: // '/subscriptions/{subscriptionId}'), resource group (format: '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}', @@ -144,7 +144,7 @@ func (client *ExemptionsClient) deleteCreateRequest(ctx context.Context, scope s return nil, err } reqQP := req.Raw().URL.Query() - reqQP.Set("api-version", "2020-07-01-preview") + reqQP.Set("api-version", "2022-07-01-preview") req.Raw().URL.RawQuery = reqQP.Encode() req.Raw().Header["Accept"] = []string{"application/json"} return req, nil @@ -153,7 +153,7 @@ func (client *ExemptionsClient) deleteCreateRequest(ctx context.Context, scope s // Get - This operation retrieves a single policy exemption, given its name and the scope it was created at. // If the operation fails it returns an *azcore.ResponseError type. // -// Generated from API version 2020-07-01-preview +// Generated from API version 2022-07-01-preview // - scope - The scope of the policy exemption. Valid scopes are: management group (format: '/providers/Microsoft.Management/managementGroups/{managementGroup}'), // subscription (format: // '/subscriptions/{subscriptionId}'), resource group (format: '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}', @@ -189,7 +189,7 @@ func (client *ExemptionsClient) getCreateRequest(ctx context.Context, scope stri return nil, err } reqQP := req.Raw().URL.Query() - reqQP.Set("api-version", "2020-07-01-preview") + reqQP.Set("api-version", "2022-07-01-preview") req.Raw().URL.RawQuery = reqQP.Encode() req.Raw().Header["Accept"] = []string{"application/json"} return req, nil @@ -211,7 +211,7 @@ func (client *ExemptionsClient) getHandleResponse(resp *http.Response) (Exemptio // directly or from management groups that contain the given subscription, as well as any applied to objects contained within // the subscription. // -// Generated from API version 2020-07-01-preview +// Generated from API version 2022-07-01-preview // - options - ExemptionsClientListOptions contains the optional parameters for the ExemptionsClient.NewListPager method. func (client *ExemptionsClient) NewListPager(options *ExemptionsClientListOptions) *runtime.Pager[ExemptionsClientListResponse] { return runtime.NewPager(runtime.PagingHandler[ExemptionsClientListResponse]{ @@ -253,7 +253,7 @@ func (client *ExemptionsClient) listCreateRequest(ctx context.Context, options * return nil, err } reqQP := req.Raw().URL.Query() - reqQP.Set("api-version", "2020-07-01-preview") + reqQP.Set("api-version", "2022-07-01-preview") req.Raw().URL.RawQuery = reqQP.Encode() unencodedParams := []string{req.Raw().URL.RawQuery} if options != nil && options.Filter != nil { @@ -279,7 +279,7 @@ func (client *ExemptionsClient) listHandleResponse(resp *http.Response) (Exempti // policy exemptions that are assigned to the management group or the management // group's ancestors. // -// Generated from API version 2020-07-01-preview +// Generated from API version 2022-07-01-preview // - managementGroupID - The ID of the management group. // - options - ExemptionsClientListForManagementGroupOptions contains the optional parameters for the ExemptionsClient.NewListForManagementGroupPager // method. @@ -323,7 +323,7 @@ func (client *ExemptionsClient) listForManagementGroupCreateRequest(ctx context. return nil, err } reqQP := req.Raw().URL.Query() - reqQP.Set("api-version", "2020-07-01-preview") + reqQP.Set("api-version", "2022-07-01-preview") req.Raw().URL.RawQuery = reqQP.Encode() unencodedParams := []string{req.Raw().URL.RawQuery} if options != nil && options.Filter != nil { @@ -360,7 +360,7 @@ func (client *ExemptionsClient) listForManagementGroupHandleResponse(resp *http. // both in the {resourceType} parameter, format: ({resourceProviderNamespace} == ”, {parentResourcePath} == ”, {resourceType} // == 'Microsoft.Web/sites', {resourceName} == 'MyWebApp'). // -// Generated from API version 2020-07-01-preview +// Generated from API version 2022-07-01-preview // - resourceGroupName - The name of the resource group containing the resource. // - resourceProviderNamespace - The namespace of the resource provider. For example, the namespace of a virtual machine is // Microsoft.Compute (from Microsoft.Compute/virtualMachines) @@ -423,7 +423,7 @@ func (client *ExemptionsClient) listForResourceCreateRequest(ctx context.Context return nil, err } reqQP := req.Raw().URL.Query() - reqQP.Set("api-version", "2020-07-01-preview") + reqQP.Set("api-version", "2022-07-01-preview") req.Raw().URL.RawQuery = reqQP.Encode() unencodedParams := []string{req.Raw().URL.RawQuery} if options != nil && options.Filter != nil { @@ -450,7 +450,7 @@ func (client *ExemptionsClient) listForResourceHandleResponse(resp *http.Respons // group, including those that apply directly or apply from containing scopes, as well as any applied to resources contained // within the resource group. // -// Generated from API version 2020-07-01-preview +// Generated from API version 2022-07-01-preview // - resourceGroupName - The name of the resource group containing the resource. // - options - ExemptionsClientListForResourceGroupOptions contains the optional parameters for the ExemptionsClient.NewListForResourceGroupPager // method. @@ -498,7 +498,7 @@ func (client *ExemptionsClient) listForResourceGroupCreateRequest(ctx context.Co return nil, err } reqQP := req.Raw().URL.Query() - reqQP.Set("api-version", "2020-07-01-preview") + reqQP.Set("api-version", "2022-07-01-preview") req.Raw().URL.RawQuery = reqQP.Encode() unencodedParams := []string{req.Raw().URL.RawQuery} if options != nil && options.Filter != nil { @@ -517,3 +517,58 @@ func (client *ExemptionsClient) listForResourceGroupHandleResponse(resp *http.Re } return result, nil } + +// Update - This operation updates a policy exemption with the given scope and name. +// If the operation fails it returns an *azcore.ResponseError type. +// +// Generated from API version 2022-07-01-preview +// - scope - The scope of the policy exemption. Valid scopes are: management group (format: '/providers/Microsoft.Management/managementGroups/{managementGroup}'), +// subscription (format: +// '/subscriptions/{subscriptionId}'), resource group (format: '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}', +// or resource (format: +// '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}' +// - policyExemptionName - The name of the policy exemption to delete. +// - parameters - Parameters for policy exemption patch request. +// - options - ExemptionsClientUpdateOptions contains the optional parameters for the ExemptionsClient.Update method. +func (client *ExemptionsClient) Update(ctx context.Context, scope string, policyExemptionName string, parameters ExemptionUpdate, options *ExemptionsClientUpdateOptions) (ExemptionsClientUpdateResponse, error) { + req, err := client.updateCreateRequest(ctx, scope, policyExemptionName, parameters, options) + if err != nil { + return ExemptionsClientUpdateResponse{}, err + } + resp, err := client.internal.Pipeline().Do(req) + if err != nil { + return ExemptionsClientUpdateResponse{}, err + } + if !runtime.HasStatusCode(resp, http.StatusOK) { + return ExemptionsClientUpdateResponse{}, runtime.NewResponseError(resp) + } + return client.updateHandleResponse(resp) +} + +// updateCreateRequest creates the Update request. +func (client *ExemptionsClient) updateCreateRequest(ctx context.Context, scope string, policyExemptionName string, parameters ExemptionUpdate, options *ExemptionsClientUpdateOptions) (*policy.Request, error) { + urlPath := "/{scope}/providers/Microsoft.Authorization/policyExemptions/{policyExemptionName}" + urlPath = strings.ReplaceAll(urlPath, "{scope}", scope) + if policyExemptionName == "" { + return nil, errors.New("parameter policyExemptionName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{policyExemptionName}", url.PathEscape(policyExemptionName)) + req, err := runtime.NewRequest(ctx, http.MethodPatch, runtime.JoinPaths(client.internal.Endpoint(), urlPath)) + if err != nil { + return nil, err + } + reqQP := req.Raw().URL.Query() + reqQP.Set("api-version", "2022-07-01-preview") + req.Raw().URL.RawQuery = reqQP.Encode() + req.Raw().Header["Accept"] = []string{"application/json"} + return req, runtime.MarshalAsJSON(req, parameters) +} + +// updateHandleResponse handles the Update response. +func (client *ExemptionsClient) updateHandleResponse(resp *http.Response) (ExemptionsClientUpdateResponse, error) { + result := ExemptionsClientUpdateResponse{} + if err := runtime.UnmarshalAsJSON(resp, &result.Exemption); err != nil { + return ExemptionsClientUpdateResponse{}, err + } + return result, nil +} diff --git a/sdk/resourcemanager/resources/armpolicy/exemptions_client_example_test.go b/sdk/resourcemanager/resources/armpolicy/exemptions_client_example_test.go deleted file mode 100644 index c1d89fb815b0..000000000000 --- a/sdk/resourcemanager/resources/armpolicy/exemptions_client_example_test.go +++ /dev/null @@ -1,432 +0,0 @@ -//go:build go1.18 -// +build go1.18 - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See License.txt in the project root for license information. -// Code generated by Microsoft (R) AutoRest Code Generator. -// Changes may cause incorrect behavior and will be lost if the code is regenerated. -// DO NOT EDIT. - -package armpolicy_test - -import ( - "context" - "log" - - "github.com/Azure/azure-sdk-for-go/sdk/azcore/to" - "github.com/Azure/azure-sdk-for-go/sdk/azidentity" - "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armpolicy" -) - -// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/d55b8005f05b040b852c15e74a0f3e36494a15e1/specification/resources/resource-manager/Microsoft.Authorization/preview/2020-07-01-preview/examples/deletePolicyExemption.json -func ExampleExemptionsClient_Delete() { - cred, err := azidentity.NewDefaultAzureCredential(nil) - if err != nil { - log.Fatalf("failed to obtain a credential: %v", err) - } - ctx := context.Background() - clientFactory, err := armpolicy.NewClientFactory("", cred, nil) - if err != nil { - log.Fatalf("failed to create client: %v", err) - } - _, err = clientFactory.NewExemptionsClient().Delete(ctx, "subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2/resourceGroups/demoCluster", "DemoExpensiveVM", nil) - if err != nil { - log.Fatalf("failed to finish the request: %v", err) - } -} - -// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/d55b8005f05b040b852c15e74a0f3e36494a15e1/specification/resources/resource-manager/Microsoft.Authorization/preview/2020-07-01-preview/examples/createOrUpdatePolicyExemption.json -func ExampleExemptionsClient_CreateOrUpdate() { - cred, err := azidentity.NewDefaultAzureCredential(nil) - if err != nil { - log.Fatalf("failed to obtain a credential: %v", err) - } - ctx := context.Background() - clientFactory, err := armpolicy.NewClientFactory("", cred, nil) - if err != nil { - log.Fatalf("failed to create client: %v", err) - } - res, err := clientFactory.NewExemptionsClient().CreateOrUpdate(ctx, "subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2/resourceGroups/demoCluster", "DemoExpensiveVM", armpolicy.Exemption{ - Properties: &armpolicy.ExemptionProperties{ - Description: to.Ptr("Exempt demo cluster from limit sku"), - DisplayName: to.Ptr("Exempt demo cluster"), - ExemptionCategory: to.Ptr(armpolicy.ExemptionCategoryWaiver), - Metadata: map[string]any{ - "reason": "Temporary exemption for a expensive VM demo", - }, - PolicyAssignmentID: to.Ptr("/subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2/providers/Microsoft.Authorization/policyAssignments/CostManagement"), - PolicyDefinitionReferenceIDs: []*string{ - to.Ptr("Limit_Skus")}, - }, - }, nil) - if err != nil { - log.Fatalf("failed to finish the request: %v", err) - } - // You could use response here. We use blank identifier for just demo purposes. - _ = res - // If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes. - // res.Exemption = armpolicy.Exemption{ - // Name: to.Ptr("DemoExpensiveVM"), - // Type: to.Ptr("Microsoft.Authorization/policyExemptions"), - // ID: to.Ptr("/subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2/resourceGroups/demoCluster/providers/Microsoft.Authorization/policyExemptions/DemoExpensiveVM"), - // Properties: &armpolicy.ExemptionProperties{ - // Description: to.Ptr("Exempt demo cluster from limit sku"), - // DisplayName: to.Ptr("Exempt demo cluster"), - // ExemptionCategory: to.Ptr(armpolicy.ExemptionCategoryWaiver), - // Metadata: map[string]any{ - // "reason": "Temporary exemption for a expensive VM demo", - // }, - // PolicyAssignmentID: to.Ptr("/subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2/providers/Microsoft.Authorization/policyAssignments/CostManagement"), - // PolicyDefinitionReferenceIDs: []*string{ - // to.Ptr("Limit_Skus")}, - // }, - // SystemData: &armpolicy.SystemData{ - // CreatedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-07-01T01:01:01.1075056Z"); return t}()), - // CreatedBy: to.Ptr("string"), - // CreatedByType: to.Ptr(armpolicy.CreatedByTypeUser), - // LastModifiedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-07-01T02:01:01.1075056Z"); return t}()), - // LastModifiedBy: to.Ptr("string"), - // LastModifiedByType: to.Ptr(armpolicy.CreatedByTypeUser), - // }, - // } -} - -// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/d55b8005f05b040b852c15e74a0f3e36494a15e1/specification/resources/resource-manager/Microsoft.Authorization/preview/2020-07-01-preview/examples/getPolicyExemption.json -func ExampleExemptionsClient_Get() { - cred, err := azidentity.NewDefaultAzureCredential(nil) - if err != nil { - log.Fatalf("failed to obtain a credential: %v", err) - } - ctx := context.Background() - clientFactory, err := armpolicy.NewClientFactory("", cred, nil) - if err != nil { - log.Fatalf("failed to create client: %v", err) - } - res, err := clientFactory.NewExemptionsClient().Get(ctx, "subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2/resourceGroups/demoCluster", "DemoExpensiveVM", nil) - if err != nil { - log.Fatalf("failed to finish the request: %v", err) - } - // You could use response here. We use blank identifier for just demo purposes. - _ = res - // If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes. - // res.Exemption = armpolicy.Exemption{ - // Name: to.Ptr("DemoExpensiveVM"), - // Type: to.Ptr("Microsoft.Authorization/policyExemptions"), - // ID: to.Ptr("/subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2/resourceGroups/demoCluster/providers/Microsoft.Authorization/policyExemptions/DemoExpensiveVM"), - // Properties: &armpolicy.ExemptionProperties{ - // Description: to.Ptr("Exempt demo cluster from limit sku"), - // DisplayName: to.Ptr("Exempt demo cluster"), - // ExemptionCategory: to.Ptr(armpolicy.ExemptionCategoryWaiver), - // Metadata: map[string]any{ - // "reason": "Temporary exemption for a expensive VM demo", - // }, - // PolicyAssignmentID: to.Ptr("/subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2/providers/Microsoft.Authorization/policyAssignments/CostManagement"), - // PolicyDefinitionReferenceIDs: []*string{ - // to.Ptr("Limit_Skus")}, - // }, - // SystemData: &armpolicy.SystemData{ - // CreatedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-07-01T01:01:01.1075056Z"); return t}()), - // CreatedBy: to.Ptr("string"), - // CreatedByType: to.Ptr(armpolicy.CreatedByTypeUser), - // LastModifiedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-07-01T02:01:01.1075056Z"); return t}()), - // LastModifiedBy: to.Ptr("string"), - // LastModifiedByType: to.Ptr(armpolicy.CreatedByTypeUser), - // }, - // } -} - -// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/d55b8005f05b040b852c15e74a0f3e36494a15e1/specification/resources/resource-manager/Microsoft.Authorization/preview/2020-07-01-preview/examples/listPolicyExemptionsForSubscription.json -func ExampleExemptionsClient_NewListPager() { - cred, err := azidentity.NewDefaultAzureCredential(nil) - if err != nil { - log.Fatalf("failed to obtain a credential: %v", err) - } - ctx := context.Background() - clientFactory, err := armpolicy.NewClientFactory("", cred, nil) - if err != nil { - log.Fatalf("failed to create client: %v", err) - } - pager := clientFactory.NewExemptionsClient().NewListPager(&armpolicy.ExemptionsClientListOptions{Filter: to.Ptr("atScope()")}) - for pager.More() { - page, err := pager.NextPage(ctx) - if err != nil { - log.Fatalf("failed to advance page: %v", err) - } - for _, v := range page.Value { - // You could use page here. We use blank identifier for just demo purposes. - _ = v - } - // If the HTTP response code is 200 as defined in example definition, your page structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes. - // page.ExemptionListResult = armpolicy.ExemptionListResult{ - // Value: []*armpolicy.Exemption{ - // { - // Name: to.Ptr("TestVMSub"), - // Type: to.Ptr("Microsoft.Authorization/policyExemptions"), - // ID: to.Ptr("/subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2/providers/Microsoft.Authorization/policyExemptions/TestVMSub"), - // Properties: &armpolicy.ExemptionProperties{ - // Description: to.Ptr("Exempt demo cluster from limit sku"), - // DisplayName: to.Ptr("Exempt demo cluster"), - // ExemptionCategory: to.Ptr(armpolicy.ExemptionCategoryWaiver), - // Metadata: map[string]any{ - // "reason": "Temporary exemption for a expensive VM demo", - // }, - // PolicyAssignmentID: to.Ptr("/providers/Microsoft.Management/managementGroups/DevOrg/providers/Microsoft.Authorization/policyAssignments/CostManagement"), - // PolicyDefinitionReferenceIDs: []*string{ - // to.Ptr("Limit_Skus")}, - // }, - // SystemData: &armpolicy.SystemData{ - // CreatedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-07-01T01:01:01.1075056Z"); return t}()), - // CreatedBy: to.Ptr("string"), - // CreatedByType: to.Ptr(armpolicy.CreatedByTypeUser), - // LastModifiedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-07-01T02:01:01.1075056Z"); return t}()), - // LastModifiedBy: to.Ptr("string"), - // LastModifiedByType: to.Ptr(armpolicy.CreatedByTypeUser), - // }, - // }, - // { - // Name: to.Ptr("TestVNetSub"), - // Type: to.Ptr("Microsoft.Authorization/policyExemptions"), - // ID: to.Ptr("/subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2/providers/Microsoft.Authorization/policyExemptions/TestVNetSub"), - // Properties: &armpolicy.ExemptionProperties{ - // Description: to.Ptr("Exempt jump box open ports from limit ports policy"), - // DisplayName: to.Ptr("Exempt jump box open ports"), - // ExemptionCategory: to.Ptr(armpolicy.ExemptionCategoryMitigated), - // Metadata: map[string]any{ - // "reason": "Need to open RDP port to corp net", - // }, - // PolicyAssignmentID: to.Ptr("/providers/Microsoft.Management/managementGroups/DevOrg/providers/Microsoft.Authorization/policyAssignments/LimitPorts"), - // }, - // SystemData: &armpolicy.SystemData{ - // CreatedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-07-01T01:01:01.1075056Z"); return t}()), - // CreatedBy: to.Ptr("string"), - // CreatedByType: to.Ptr(armpolicy.CreatedByTypeUser), - // LastModifiedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-07-01T02:01:01.1075056Z"); return t}()), - // LastModifiedBy: to.Ptr("string"), - // LastModifiedByType: to.Ptr(armpolicy.CreatedByTypeUser), - // }, - // }}, - // } - } -} - -// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/d55b8005f05b040b852c15e74a0f3e36494a15e1/specification/resources/resource-manager/Microsoft.Authorization/preview/2020-07-01-preview/examples/listPolicyExemptionsForResourceGroup.json -func ExampleExemptionsClient_NewListForResourceGroupPager() { - cred, err := azidentity.NewDefaultAzureCredential(nil) - if err != nil { - log.Fatalf("failed to obtain a credential: %v", err) - } - ctx := context.Background() - clientFactory, err := armpolicy.NewClientFactory("", cred, nil) - if err != nil { - log.Fatalf("failed to create client: %v", err) - } - pager := clientFactory.NewExemptionsClient().NewListForResourceGroupPager("TestResourceGroup", &armpolicy.ExemptionsClientListForResourceGroupOptions{Filter: to.Ptr("atScope()")}) - for pager.More() { - page, err := pager.NextPage(ctx) - if err != nil { - log.Fatalf("failed to advance page: %v", err) - } - for _, v := range page.Value { - // You could use page here. We use blank identifier for just demo purposes. - _ = v - } - // If the HTTP response code is 200 as defined in example definition, your page structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes. - // page.ExemptionListResult = armpolicy.ExemptionListResult{ - // Value: []*armpolicy.Exemption{ - // { - // Name: to.Ptr("TestVMSub"), - // Type: to.Ptr("Microsoft.Authorization/policyExemptions"), - // ID: to.Ptr("/subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2/providers/Microsoft.Authorization/policyExemptions/TestVMSub"), - // Properties: &armpolicy.ExemptionProperties{ - // Description: to.Ptr("Exempt demo cluster from limit sku"), - // DisplayName: to.Ptr("Exempt demo cluster"), - // ExemptionCategory: to.Ptr(armpolicy.ExemptionCategoryWaiver), - // Metadata: map[string]any{ - // "reason": "Temporary exemption for a expensive VM demo", - // }, - // PolicyAssignmentID: to.Ptr("/providers/Microsoft.Management/managementGroups/DevOrg/providers/Microsoft.Authorization/policyAssignments/CostManagement"), - // PolicyDefinitionReferenceIDs: []*string{ - // to.Ptr("Limit_Skus")}, - // }, - // SystemData: &armpolicy.SystemData{ - // CreatedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-07-01T01:01:01.1075056Z"); return t}()), - // CreatedBy: to.Ptr("string"), - // CreatedByType: to.Ptr(armpolicy.CreatedByTypeUser), - // LastModifiedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-07-01T02:01:01.1075056Z"); return t}()), - // LastModifiedBy: to.Ptr("string"), - // LastModifiedByType: to.Ptr(armpolicy.CreatedByTypeUser), - // }, - // }, - // { - // Name: to.Ptr("TestVNetRG"), - // Type: to.Ptr("Microsoft.Authorization/policyExemptions"), - // ID: to.Ptr("/subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2/resourceGroups/TestResourceGroup/providers/Microsoft.Authorization/policyExemptions/TestVNetRG"), - // Properties: &armpolicy.ExemptionProperties{ - // Description: to.Ptr("Exempt jump box open ports from limit ports policy"), - // DisplayName: to.Ptr("Exempt jump box open ports"), - // ExemptionCategory: to.Ptr(armpolicy.ExemptionCategoryMitigated), - // Metadata: map[string]any{ - // "reason": "Need to open RDP port to corp net", - // }, - // PolicyAssignmentID: to.Ptr("/providers/Microsoft.Management/managementGroups/DevOrg/providers/Microsoft.Authorization/policyAssignments/LimitPorts"), - // }, - // SystemData: &armpolicy.SystemData{ - // CreatedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-07-01T01:01:01.1075056Z"); return t}()), - // CreatedBy: to.Ptr("string"), - // CreatedByType: to.Ptr(armpolicy.CreatedByTypeUser), - // LastModifiedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-07-01T02:01:01.1075056Z"); return t}()), - // LastModifiedBy: to.Ptr("string"), - // LastModifiedByType: to.Ptr(armpolicy.CreatedByTypeUser), - // }, - // }}, - // } - } -} - -// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/d55b8005f05b040b852c15e74a0f3e36494a15e1/specification/resources/resource-manager/Microsoft.Authorization/preview/2020-07-01-preview/examples/listPolicyExemptionsForResource.json -func ExampleExemptionsClient_NewListForResourcePager() { - cred, err := azidentity.NewDefaultAzureCredential(nil) - if err != nil { - log.Fatalf("failed to obtain a credential: %v", err) - } - ctx := context.Background() - clientFactory, err := armpolicy.NewClientFactory("", cred, nil) - if err != nil { - log.Fatalf("failed to create client: %v", err) - } - pager := clientFactory.NewExemptionsClient().NewListForResourcePager("TestResourceGroup", "Microsoft.Compute", "virtualMachines/MyTestVm", "domainNames", "MyTestComputer.cloudapp.net", &armpolicy.ExemptionsClientListForResourceOptions{Filter: nil}) - for pager.More() { - page, err := pager.NextPage(ctx) - if err != nil { - log.Fatalf("failed to advance page: %v", err) - } - for _, v := range page.Value { - // You could use page here. We use blank identifier for just demo purposes. - _ = v - } - // If the HTTP response code is 200 as defined in example definition, your page structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes. - // page.ExemptionListResult = armpolicy.ExemptionListResult{ - // Value: []*armpolicy.Exemption{ - // { - // Name: to.Ptr("DemoExpensiveVMGroup"), - // Type: to.Ptr("Microsoft.Authorization/policyExemptions"), - // ID: to.Ptr("/subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2/resourceGroups/TestResourceGroup/providers/Microsoft.Authorization/policyExemptions/DemoExpensiveVMGroup"), - // Properties: &armpolicy.ExemptionProperties{ - // Description: to.Ptr("Exempt demo cluster from limit sku"), - // DisplayName: to.Ptr("Exempt demo cluster"), - // ExemptionCategory: to.Ptr(armpolicy.ExemptionCategoryWaiver), - // Metadata: map[string]any{ - // "reason": "Temporary exemption for a expensive VM demo", - // }, - // PolicyAssignmentID: to.Ptr("/subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2/providers/Microsoft.Authorization/policyAssignments/CostManagement"), - // PolicyDefinitionReferenceIDs: []*string{ - // to.Ptr("Limit_Skus")}, - // }, - // SystemData: &armpolicy.SystemData{ - // CreatedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-07-01T01:01:01.1075056Z"); return t}()), - // CreatedBy: to.Ptr("string"), - // CreatedByType: to.Ptr(armpolicy.CreatedByTypeUser), - // LastModifiedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-07-01T02:01:01.1075056Z"); return t}()), - // LastModifiedBy: to.Ptr("string"), - // LastModifiedByType: to.Ptr(armpolicy.CreatedByTypeUser), - // }, - // }, - // { - // Name: to.Ptr("jumpBoxExemption"), - // Type: to.Ptr("Microsoft.Authorization/policyExemptions"), - // ID: to.Ptr("/subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2/resourceGroups/TestResourceGroup/providers/Microsoft.Compute/virtualMachines/MyTestVm/providers/Microsoft.Authorization/policyExemptions/jumpBoxExemption"), - // Properties: &armpolicy.ExemptionProperties{ - // Description: to.Ptr("Exempt jump box open ports from limit ports policy"), - // DisplayName: to.Ptr("Exempt jump box open ports"), - // ExemptionCategory: to.Ptr(armpolicy.ExemptionCategoryMitigated), - // Metadata: map[string]any{ - // "reason": "Need to open RDP port to corp net", - // }, - // PolicyAssignmentID: to.Ptr("/subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2/providers/Microsoft.Authorization/policyAssignments/LimitPorts"), - // }, - // SystemData: &armpolicy.SystemData{ - // CreatedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-07-01T01:01:01.1075056Z"); return t}()), - // CreatedBy: to.Ptr("string"), - // CreatedByType: to.Ptr(armpolicy.CreatedByTypeUser), - // LastModifiedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-07-01T02:01:01.1075056Z"); return t}()), - // LastModifiedBy: to.Ptr("string"), - // LastModifiedByType: to.Ptr(armpolicy.CreatedByTypeUser), - // }, - // }}, - // } - } -} - -// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/d55b8005f05b040b852c15e74a0f3e36494a15e1/specification/resources/resource-manager/Microsoft.Authorization/preview/2020-07-01-preview/examples/listPolicyExemptionsForManagementGroup.json -func ExampleExemptionsClient_NewListForManagementGroupPager() { - cred, err := azidentity.NewDefaultAzureCredential(nil) - if err != nil { - log.Fatalf("failed to obtain a credential: %v", err) - } - ctx := context.Background() - clientFactory, err := armpolicy.NewClientFactory("", cred, nil) - if err != nil { - log.Fatalf("failed to create client: %v", err) - } - pager := clientFactory.NewExemptionsClient().NewListForManagementGroupPager("DevOrg", &armpolicy.ExemptionsClientListForManagementGroupOptions{Filter: to.Ptr("atScope()")}) - for pager.More() { - page, err := pager.NextPage(ctx) - if err != nil { - log.Fatalf("failed to advance page: %v", err) - } - for _, v := range page.Value { - // You could use page here. We use blank identifier for just demo purposes. - _ = v - } - // If the HTTP response code is 200 as defined in example definition, your page structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes. - // page.ExemptionListResult = armpolicy.ExemptionListResult{ - // Value: []*armpolicy.Exemption{ - // { - // Name: to.Ptr("ResearchBudgetExemption"), - // Type: to.Ptr("Microsoft.Authorization/policyExemptions"), - // ID: to.Ptr("/providers/Microsoft.Management/managementGroups/DevOrg/providers/Microsoft.Authorization/policyExemptions/ResearchBudgetExemption"), - // Properties: &armpolicy.ExemptionProperties{ - // Description: to.Ptr("Exempt demo cluster from limit sku"), - // DisplayName: to.Ptr("Exempt demo cluster"), - // ExemptionCategory: to.Ptr(armpolicy.ExemptionCategoryWaiver), - // Metadata: map[string]any{ - // "reason": "Temporary exemption for a expensive VM demo", - // }, - // PolicyAssignmentID: to.Ptr("/providers/Microsoft.Management/managementGroups/HardwareDivision/providers/Microsoft.Authorization/policyAssignments/CostManagement"), - // PolicyDefinitionReferenceIDs: []*string{ - // to.Ptr("Limit_Skus")}, - // }, - // SystemData: &armpolicy.SystemData{ - // CreatedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-07-01T01:01:01.1075056Z"); return t}()), - // CreatedBy: to.Ptr("string"), - // CreatedByType: to.Ptr(armpolicy.CreatedByTypeUser), - // LastModifiedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-07-01T02:01:01.1075056Z"); return t}()), - // LastModifiedBy: to.Ptr("string"), - // LastModifiedByType: to.Ptr(armpolicy.CreatedByTypeUser), - // }, - // }, - // { - // Name: to.Ptr("VNetIsMonitored"), - // Type: to.Ptr("Microsoft.Authorization/policyExemptions"), - // ID: to.Ptr("/providers/Microsoft.Management/managementGroups/DevOrg/providers/Microsoft.Authorization/policyExemptions/VNetIsMonitored"), - // Properties: &armpolicy.ExemptionProperties{ - // Description: to.Ptr("Exempt jump box open ports from limit ports policy"), - // DisplayName: to.Ptr("Exempt jump box open ports"), - // ExemptionCategory: to.Ptr(armpolicy.ExemptionCategoryMitigated), - // Metadata: map[string]any{ - // "reason": "Need to open RDP port to corp net", - // }, - // PolicyAssignmentID: to.Ptr("/providers/Microsoft.Management/managementGroups/HardwareDivision/providers/Microsoft.Authorization/policyAssignments/LimitPorts"), - // }, - // SystemData: &armpolicy.SystemData{ - // CreatedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-07-01T01:01:01.1075056Z"); return t}()), - // CreatedBy: to.Ptr("string"), - // CreatedByType: to.Ptr(armpolicy.CreatedByTypeUser), - // LastModifiedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-07-01T02:01:01.1075056Z"); return t}()), - // LastModifiedBy: to.Ptr("string"), - // LastModifiedByType: to.Ptr(armpolicy.CreatedByTypeUser), - // }, - // }}, - // } - } -} diff --git a/sdk/resourcemanager/resources/armpolicy/go.mod b/sdk/resourcemanager/resources/armpolicy/go.mod index 2c8a1271c0ee..efe8ab44dc98 100644 --- a/sdk/resourcemanager/resources/armpolicy/go.mod +++ b/sdk/resourcemanager/resources/armpolicy/go.mod @@ -4,12 +4,12 @@ go 1.18 require ( github.com/Azure/azure-sdk-for-go/sdk/azcore v1.4.0 - github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.2.0 github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/internal v1.1.2 github.com/stretchr/testify v1.7.0 ) require ( + github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.2.0 // indirect github.com/Azure/azure-sdk-for-go/sdk/internal v1.2.0 // indirect github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armresources v1.0.0 // indirect github.com/AzureAD/microsoft-authentication-library-for-go v0.7.0 // indirect diff --git a/sdk/resourcemanager/resources/armpolicy/models.go b/sdk/resourcemanager/resources/armpolicy/models.go index 4521305f6c63..6dfeb4a1d08b 100644 --- a/sdk/resourcemanager/resources/armpolicy/models.go +++ b/sdk/resourcemanager/resources/armpolicy/models.go @@ -120,22 +120,41 @@ type AssignmentProperties struct { // The policy's excluded scopes. NotScopes []*string + // The policy property value override. + Overrides []*Override + // The parameter values for the assigned policy rule. The keys are the parameter names. Parameters map[string]*ParameterValuesValue // The ID of the policy definition or policy set definition being assigned. PolicyDefinitionID *string + // The resource selector list to filter policies by resource properties. + ResourceSelectors []*ResourceSelector + // READ-ONLY; The scope for the policy assignment. Scope *string } +// AssignmentUpdate - The policy assignment for Patch request. type AssignmentUpdate struct { // The managed identity associated with the policy assignment. Identity *Identity // The location of the policy assignment. Only required when utilizing managed identity. Location *string + + // The policy assignment properties for Patch request. + Properties *AssignmentUpdateProperties +} + +// AssignmentUpdateProperties - The policy assignment properties for Patch request. +type AssignmentUpdateProperties struct { + // The policy property value override. + Overrides []*Override + + // The resource selector list to filter policies by resource properties. + ResourceSelectors []*ResourceSelector } // AssignmentsClientCreateByIDOptions contains the optional parameters for the AssignmentsClient.CreateByID method. @@ -562,6 +581,9 @@ type ExemptionProperties struct { // REQUIRED; The ID of the policy assignment that is being exempted. PolicyAssignmentID *string + // The option whether validate the exemption is at or under the assignment scope. + AssignmentScopeValidation *AssignmentScopeValidation + // The description of the policy exemption. Description *string @@ -576,6 +598,24 @@ type ExemptionProperties struct { // The policy definition reference ID list when the associated policy assignment is an assignment of a policy set definition. PolicyDefinitionReferenceIDs []*string + + // The resource selector list to filter policies by resource properties. + ResourceSelectors []*ResourceSelector +} + +// ExemptionUpdate - The policy exemption for Patch request. +type ExemptionUpdate struct { + // The policy exemption properties for Patch request. + Properties *ExemptionUpdateProperties +} + +// ExemptionUpdateProperties - The policy exemption properties for Patch request. +type ExemptionUpdateProperties struct { + // The option whether validate the exemption is at or under the assignment scope. + AssignmentScopeValidation *AssignmentScopeValidation + + // The resource selector list to filter policies by resource properties. + ResourceSelectors []*ResourceSelector } // ExemptionsClientCreateOrUpdateOptions contains the optional parameters for the ExemptionsClient.CreateOrUpdate method. @@ -660,6 +700,11 @@ type ExemptionsClientListOptions struct { Filter *string } +// ExemptionsClientUpdateOptions contains the optional parameters for the ExemptionsClient.Update method. +type ExemptionsClientUpdateOptions struct { + // placeholder for future optional parameters +} + // Identity for the resource. Policy assignments support a maximum of one identity. That is either a system assigned identity // or a single user assigned identity. type Identity struct { @@ -691,6 +736,18 @@ type NonComplianceMessage struct { PolicyDefinitionReferenceID *string } +// Override - The policy property value override. +type Override struct { + // The override kind. + Kind *OverrideKind + + // The list of the selector expressions. + Selectors []*Selector + + // The value to override the policy property. + Value *string +} + // ParameterDefinitionsValue - The definition of a parameter that can be provided to the policy. type ParameterDefinitionsValue struct { // The allowed values for the parameter. @@ -733,6 +790,15 @@ type ParameterValuesValue struct { Value any } +// ResourceSelector - The resource selector to filter policies by resource properties. +type ResourceSelector struct { + // The name of the resource selector. + Name *string + + // The list of the selector expressions. + Selectors []*Selector +} + // ResourceTypeAliases - The resource type aliases definition. type ResourceTypeAliases struct { // The aliases for property names. @@ -742,6 +808,18 @@ type ResourceTypeAliases struct { ResourceType *string } +// Selector - The selector expression. +type Selector struct { + // The list of values to filter in. + In []*string + + // The selector kind. + Kind *SelectorKind + + // The list of values to filter out. + NotIn []*string +} + // SetDefinition - The policy set definition. type SetDefinition struct { // The policy definition properties. @@ -904,3 +982,173 @@ type UserAssignedIdentitiesValue struct { // READ-ONLY; The principal id of user assigned identity. PrincipalID *string } + +// Variable - The variable. +type Variable struct { + // REQUIRED; Properties for the variable. + Properties *VariableProperties + + // READ-ONLY; The ID of the variable. + ID *string + + // READ-ONLY; The name of the variable. + Name *string + + // READ-ONLY; Azure Resource Manager metadata containing createdBy and modifiedBy information. + SystemData *SystemData + + // READ-ONLY; The type of the resource (Microsoft.Authorization/variables). + Type *string +} + +// VariableColumn - The variable column. +type VariableColumn struct { + // REQUIRED; The name of this policy variable column. + ColumnName *string +} + +// VariableListResult - List of variables. +type VariableListResult struct { + // An array of variables. + Value []*Variable + + // READ-ONLY; The URL to use for getting the next set of results. + NextLink *string +} + +// VariableProperties - The variable properties. +type VariableProperties struct { + // REQUIRED; Variable column definitions. + Columns []*VariableColumn +} + +// VariableValue - The variable value. +type VariableValue struct { + // REQUIRED; Properties for the variable value. + Properties *VariableValueProperties + + // READ-ONLY; The ID of the variable. + ID *string + + // READ-ONLY; The name of the variable. + Name *string + + // READ-ONLY; Azure Resource Manager metadata containing createdBy and modifiedBy information. + SystemData *SystemData + + // READ-ONLY; The type of the resource (Microsoft.Authorization/variables/values). + Type *string +} + +// VariableValueColumnValue - The name value tuple for this variable value column. +type VariableValueColumnValue struct { + // REQUIRED; Column name for the variable value + ColumnName *string + + // REQUIRED; Column value for the variable value; this can be an integer, double, boolean, null or a string. + ColumnValue any +} + +// VariableValueListResult - List of variable values. +type VariableValueListResult struct { + // An array of variable values. + Value []*VariableValue + + // READ-ONLY; The URL to use for getting the next set of results. + NextLink *string +} + +// VariableValueProperties - The variable value properties. +type VariableValueProperties struct { + // REQUIRED; Variable value column value array. + Values []*VariableValueColumnValue +} + +// VariableValuesClientCreateOrUpdateAtManagementGroupOptions contains the optional parameters for the VariableValuesClient.CreateOrUpdateAtManagementGroup +// method. +type VariableValuesClientCreateOrUpdateAtManagementGroupOptions struct { + // placeholder for future optional parameters +} + +// VariableValuesClientCreateOrUpdateOptions contains the optional parameters for the VariableValuesClient.CreateOrUpdate +// method. +type VariableValuesClientCreateOrUpdateOptions struct { + // placeholder for future optional parameters +} + +// VariableValuesClientDeleteAtManagementGroupOptions contains the optional parameters for the VariableValuesClient.DeleteAtManagementGroup +// method. +type VariableValuesClientDeleteAtManagementGroupOptions struct { + // placeholder for future optional parameters +} + +// VariableValuesClientDeleteOptions contains the optional parameters for the VariableValuesClient.Delete method. +type VariableValuesClientDeleteOptions struct { + // placeholder for future optional parameters +} + +// VariableValuesClientGetAtManagementGroupOptions contains the optional parameters for the VariableValuesClient.GetAtManagementGroup +// method. +type VariableValuesClientGetAtManagementGroupOptions struct { + // placeholder for future optional parameters +} + +// VariableValuesClientGetOptions contains the optional parameters for the VariableValuesClient.Get method. +type VariableValuesClientGetOptions struct { + // placeholder for future optional parameters +} + +// VariableValuesClientListForManagementGroupOptions contains the optional parameters for the VariableValuesClient.NewListForManagementGroupPager +// method. +type VariableValuesClientListForManagementGroupOptions struct { + // placeholder for future optional parameters +} + +// VariableValuesClientListOptions contains the optional parameters for the VariableValuesClient.NewListPager method. +type VariableValuesClientListOptions struct { + // placeholder for future optional parameters +} + +// VariablesClientCreateOrUpdateAtManagementGroupOptions contains the optional parameters for the VariablesClient.CreateOrUpdateAtManagementGroup +// method. +type VariablesClientCreateOrUpdateAtManagementGroupOptions struct { + // placeholder for future optional parameters +} + +// VariablesClientCreateOrUpdateOptions contains the optional parameters for the VariablesClient.CreateOrUpdate method. +type VariablesClientCreateOrUpdateOptions struct { + // placeholder for future optional parameters +} + +// VariablesClientDeleteAtManagementGroupOptions contains the optional parameters for the VariablesClient.DeleteAtManagementGroup +// method. +type VariablesClientDeleteAtManagementGroupOptions struct { + // placeholder for future optional parameters +} + +// VariablesClientDeleteOptions contains the optional parameters for the VariablesClient.Delete method. +type VariablesClientDeleteOptions struct { + // placeholder for future optional parameters +} + +// VariablesClientGetAtManagementGroupOptions contains the optional parameters for the VariablesClient.GetAtManagementGroup +// method. +type VariablesClientGetAtManagementGroupOptions struct { + // placeholder for future optional parameters +} + +// VariablesClientGetOptions contains the optional parameters for the VariablesClient.Get method. +type VariablesClientGetOptions struct { + // placeholder for future optional parameters +} + +// VariablesClientListForManagementGroupOptions contains the optional parameters for the VariablesClient.NewListForManagementGroupPager +// method. +type VariablesClientListForManagementGroupOptions struct { + // placeholder for future optional parameters +} + +// VariablesClientListOptions contains the optional parameters for the VariablesClient.NewListPager method. +type VariablesClientListOptions struct { + // placeholder for future optional parameters +} diff --git a/sdk/resourcemanager/resources/armpolicy/models_serde.go b/sdk/resourcemanager/resources/armpolicy/models_serde.go index bd17767cc57a..2015c35a92bd 100644 --- a/sdk/resourcemanager/resources/armpolicy/models_serde.go +++ b/sdk/resourcemanager/resources/armpolicy/models_serde.go @@ -259,8 +259,10 @@ func (a AssignmentProperties) MarshalJSON() ([]byte, error) { populateAny(objectMap, "metadata", a.Metadata) populate(objectMap, "nonComplianceMessages", a.NonComplianceMessages) populate(objectMap, "notScopes", a.NotScopes) + populate(objectMap, "overrides", a.Overrides) populate(objectMap, "parameters", a.Parameters) populate(objectMap, "policyDefinitionId", a.PolicyDefinitionID) + populate(objectMap, "resourceSelectors", a.ResourceSelectors) populate(objectMap, "scope", a.Scope) return json.Marshal(objectMap) } @@ -292,12 +294,18 @@ func (a *AssignmentProperties) UnmarshalJSON(data []byte) error { case "notScopes": err = unpopulate(val, "NotScopes", &a.NotScopes) delete(rawMsg, key) + case "overrides": + err = unpopulate(val, "Overrides", &a.Overrides) + delete(rawMsg, key) case "parameters": err = unpopulate(val, "Parameters", &a.Parameters) delete(rawMsg, key) case "policyDefinitionId": err = unpopulate(val, "PolicyDefinitionID", &a.PolicyDefinitionID) delete(rawMsg, key) + case "resourceSelectors": + err = unpopulate(val, "ResourceSelectors", &a.ResourceSelectors) + delete(rawMsg, key) case "scope": err = unpopulate(val, "Scope", &a.Scope) delete(rawMsg, key) @@ -314,6 +322,7 @@ func (a AssignmentUpdate) MarshalJSON() ([]byte, error) { objectMap := make(map[string]any) populate(objectMap, "identity", a.Identity) populate(objectMap, "location", a.Location) + populate(objectMap, "properties", a.Properties) return json.Marshal(objectMap) } @@ -332,6 +341,40 @@ func (a *AssignmentUpdate) UnmarshalJSON(data []byte) error { case "location": err = unpopulate(val, "Location", &a.Location) delete(rawMsg, key) + case "properties": + err = unpopulate(val, "Properties", &a.Properties) + delete(rawMsg, key) + } + if err != nil { + return fmt.Errorf("unmarshalling type %T: %v", a, err) + } + } + return nil +} + +// MarshalJSON implements the json.Marshaller interface for type AssignmentUpdateProperties. +func (a AssignmentUpdateProperties) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]any) + populate(objectMap, "overrides", a.Overrides) + populate(objectMap, "resourceSelectors", a.ResourceSelectors) + return json.Marshal(objectMap) +} + +// UnmarshalJSON implements the json.Unmarshaller interface for type AssignmentUpdateProperties. +func (a *AssignmentUpdateProperties) UnmarshalJSON(data []byte) error { + var rawMsg map[string]json.RawMessage + if err := json.Unmarshal(data, &rawMsg); err != nil { + return fmt.Errorf("unmarshalling type %T: %v", a, err) + } + for key, val := range rawMsg { + var err error + switch key { + case "overrides": + err = unpopulate(val, "Overrides", &a.Overrides) + delete(rawMsg, key) + case "resourceSelectors": + err = unpopulate(val, "ResourceSelectors", &a.ResourceSelectors) + delete(rawMsg, key) } if err != nil { return fmt.Errorf("unmarshalling type %T: %v", a, err) @@ -920,6 +963,7 @@ func (e *ExemptionListResult) UnmarshalJSON(data []byte) error { // MarshalJSON implements the json.Marshaller interface for type ExemptionProperties. func (e ExemptionProperties) MarshalJSON() ([]byte, error) { objectMap := make(map[string]any) + populate(objectMap, "assignmentScopeValidation", e.AssignmentScopeValidation) populate(objectMap, "description", e.Description) populate(objectMap, "displayName", e.DisplayName) populate(objectMap, "exemptionCategory", e.ExemptionCategory) @@ -927,6 +971,7 @@ func (e ExemptionProperties) MarshalJSON() ([]byte, error) { populateAny(objectMap, "metadata", e.Metadata) populate(objectMap, "policyAssignmentId", e.PolicyAssignmentID) populate(objectMap, "policyDefinitionReferenceIds", e.PolicyDefinitionReferenceIDs) + populate(objectMap, "resourceSelectors", e.ResourceSelectors) return json.Marshal(objectMap) } @@ -939,6 +984,9 @@ func (e *ExemptionProperties) UnmarshalJSON(data []byte) error { for key, val := range rawMsg { var err error switch key { + case "assignmentScopeValidation": + err = unpopulate(val, "AssignmentScopeValidation", &e.AssignmentScopeValidation) + delete(rawMsg, key) case "description": err = unpopulate(val, "Description", &e.Description) delete(rawMsg, key) @@ -960,6 +1008,67 @@ func (e *ExemptionProperties) UnmarshalJSON(data []byte) error { case "policyDefinitionReferenceIds": err = unpopulate(val, "PolicyDefinitionReferenceIDs", &e.PolicyDefinitionReferenceIDs) delete(rawMsg, key) + case "resourceSelectors": + err = unpopulate(val, "ResourceSelectors", &e.ResourceSelectors) + delete(rawMsg, key) + } + if err != nil { + return fmt.Errorf("unmarshalling type %T: %v", e, err) + } + } + return nil +} + +// MarshalJSON implements the json.Marshaller interface for type ExemptionUpdate. +func (e ExemptionUpdate) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]any) + populate(objectMap, "properties", e.Properties) + return json.Marshal(objectMap) +} + +// UnmarshalJSON implements the json.Unmarshaller interface for type ExemptionUpdate. +func (e *ExemptionUpdate) UnmarshalJSON(data []byte) error { + var rawMsg map[string]json.RawMessage + if err := json.Unmarshal(data, &rawMsg); err != nil { + return fmt.Errorf("unmarshalling type %T: %v", e, err) + } + for key, val := range rawMsg { + var err error + switch key { + case "properties": + err = unpopulate(val, "Properties", &e.Properties) + delete(rawMsg, key) + } + if err != nil { + return fmt.Errorf("unmarshalling type %T: %v", e, err) + } + } + return nil +} + +// MarshalJSON implements the json.Marshaller interface for type ExemptionUpdateProperties. +func (e ExemptionUpdateProperties) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]any) + populate(objectMap, "assignmentScopeValidation", e.AssignmentScopeValidation) + populate(objectMap, "resourceSelectors", e.ResourceSelectors) + return json.Marshal(objectMap) +} + +// UnmarshalJSON implements the json.Unmarshaller interface for type ExemptionUpdateProperties. +func (e *ExemptionUpdateProperties) UnmarshalJSON(data []byte) error { + var rawMsg map[string]json.RawMessage + if err := json.Unmarshal(data, &rawMsg); err != nil { + return fmt.Errorf("unmarshalling type %T: %v", e, err) + } + for key, val := range rawMsg { + var err error + switch key { + case "assignmentScopeValidation": + err = unpopulate(val, "AssignmentScopeValidation", &e.AssignmentScopeValidation) + delete(rawMsg, key) + case "resourceSelectors": + err = unpopulate(val, "ResourceSelectors", &e.ResourceSelectors) + delete(rawMsg, key) } if err != nil { return fmt.Errorf("unmarshalling type %T: %v", e, err) @@ -1038,6 +1147,41 @@ func (n *NonComplianceMessage) UnmarshalJSON(data []byte) error { return nil } +// MarshalJSON implements the json.Marshaller interface for type Override. +func (o Override) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]any) + populate(objectMap, "kind", o.Kind) + populate(objectMap, "selectors", o.Selectors) + populate(objectMap, "value", o.Value) + return json.Marshal(objectMap) +} + +// UnmarshalJSON implements the json.Unmarshaller interface for type Override. +func (o *Override) UnmarshalJSON(data []byte) error { + var rawMsg map[string]json.RawMessage + if err := json.Unmarshal(data, &rawMsg); err != nil { + return fmt.Errorf("unmarshalling type %T: %v", o, err) + } + for key, val := range rawMsg { + var err error + switch key { + case "kind": + err = unpopulate(val, "Kind", &o.Kind) + delete(rawMsg, key) + case "selectors": + err = unpopulate(val, "Selectors", &o.Selectors) + delete(rawMsg, key) + case "value": + err = unpopulate(val, "Value", &o.Value) + delete(rawMsg, key) + } + if err != nil { + return fmt.Errorf("unmarshalling type %T: %v", o, err) + } + } + return nil +} + // MarshalJSON implements the json.Marshaller interface for type ParameterDefinitionsValue. func (p ParameterDefinitionsValue) MarshalJSON() ([]byte, error) { objectMap := make(map[string]any) @@ -1158,6 +1302,37 @@ func (p *ParameterValuesValue) UnmarshalJSON(data []byte) error { return nil } +// MarshalJSON implements the json.Marshaller interface for type ResourceSelector. +func (r ResourceSelector) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]any) + populate(objectMap, "name", r.Name) + populate(objectMap, "selectors", r.Selectors) + return json.Marshal(objectMap) +} + +// UnmarshalJSON implements the json.Unmarshaller interface for type ResourceSelector. +func (r *ResourceSelector) UnmarshalJSON(data []byte) error { + var rawMsg map[string]json.RawMessage + if err := json.Unmarshal(data, &rawMsg); err != nil { + return fmt.Errorf("unmarshalling type %T: %v", r, err) + } + for key, val := range rawMsg { + var err error + switch key { + case "name": + err = unpopulate(val, "Name", &r.Name) + delete(rawMsg, key) + case "selectors": + err = unpopulate(val, "Selectors", &r.Selectors) + delete(rawMsg, key) + } + if err != nil { + return fmt.Errorf("unmarshalling type %T: %v", r, err) + } + } + return nil +} + // MarshalJSON implements the json.Marshaller interface for type ResourceTypeAliases. func (r ResourceTypeAliases) MarshalJSON() ([]byte, error) { objectMap := make(map[string]any) @@ -1189,6 +1364,41 @@ func (r *ResourceTypeAliases) UnmarshalJSON(data []byte) error { return nil } +// MarshalJSON implements the json.Marshaller interface for type Selector. +func (s Selector) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]any) + populate(objectMap, "in", s.In) + populate(objectMap, "kind", s.Kind) + populate(objectMap, "notIn", s.NotIn) + return json.Marshal(objectMap) +} + +// UnmarshalJSON implements the json.Unmarshaller interface for type Selector. +func (s *Selector) UnmarshalJSON(data []byte) error { + var rawMsg map[string]json.RawMessage + if err := json.Unmarshal(data, &rawMsg); err != nil { + return fmt.Errorf("unmarshalling type %T: %v", s, err) + } + for key, val := range rawMsg { + var err error + switch key { + case "in": + err = unpopulate(val, "In", &s.In) + delete(rawMsg, key) + case "kind": + err = unpopulate(val, "Kind", &s.Kind) + delete(rawMsg, key) + case "notIn": + err = unpopulate(val, "NotIn", &s.NotIn) + delete(rawMsg, key) + } + if err != nil { + return fmt.Errorf("unmarshalling type %T: %v", s, err) + } + } + return nil +} + // MarshalJSON implements the json.Marshaller interface for type SetDefinition. func (s SetDefinition) MarshalJSON() ([]byte, error) { objectMap := make(map[string]any) @@ -1392,6 +1602,266 @@ func (u *UserAssignedIdentitiesValue) UnmarshalJSON(data []byte) error { return nil } +// MarshalJSON implements the json.Marshaller interface for type Variable. +func (v Variable) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]any) + populate(objectMap, "id", v.ID) + populate(objectMap, "name", v.Name) + populate(objectMap, "properties", v.Properties) + populate(objectMap, "systemData", v.SystemData) + populate(objectMap, "type", v.Type) + return json.Marshal(objectMap) +} + +// UnmarshalJSON implements the json.Unmarshaller interface for type Variable. +func (v *Variable) UnmarshalJSON(data []byte) error { + var rawMsg map[string]json.RawMessage + if err := json.Unmarshal(data, &rawMsg); err != nil { + return fmt.Errorf("unmarshalling type %T: %v", v, err) + } + for key, val := range rawMsg { + var err error + switch key { + case "id": + err = unpopulate(val, "ID", &v.ID) + delete(rawMsg, key) + case "name": + err = unpopulate(val, "Name", &v.Name) + delete(rawMsg, key) + case "properties": + err = unpopulate(val, "Properties", &v.Properties) + delete(rawMsg, key) + case "systemData": + err = unpopulate(val, "SystemData", &v.SystemData) + delete(rawMsg, key) + case "type": + err = unpopulate(val, "Type", &v.Type) + delete(rawMsg, key) + } + if err != nil { + return fmt.Errorf("unmarshalling type %T: %v", v, err) + } + } + return nil +} + +// MarshalJSON implements the json.Marshaller interface for type VariableColumn. +func (v VariableColumn) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]any) + populate(objectMap, "columnName", v.ColumnName) + return json.Marshal(objectMap) +} + +// UnmarshalJSON implements the json.Unmarshaller interface for type VariableColumn. +func (v *VariableColumn) UnmarshalJSON(data []byte) error { + var rawMsg map[string]json.RawMessage + if err := json.Unmarshal(data, &rawMsg); err != nil { + return fmt.Errorf("unmarshalling type %T: %v", v, err) + } + for key, val := range rawMsg { + var err error + switch key { + case "columnName": + err = unpopulate(val, "ColumnName", &v.ColumnName) + delete(rawMsg, key) + } + if err != nil { + return fmt.Errorf("unmarshalling type %T: %v", v, err) + } + } + return nil +} + +// MarshalJSON implements the json.Marshaller interface for type VariableListResult. +func (v VariableListResult) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]any) + populate(objectMap, "nextLink", v.NextLink) + populate(objectMap, "value", v.Value) + return json.Marshal(objectMap) +} + +// UnmarshalJSON implements the json.Unmarshaller interface for type VariableListResult. +func (v *VariableListResult) UnmarshalJSON(data []byte) error { + var rawMsg map[string]json.RawMessage + if err := json.Unmarshal(data, &rawMsg); err != nil { + return fmt.Errorf("unmarshalling type %T: %v", v, err) + } + for key, val := range rawMsg { + var err error + switch key { + case "nextLink": + err = unpopulate(val, "NextLink", &v.NextLink) + delete(rawMsg, key) + case "value": + err = unpopulate(val, "Value", &v.Value) + delete(rawMsg, key) + } + if err != nil { + return fmt.Errorf("unmarshalling type %T: %v", v, err) + } + } + return nil +} + +// MarshalJSON implements the json.Marshaller interface for type VariableProperties. +func (v VariableProperties) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]any) + populate(objectMap, "columns", v.Columns) + return json.Marshal(objectMap) +} + +// UnmarshalJSON implements the json.Unmarshaller interface for type VariableProperties. +func (v *VariableProperties) UnmarshalJSON(data []byte) error { + var rawMsg map[string]json.RawMessage + if err := json.Unmarshal(data, &rawMsg); err != nil { + return fmt.Errorf("unmarshalling type %T: %v", v, err) + } + for key, val := range rawMsg { + var err error + switch key { + case "columns": + err = unpopulate(val, "Columns", &v.Columns) + delete(rawMsg, key) + } + if err != nil { + return fmt.Errorf("unmarshalling type %T: %v", v, err) + } + } + return nil +} + +// MarshalJSON implements the json.Marshaller interface for type VariableValue. +func (v VariableValue) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]any) + populate(objectMap, "id", v.ID) + populate(objectMap, "name", v.Name) + populate(objectMap, "properties", v.Properties) + populate(objectMap, "systemData", v.SystemData) + populate(objectMap, "type", v.Type) + return json.Marshal(objectMap) +} + +// UnmarshalJSON implements the json.Unmarshaller interface for type VariableValue. +func (v *VariableValue) UnmarshalJSON(data []byte) error { + var rawMsg map[string]json.RawMessage + if err := json.Unmarshal(data, &rawMsg); err != nil { + return fmt.Errorf("unmarshalling type %T: %v", v, err) + } + for key, val := range rawMsg { + var err error + switch key { + case "id": + err = unpopulate(val, "ID", &v.ID) + delete(rawMsg, key) + case "name": + err = unpopulate(val, "Name", &v.Name) + delete(rawMsg, key) + case "properties": + err = unpopulate(val, "Properties", &v.Properties) + delete(rawMsg, key) + case "systemData": + err = unpopulate(val, "SystemData", &v.SystemData) + delete(rawMsg, key) + case "type": + err = unpopulate(val, "Type", &v.Type) + delete(rawMsg, key) + } + if err != nil { + return fmt.Errorf("unmarshalling type %T: %v", v, err) + } + } + return nil +} + +// MarshalJSON implements the json.Marshaller interface for type VariableValueColumnValue. +func (v VariableValueColumnValue) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]any) + populate(objectMap, "columnName", v.ColumnName) + populateAny(objectMap, "columnValue", v.ColumnValue) + return json.Marshal(objectMap) +} + +// UnmarshalJSON implements the json.Unmarshaller interface for type VariableValueColumnValue. +func (v *VariableValueColumnValue) UnmarshalJSON(data []byte) error { + var rawMsg map[string]json.RawMessage + if err := json.Unmarshal(data, &rawMsg); err != nil { + return fmt.Errorf("unmarshalling type %T: %v", v, err) + } + for key, val := range rawMsg { + var err error + switch key { + case "columnName": + err = unpopulate(val, "ColumnName", &v.ColumnName) + delete(rawMsg, key) + case "columnValue": + err = unpopulate(val, "ColumnValue", &v.ColumnValue) + delete(rawMsg, key) + } + if err != nil { + return fmt.Errorf("unmarshalling type %T: %v", v, err) + } + } + return nil +} + +// MarshalJSON implements the json.Marshaller interface for type VariableValueListResult. +func (v VariableValueListResult) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]any) + populate(objectMap, "nextLink", v.NextLink) + populate(objectMap, "value", v.Value) + return json.Marshal(objectMap) +} + +// UnmarshalJSON implements the json.Unmarshaller interface for type VariableValueListResult. +func (v *VariableValueListResult) UnmarshalJSON(data []byte) error { + var rawMsg map[string]json.RawMessage + if err := json.Unmarshal(data, &rawMsg); err != nil { + return fmt.Errorf("unmarshalling type %T: %v", v, err) + } + for key, val := range rawMsg { + var err error + switch key { + case "nextLink": + err = unpopulate(val, "NextLink", &v.NextLink) + delete(rawMsg, key) + case "value": + err = unpopulate(val, "Value", &v.Value) + delete(rawMsg, key) + } + if err != nil { + return fmt.Errorf("unmarshalling type %T: %v", v, err) + } + } + return nil +} + +// MarshalJSON implements the json.Marshaller interface for type VariableValueProperties. +func (v VariableValueProperties) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]any) + populate(objectMap, "values", v.Values) + return json.Marshal(objectMap) +} + +// UnmarshalJSON implements the json.Unmarshaller interface for type VariableValueProperties. +func (v *VariableValueProperties) UnmarshalJSON(data []byte) error { + var rawMsg map[string]json.RawMessage + if err := json.Unmarshal(data, &rawMsg); err != nil { + return fmt.Errorf("unmarshalling type %T: %v", v, err) + } + for key, val := range rawMsg { + var err error + switch key { + case "values": + err = unpopulate(val, "Values", &v.Values) + delete(rawMsg, key) + } + if err != nil { + return fmt.Errorf("unmarshalling type %T: %v", v, err) + } + } + return nil +} + func populate(m map[string]any, k string, v any) { if v == nil { return diff --git a/sdk/resourcemanager/resources/armpolicy/response_types.go b/sdk/resourcemanager/resources/armpolicy/response_types.go index 21d3c08cb86c..5e8e7f96d829 100644 --- a/sdk/resourcemanager/resources/armpolicy/response_types.go +++ b/sdk/resourcemanager/resources/armpolicy/response_types.go @@ -164,6 +164,11 @@ type ExemptionsClientListResponse struct { ExemptionListResult } +// ExemptionsClientUpdateResponse contains the response from method ExemptionsClient.Update. +type ExemptionsClientUpdateResponse struct { + Exemption +} + // SetDefinitionsClientCreateOrUpdateAtManagementGroupResponse contains the response from method SetDefinitionsClient.CreateOrUpdateAtManagementGroup. type SetDefinitionsClientCreateOrUpdateAtManagementGroupResponse struct { SetDefinition @@ -213,3 +218,83 @@ type SetDefinitionsClientListByManagementGroupResponse struct { type SetDefinitionsClientListResponse struct { SetDefinitionListResult } + +// VariableValuesClientCreateOrUpdateAtManagementGroupResponse contains the response from method VariableValuesClient.CreateOrUpdateAtManagementGroup. +type VariableValuesClientCreateOrUpdateAtManagementGroupResponse struct { + VariableValue +} + +// VariableValuesClientCreateOrUpdateResponse contains the response from method VariableValuesClient.CreateOrUpdate. +type VariableValuesClientCreateOrUpdateResponse struct { + VariableValue +} + +// VariableValuesClientDeleteAtManagementGroupResponse contains the response from method VariableValuesClient.DeleteAtManagementGroup. +type VariableValuesClientDeleteAtManagementGroupResponse struct { + // placeholder for future response values +} + +// VariableValuesClientDeleteResponse contains the response from method VariableValuesClient.Delete. +type VariableValuesClientDeleteResponse struct { + // placeholder for future response values +} + +// VariableValuesClientGetAtManagementGroupResponse contains the response from method VariableValuesClient.GetAtManagementGroup. +type VariableValuesClientGetAtManagementGroupResponse struct { + VariableValue +} + +// VariableValuesClientGetResponse contains the response from method VariableValuesClient.Get. +type VariableValuesClientGetResponse struct { + VariableValue +} + +// VariableValuesClientListForManagementGroupResponse contains the response from method VariableValuesClient.NewListForManagementGroupPager. +type VariableValuesClientListForManagementGroupResponse struct { + VariableValueListResult +} + +// VariableValuesClientListResponse contains the response from method VariableValuesClient.NewListPager. +type VariableValuesClientListResponse struct { + VariableValueListResult +} + +// VariablesClientCreateOrUpdateAtManagementGroupResponse contains the response from method VariablesClient.CreateOrUpdateAtManagementGroup. +type VariablesClientCreateOrUpdateAtManagementGroupResponse struct { + Variable +} + +// VariablesClientCreateOrUpdateResponse contains the response from method VariablesClient.CreateOrUpdate. +type VariablesClientCreateOrUpdateResponse struct { + Variable +} + +// VariablesClientDeleteAtManagementGroupResponse contains the response from method VariablesClient.DeleteAtManagementGroup. +type VariablesClientDeleteAtManagementGroupResponse struct { + // placeholder for future response values +} + +// VariablesClientDeleteResponse contains the response from method VariablesClient.Delete. +type VariablesClientDeleteResponse struct { + // placeholder for future response values +} + +// VariablesClientGetAtManagementGroupResponse contains the response from method VariablesClient.GetAtManagementGroup. +type VariablesClientGetAtManagementGroupResponse struct { + Variable +} + +// VariablesClientGetResponse contains the response from method VariablesClient.Get. +type VariablesClientGetResponse struct { + Variable +} + +// VariablesClientListForManagementGroupResponse contains the response from method VariablesClient.NewListForManagementGroupPager. +type VariablesClientListForManagementGroupResponse struct { + VariableListResult +} + +// VariablesClientListResponse contains the response from method VariablesClient.NewListPager. +type VariablesClientListResponse struct { + VariableListResult +} diff --git a/sdk/resourcemanager/resources/armpolicy/setdefinitions_client_example_test.go b/sdk/resourcemanager/resources/armpolicy/setdefinitions_client_example_test.go deleted file mode 100644 index fdfda46c6dc7..000000000000 --- a/sdk/resourcemanager/resources/armpolicy/setdefinitions_client_example_test.go +++ /dev/null @@ -1,1028 +0,0 @@ -//go:build go1.18 -// +build go1.18 - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See License.txt in the project root for license information. -// Code generated by Microsoft (R) AutoRest Code Generator. -// Changes may cause incorrect behavior and will be lost if the code is regenerated. -// DO NOT EDIT. - -package armpolicy_test - -import ( - "context" - "log" - - "github.com/Azure/azure-sdk-for-go/sdk/azcore/to" - "github.com/Azure/azure-sdk-for-go/sdk/azidentity" - "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armpolicy" -) - -// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/d55b8005f05b040b852c15e74a0f3e36494a15e1/specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/createOrUpdatePolicySetDefinition.json -func ExampleSetDefinitionsClient_CreateOrUpdate_createOrUpdateAPolicySetDefinition() { - cred, err := azidentity.NewDefaultAzureCredential(nil) - if err != nil { - log.Fatalf("failed to obtain a credential: %v", err) - } - ctx := context.Background() - clientFactory, err := armpolicy.NewClientFactory("", cred, nil) - if err != nil { - log.Fatalf("failed to create client: %v", err) - } - res, err := clientFactory.NewSetDefinitionsClient().CreateOrUpdate(ctx, "CostManagement", armpolicy.SetDefinition{ - Properties: &armpolicy.SetDefinitionProperties{ - Description: to.Ptr("Policies to enforce low cost storage SKUs"), - DisplayName: to.Ptr("Cost Management"), - Metadata: map[string]any{ - "category": "Cost Management", - }, - Parameters: map[string]*armpolicy.ParameterDefinitionsValue{ - "namePrefix": { - Type: to.Ptr(armpolicy.ParameterTypeString), - DefaultValue: "myPrefix", - Metadata: &armpolicy.ParameterDefinitionsValueMetadata{ - DisplayName: to.Ptr("Prefix to enforce on resource names"), - }, - }, - }, - PolicyDefinitions: []*armpolicy.DefinitionReference{ - { - Parameters: map[string]*armpolicy.ParameterValuesValue{ - "listOfAllowedSKUs": { - Value: []any{ - "Standard_GRS", - "Standard_LRS", - }, - }, - }, - PolicyDefinitionID: to.Ptr("/subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2/providers/Microsoft.Authorization/policyDefinitions/7433c107-6db4-4ad1-b57a-a76dce0154a1"), - PolicyDefinitionReferenceID: to.Ptr("Limit_Skus"), - }, - { - Parameters: map[string]*armpolicy.ParameterValuesValue{ - "prefix": { - Value: "[parameters('namePrefix')]", - }, - "suffix": { - Value: "-LC", - }, - }, - PolicyDefinitionID: to.Ptr("/subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2/providers/Microsoft.Authorization/policyDefinitions/ResourceNaming"), - PolicyDefinitionReferenceID: to.Ptr("Resource_Naming"), - }}, - }, - }, nil) - if err != nil { - log.Fatalf("failed to finish the request: %v", err) - } - // You could use response here. We use blank identifier for just demo purposes. - _ = res - // If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes. - // res.SetDefinition = armpolicy.SetDefinition{ - // Name: to.Ptr("CostManagement"), - // Type: to.Ptr("Microsoft.Authorization/policySetDefinitions"), - // ID: to.Ptr("/subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2/providers/Microsoft.Authorization/policySetDefinitions/CostManagement"), - // Properties: &armpolicy.SetDefinitionProperties{ - // Description: to.Ptr("Policies to enforce low cost storage SKUs"), - // DisplayName: to.Ptr("Cost Management"), - // Metadata: map[string]any{ - // "category": "Cost Management", - // }, - // Parameters: map[string]*armpolicy.ParameterDefinitionsValue{ - // "namePrefix": &armpolicy.ParameterDefinitionsValue{ - // Type: to.Ptr(armpolicy.ParameterTypeString), - // DefaultValue: "myPrefix", - // Metadata: &armpolicy.ParameterDefinitionsValueMetadata{ - // DisplayName: to.Ptr("Prefix to enforce on resource names"), - // }, - // }, - // }, - // PolicyDefinitions: []*armpolicy.DefinitionReference{ - // { - // Parameters: map[string]*armpolicy.ParameterValuesValue{ - // "listOfAllowedSKUs": &armpolicy.ParameterValuesValue{ - // Value: []any{ - // "Standard_GRS", - // "Standard_LRS", - // }, - // }, - // }, - // PolicyDefinitionID: to.Ptr("/subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2/providers/Microsoft.Authorization/policyDefinitions/7433c107-6db4-4ad1-b57a-a76dce0154a1"), - // PolicyDefinitionReferenceID: to.Ptr("Limit_Skus"), - // }, - // { - // Parameters: map[string]*armpolicy.ParameterValuesValue{ - // "prefix": &armpolicy.ParameterValuesValue{ - // Value: "[parameters('namePrefix')]", - // }, - // "suffix": &armpolicy.ParameterValuesValue{ - // Value: "-LC", - // }, - // }, - // PolicyDefinitionID: to.Ptr("/subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2/providers/Microsoft.Authorization/policyDefinitions/ResourceNaming"), - // PolicyDefinitionReferenceID: to.Ptr("Resource_Naming"), - // }}, - // }, - // } -} - -// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/d55b8005f05b040b852c15e74a0f3e36494a15e1/specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/createOrUpdatePolicySetDefinitionWithGroups.json -func ExampleSetDefinitionsClient_CreateOrUpdate_createOrUpdateAPolicySetDefinitionWithGroups() { - cred, err := azidentity.NewDefaultAzureCredential(nil) - if err != nil { - log.Fatalf("failed to obtain a credential: %v", err) - } - ctx := context.Background() - clientFactory, err := armpolicy.NewClientFactory("", cred, nil) - if err != nil { - log.Fatalf("failed to create client: %v", err) - } - res, err := clientFactory.NewSetDefinitionsClient().CreateOrUpdate(ctx, "CostManagement", armpolicy.SetDefinition{ - Properties: &armpolicy.SetDefinitionProperties{ - Description: to.Ptr("Policies to enforce low cost storage SKUs"), - DisplayName: to.Ptr("Cost Management"), - Metadata: map[string]any{ - "category": "Cost Management", - }, - PolicyDefinitionGroups: []*armpolicy.DefinitionGroup{ - { - Name: to.Ptr("CostSaving"), - Description: to.Ptr("Policies designed to control spend within a subscription."), - DisplayName: to.Ptr("Cost Management Policies"), - }, - { - Name: to.Ptr("Organizational"), - Description: to.Ptr("Policies that help enforce resource organization standards within a subscription."), - DisplayName: to.Ptr("Organizational Policies"), - }}, - PolicyDefinitions: []*armpolicy.DefinitionReference{ - { - GroupNames: []*string{ - to.Ptr("CostSaving")}, - Parameters: map[string]*armpolicy.ParameterValuesValue{ - "listOfAllowedSKUs": { - Value: []any{ - "Standard_GRS", - "Standard_LRS", - }, - }, - }, - PolicyDefinitionID: to.Ptr("/subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2/providers/Microsoft.Authorization/policyDefinitions/7433c107-6db4-4ad1-b57a-a76dce0154a1"), - PolicyDefinitionReferenceID: to.Ptr("Limit_Skus"), - }, - { - GroupNames: []*string{ - to.Ptr("Organizational")}, - Parameters: map[string]*armpolicy.ParameterValuesValue{ - "prefix": { - Value: "DeptA", - }, - "suffix": { - Value: "-LC", - }, - }, - PolicyDefinitionID: to.Ptr("/subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2/providers/Microsoft.Authorization/policyDefinitions/ResourceNaming"), - PolicyDefinitionReferenceID: to.Ptr("Resource_Naming"), - }}, - }, - }, nil) - if err != nil { - log.Fatalf("failed to finish the request: %v", err) - } - // You could use response here. We use blank identifier for just demo purposes. - _ = res - // If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes. - // res.SetDefinition = armpolicy.SetDefinition{ - // Name: to.Ptr("CostManagement"), - // Type: to.Ptr("Microsoft.Authorization/policySetDefinitions"), - // ID: to.Ptr("/subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2/providers/Microsoft.Authorization/policySetDefinitions/CostManagement"), - // Properties: &armpolicy.SetDefinitionProperties{ - // Description: to.Ptr("Policies to enforce low cost storage SKUs"), - // DisplayName: to.Ptr("Cost Management"), - // Metadata: map[string]any{ - // "category": "Cost Management", - // }, - // PolicyDefinitionGroups: []*armpolicy.DefinitionGroup{ - // { - // Name: to.Ptr("CostSaving"), - // Description: to.Ptr("Policies designed to control spend within a subscription."), - // DisplayName: to.Ptr("Cost Management Policies"), - // }, - // { - // Name: to.Ptr("Organizational"), - // Description: to.Ptr("Policies that help enforce resource organization standards within a subscription."), - // DisplayName: to.Ptr("Organizational Policies"), - // }}, - // PolicyDefinitions: []*armpolicy.DefinitionReference{ - // { - // GroupNames: []*string{ - // to.Ptr("CostSaving")}, - // Parameters: map[string]*armpolicy.ParameterValuesValue{ - // "listOfAllowedSKUs": &armpolicy.ParameterValuesValue{ - // Value: []any{ - // "Standard_GRS", - // "Standard_LRS", - // }, - // }, - // }, - // PolicyDefinitionID: to.Ptr("/subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2/providers/Microsoft.Authorization/policyDefinitions/7433c107-6db4-4ad1-b57a-a76dce0154a1"), - // PolicyDefinitionReferenceID: to.Ptr("Limit_Skus"), - // }, - // { - // GroupNames: []*string{ - // to.Ptr("Organizational")}, - // Parameters: map[string]*armpolicy.ParameterValuesValue{ - // "prefix": &armpolicy.ParameterValuesValue{ - // Value: "DeptA", - // }, - // "suffix": &armpolicy.ParameterValuesValue{ - // Value: "-LC", - // }, - // }, - // PolicyDefinitionID: to.Ptr("/subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2/providers/Microsoft.Authorization/policyDefinitions/ResourceNaming"), - // PolicyDefinitionReferenceID: to.Ptr("Resource_Naming"), - // }}, - // }, - // } -} - -// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/d55b8005f05b040b852c15e74a0f3e36494a15e1/specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/deletePolicySetDefinition.json -func ExampleSetDefinitionsClient_Delete() { - cred, err := azidentity.NewDefaultAzureCredential(nil) - if err != nil { - log.Fatalf("failed to obtain a credential: %v", err) - } - ctx := context.Background() - clientFactory, err := armpolicy.NewClientFactory("", cred, nil) - if err != nil { - log.Fatalf("failed to create client: %v", err) - } - _, err = clientFactory.NewSetDefinitionsClient().Delete(ctx, "CostManagement", nil) - if err != nil { - log.Fatalf("failed to finish the request: %v", err) - } -} - -// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/d55b8005f05b040b852c15e74a0f3e36494a15e1/specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/getPolicySetDefinition.json -func ExampleSetDefinitionsClient_Get() { - cred, err := azidentity.NewDefaultAzureCredential(nil) - if err != nil { - log.Fatalf("failed to obtain a credential: %v", err) - } - ctx := context.Background() - clientFactory, err := armpolicy.NewClientFactory("", cred, nil) - if err != nil { - log.Fatalf("failed to create client: %v", err) - } - res, err := clientFactory.NewSetDefinitionsClient().Get(ctx, "CostManagement", nil) - if err != nil { - log.Fatalf("failed to finish the request: %v", err) - } - // You could use response here. We use blank identifier for just demo purposes. - _ = res - // If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes. - // res.SetDefinition = armpolicy.SetDefinition{ - // Name: to.Ptr("CostManagement"), - // Type: to.Ptr("Microsoft.Authorization/policySetDefinitions"), - // ID: to.Ptr("/subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2/providers/Microsoft.Authorization/policySetDefinitions/CostManagement"), - // Properties: &armpolicy.SetDefinitionProperties{ - // Description: to.Ptr("Policies to enforce low cost storage SKUs"), - // DisplayName: to.Ptr("Cost Management"), - // Metadata: map[string]any{ - // "category": "Cost Management", - // }, - // PolicyDefinitionGroups: []*armpolicy.DefinitionGroup{ - // { - // Name: to.Ptr("CostSaving"), - // Description: to.Ptr("Policies designed to control spend within a subscription."), - // DisplayName: to.Ptr("Cost Management Policies"), - // }, - // { - // Name: to.Ptr("Organizational"), - // Description: to.Ptr("Policies that help enforce resource organization standards within a subscription."), - // DisplayName: to.Ptr("Organizational Policies"), - // }}, - // PolicyDefinitions: []*armpolicy.DefinitionReference{ - // { - // GroupNames: []*string{ - // to.Ptr("CostSaving")}, - // Parameters: map[string]*armpolicy.ParameterValuesValue{ - // "listOfAllowedSKUs": &armpolicy.ParameterValuesValue{ - // Value: []any{ - // "Standard_GRS", - // "Standard_LRS", - // }, - // }, - // }, - // PolicyDefinitionID: to.Ptr("/subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2/providers/Microsoft.Authorization/policyDefinitions/7433c107-6db4-4ad1-b57a-a76dce0154a1"), - // PolicyDefinitionReferenceID: to.Ptr("Limit_Skus"), - // }, - // { - // GroupNames: []*string{ - // to.Ptr("Organizational")}, - // Parameters: map[string]*armpolicy.ParameterValuesValue{ - // "prefix": &armpolicy.ParameterValuesValue{ - // Value: "DeptA", - // }, - // "suffix": &armpolicy.ParameterValuesValue{ - // Value: "-LC", - // }, - // }, - // PolicyDefinitionID: to.Ptr("/subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2/providers/Microsoft.Authorization/policyDefinitions/ResourceNaming"), - // PolicyDefinitionReferenceID: to.Ptr("Resource_Naming"), - // }}, - // }, - // } -} - -// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/d55b8005f05b040b852c15e74a0f3e36494a15e1/specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/getBuiltInPolicySetDefinition.json -func ExampleSetDefinitionsClient_GetBuiltIn() { - cred, err := azidentity.NewDefaultAzureCredential(nil) - if err != nil { - log.Fatalf("failed to obtain a credential: %v", err) - } - ctx := context.Background() - clientFactory, err := armpolicy.NewClientFactory("", cred, nil) - if err != nil { - log.Fatalf("failed to create client: %v", err) - } - res, err := clientFactory.NewSetDefinitionsClient().GetBuiltIn(ctx, "1f3afdf9-d0c9-4c3d-847f-89da613e70a8", nil) - if err != nil { - log.Fatalf("failed to finish the request: %v", err) - } - // You could use response here. We use blank identifier for just demo purposes. - _ = res - // If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes. - // res.SetDefinition = armpolicy.SetDefinition{ - // Name: to.Ptr("1f3afdf9-d0c9-4c3d-847f-89da613e70a8"), - // Type: to.Ptr("Microsoft.Authorization/policySetDefinitions"), - // ID: to.Ptr("/providers/Microsoft.Authorization/policySetDefinitions/1f3afdf9-d0c9-4c3d-847f-89da613e70a8"), - // Properties: &armpolicy.SetDefinitionProperties{ - // Description: to.Ptr("Monitor all the available security recommendations in Azure Security Center. This is the default policy for Azure Security Center."), - // DisplayName: to.Ptr("[Preview]: Enable Monitoring in Azure Security Center"), - // Metadata: map[string]any{ - // "category": "Security Center", - // }, - // Parameters: map[string]*armpolicy.ParameterDefinitionsValue{ - // }, - // PolicyDefinitions: []*armpolicy.DefinitionReference{ - // { - // PolicyDefinitionID: to.Ptr("/providers/Microsoft.Authorization/policyDefinitions/a8bef009-a5c9-4d0f-90d7-6018734e8a16"), - // PolicyDefinitionReferenceID: to.Ptr("RefId1"), - // }, - // { - // PolicyDefinitionID: to.Ptr("/providers/Microsoft.Authorization/policyDefinitions/af8051bf-258b-44e2-a2bf-165330459f9d"), - // PolicyDefinitionReferenceID: to.Ptr("RefId2"), - // }, - // { - // PolicyDefinitionID: to.Ptr("/providers/Microsoft.Authorization/policyDefinitions/86b3d65f-7626-441e-b690-81a8b71cff60"), - // PolicyDefinitionReferenceID: to.Ptr("RefId3"), - // }, - // { - // PolicyDefinitionID: to.Ptr("/providers/Microsoft.Authorization/policyDefinitions/655cb504-bcee-4362-bd4c-402e6aa38759"), - // PolicyDefinitionReferenceID: to.Ptr("RefId4"), - // }, - // { - // PolicyDefinitionID: to.Ptr("/providers/Microsoft.Authorization/policyDefinitions/b0f33259-77d7-4c9e-aac6-3aabcfae693c"), - // PolicyDefinitionReferenceID: to.Ptr("RefId5"), - // }, - // { - // PolicyDefinitionID: to.Ptr("/providers/Microsoft.Authorization/policyDefinitions/47a6b606-51aa-4496-8bb7-64b11cf66adc"), - // PolicyDefinitionReferenceID: to.Ptr("RefId6"), - // }, - // { - // PolicyDefinitionID: to.Ptr("/providers/Microsoft.Authorization/policyDefinitions/44452482-524f-4bf4-b852-0bff7cc4a3ed"), - // PolicyDefinitionReferenceID: to.Ptr("RefId7"), - // }, - // { - // PolicyDefinitionID: to.Ptr("/providers/Microsoft.Authorization/policyDefinitions/e1e5fd5d-3e4c-4ce1-8661-7d1873ae6b15"), - // PolicyDefinitionReferenceID: to.Ptr("RefId8"), - // }, - // { - // PolicyDefinitionID: to.Ptr("/providers/Microsoft.Authorization/policyDefinitions/af6cd1bd-1635-48cb-bde7-5b15693900b9"), - // PolicyDefinitionReferenceID: to.Ptr("RefId9"), - // }, - // { - // PolicyDefinitionID: to.Ptr("/providers/Microsoft.Authorization/policyDefinitions/0961003e-5a0a-4549-abde-af6a37f2724d"), - // PolicyDefinitionReferenceID: to.Ptr("RefId10"), - // }}, - // PolicyType: to.Ptr(armpolicy.PolicyTypeBuiltIn), - // }, - // } -} - -// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/d55b8005f05b040b852c15e74a0f3e36494a15e1/specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/listPolicySetDefinitions.json -func ExampleSetDefinitionsClient_NewListPager() { - cred, err := azidentity.NewDefaultAzureCredential(nil) - if err != nil { - log.Fatalf("failed to obtain a credential: %v", err) - } - ctx := context.Background() - clientFactory, err := armpolicy.NewClientFactory("", cred, nil) - if err != nil { - log.Fatalf("failed to create client: %v", err) - } - pager := clientFactory.NewSetDefinitionsClient().NewListPager(&armpolicy.SetDefinitionsClientListOptions{Filter: nil, - Top: nil, - }) - for pager.More() { - page, err := pager.NextPage(ctx) - if err != nil { - log.Fatalf("failed to advance page: %v", err) - } - for _, v := range page.Value { - // You could use page here. We use blank identifier for just demo purposes. - _ = v - } - // If the HTTP response code is 200 as defined in example definition, your page structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes. - // page.SetDefinitionListResult = armpolicy.SetDefinitionListResult{ - // Value: []*armpolicy.SetDefinition{ - // { - // Name: to.Ptr("1f3afdf9-d0c9-4c3d-847f-89da613e70a8"), - // Type: to.Ptr("Microsoft.Authorization/policySetDefinitions"), - // ID: to.Ptr("/providers/Microsoft.Authorization/policySetDefinitions/1f3afdf9-d0c9-4c3d-847f-89da613e70a8"), - // Properties: &armpolicy.SetDefinitionProperties{ - // Description: to.Ptr("Monitor all the available security recommendations in Azure Security Center. This is the default policy for Azure Security Center."), - // DisplayName: to.Ptr("[Preview]: Enable Monitoring in Azure Security Center"), - // Metadata: map[string]any{ - // "category": "Security Center", - // }, - // Parameters: map[string]*armpolicy.ParameterDefinitionsValue{ - // }, - // PolicyDefinitions: []*armpolicy.DefinitionReference{ - // { - // PolicyDefinitionID: to.Ptr("/providers/Microsoft.Authorization/policyDefinitions/a8bef009-a5c9-4d0f-90d7-6018734e8a16"), - // PolicyDefinitionReferenceID: to.Ptr("RefId1"), - // }, - // { - // PolicyDefinitionID: to.Ptr("/providers/Microsoft.Authorization/policyDefinitions/af8051bf-258b-44e2-a2bf-165330459f9d"), - // PolicyDefinitionReferenceID: to.Ptr("RefId2"), - // }, - // { - // PolicyDefinitionID: to.Ptr("/providers/Microsoft.Authorization/policyDefinitions/86b3d65f-7626-441e-b690-81a8b71cff60"), - // PolicyDefinitionReferenceID: to.Ptr("RefId3"), - // }, - // { - // PolicyDefinitionID: to.Ptr("/providers/Microsoft.Authorization/policyDefinitions/655cb504-bcee-4362-bd4c-402e6aa38759"), - // PolicyDefinitionReferenceID: to.Ptr("RefId4"), - // }, - // { - // PolicyDefinitionID: to.Ptr("/providers/Microsoft.Authorization/policyDefinitions/b0f33259-77d7-4c9e-aac6-3aabcfae693c"), - // PolicyDefinitionReferenceID: to.Ptr("RefId5"), - // }, - // { - // PolicyDefinitionID: to.Ptr("/providers/Microsoft.Authorization/policyDefinitions/47a6b606-51aa-4496-8bb7-64b11cf66adc"), - // PolicyDefinitionReferenceID: to.Ptr("RefId6"), - // }, - // { - // PolicyDefinitionID: to.Ptr("/providers/Microsoft.Authorization/policyDefinitions/44452482-524f-4bf4-b852-0bff7cc4a3ed"), - // PolicyDefinitionReferenceID: to.Ptr("RefId7"), - // }, - // { - // PolicyDefinitionID: to.Ptr("/providers/Microsoft.Authorization/policyDefinitions/e1e5fd5d-3e4c-4ce1-8661-7d1873ae6b15"), - // PolicyDefinitionReferenceID: to.Ptr("RefId8"), - // }, - // { - // PolicyDefinitionID: to.Ptr("/providers/Microsoft.Authorization/policyDefinitions/af6cd1bd-1635-48cb-bde7-5b15693900b9"), - // PolicyDefinitionReferenceID: to.Ptr("RefId9"), - // }, - // { - // PolicyDefinitionID: to.Ptr("/providers/Microsoft.Authorization/policyDefinitions/0961003e-5a0a-4549-abde-af6a37f2724d"), - // PolicyDefinitionReferenceID: to.Ptr("RefId10"), - // }}, - // PolicyType: to.Ptr(armpolicy.PolicyTypeBuiltIn), - // }, - // }, - // { - // Name: to.Ptr("CostManagement"), - // Type: to.Ptr("Microsoft.Authorization/policySetDefinitions"), - // ID: to.Ptr("/subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2/providers/Microsoft.Authorization/policySetDefinitions/CostManagement"), - // Properties: &armpolicy.SetDefinitionProperties{ - // Description: to.Ptr("Policies to enforce low cost storage SKUs"), - // DisplayName: to.Ptr("Cost Management"), - // Metadata: map[string]any{ - // "category": "Cost Management", - // }, - // PolicyDefinitions: []*armpolicy.DefinitionReference{ - // { - // Parameters: map[string]*armpolicy.ParameterValuesValue{ - // "listOfAllowedSKUs": &armpolicy.ParameterValuesValue{ - // Value: []any{ - // "Standard_GRS", - // "Standard_LRS", - // }, - // }, - // }, - // PolicyDefinitionID: to.Ptr("/subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2/providers/Microsoft.Authorization/policyDefinitions/7433c107-6db4-4ad1-b57a-a76dce0154a1"), - // PolicyDefinitionReferenceID: to.Ptr("Limit_Skus"), - // }, - // { - // Parameters: map[string]*armpolicy.ParameterValuesValue{ - // "prefix": &armpolicy.ParameterValuesValue{ - // Value: "DeptA", - // }, - // "suffix": &armpolicy.ParameterValuesValue{ - // Value: "-LC", - // }, - // }, - // PolicyDefinitionID: to.Ptr("/subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2/providers/Microsoft.Authorization/policyDefinitions/ResourceNaming"), - // PolicyDefinitionReferenceID: to.Ptr("Resource_Naming"), - // }}, - // }, - // }}, - // } - } -} - -// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/d55b8005f05b040b852c15e74a0f3e36494a15e1/specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/listBuiltInPolicySetDefinitions.json -func ExampleSetDefinitionsClient_NewListBuiltInPager() { - cred, err := azidentity.NewDefaultAzureCredential(nil) - if err != nil { - log.Fatalf("failed to obtain a credential: %v", err) - } - ctx := context.Background() - clientFactory, err := armpolicy.NewClientFactory("", cred, nil) - if err != nil { - log.Fatalf("failed to create client: %v", err) - } - pager := clientFactory.NewSetDefinitionsClient().NewListBuiltInPager(&armpolicy.SetDefinitionsClientListBuiltInOptions{Filter: nil, - Top: nil, - }) - for pager.More() { - page, err := pager.NextPage(ctx) - if err != nil { - log.Fatalf("failed to advance page: %v", err) - } - for _, v := range page.Value { - // You could use page here. We use blank identifier for just demo purposes. - _ = v - } - // If the HTTP response code is 200 as defined in example definition, your page structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes. - // page.SetDefinitionListResult = armpolicy.SetDefinitionListResult{ - // Value: []*armpolicy.SetDefinition{ - // { - // Name: to.Ptr("1f3afdf9-d0c9-4c3d-847f-89da613e70a8"), - // Type: to.Ptr("Microsoft.Authorization/policySetDefinitions"), - // ID: to.Ptr("/providers/Microsoft.Authorization/policySetDefinitions/1f3afdf9-d0c9-4c3d-847f-89da613e70a8"), - // Properties: &armpolicy.SetDefinitionProperties{ - // Description: to.Ptr("Monitor all the available security recommendations in Azure Security Center. This is the default policy for Azure Security Center."), - // DisplayName: to.Ptr("[Preview]: Enable Monitoring in Azure Security Center"), - // Metadata: map[string]any{ - // "category": "Security Center", - // }, - // Parameters: map[string]*armpolicy.ParameterDefinitionsValue{ - // }, - // PolicyDefinitions: []*armpolicy.DefinitionReference{ - // { - // PolicyDefinitionID: to.Ptr("/providers/Microsoft.Authorization/policyDefinitions/a8bef009-a5c9-4d0f-90d7-6018734e8a16"), - // PolicyDefinitionReferenceID: to.Ptr("RefId1"), - // }, - // { - // PolicyDefinitionID: to.Ptr("/providers/Microsoft.Authorization/policyDefinitions/af8051bf-258b-44e2-a2bf-165330459f9d"), - // PolicyDefinitionReferenceID: to.Ptr("RefId2"), - // }, - // { - // PolicyDefinitionID: to.Ptr("/providers/Microsoft.Authorization/policyDefinitions/86b3d65f-7626-441e-b690-81a8b71cff60"), - // PolicyDefinitionReferenceID: to.Ptr("RefId3"), - // }, - // { - // PolicyDefinitionID: to.Ptr("/providers/Microsoft.Authorization/policyDefinitions/655cb504-bcee-4362-bd4c-402e6aa38759"), - // PolicyDefinitionReferenceID: to.Ptr("RefId4"), - // }, - // { - // PolicyDefinitionID: to.Ptr("/providers/Microsoft.Authorization/policyDefinitions/b0f33259-77d7-4c9e-aac6-3aabcfae693c"), - // PolicyDefinitionReferenceID: to.Ptr("RefId5"), - // }, - // { - // PolicyDefinitionID: to.Ptr("/providers/Microsoft.Authorization/policyDefinitions/47a6b606-51aa-4496-8bb7-64b11cf66adc"), - // PolicyDefinitionReferenceID: to.Ptr("RefId6"), - // }, - // { - // PolicyDefinitionID: to.Ptr("/providers/Microsoft.Authorization/policyDefinitions/44452482-524f-4bf4-b852-0bff7cc4a3ed"), - // PolicyDefinitionReferenceID: to.Ptr("RefId7"), - // }, - // { - // PolicyDefinitionID: to.Ptr("/providers/Microsoft.Authorization/policyDefinitions/e1e5fd5d-3e4c-4ce1-8661-7d1873ae6b15"), - // PolicyDefinitionReferenceID: to.Ptr("RefId8"), - // }, - // { - // PolicyDefinitionID: to.Ptr("/providers/Microsoft.Authorization/policyDefinitions/af6cd1bd-1635-48cb-bde7-5b15693900b9"), - // PolicyDefinitionReferenceID: to.Ptr("RefId9"), - // }, - // { - // PolicyDefinitionID: to.Ptr("/providers/Microsoft.Authorization/policyDefinitions/0961003e-5a0a-4549-abde-af6a37f2724d"), - // PolicyDefinitionReferenceID: to.Ptr("RefId10"), - // }}, - // PolicyType: to.Ptr(armpolicy.PolicyTypeBuiltIn), - // }, - // }}, - // } - } -} - -// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/d55b8005f05b040b852c15e74a0f3e36494a15e1/specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/createOrUpdatePolicySetDefinitionAtManagementGroup.json -func ExampleSetDefinitionsClient_CreateOrUpdateAtManagementGroup_createOrUpdateAPolicySetDefinitionAtManagementGroupLevel() { - cred, err := azidentity.NewDefaultAzureCredential(nil) - if err != nil { - log.Fatalf("failed to obtain a credential: %v", err) - } - ctx := context.Background() - clientFactory, err := armpolicy.NewClientFactory("", cred, nil) - if err != nil { - log.Fatalf("failed to create client: %v", err) - } - res, err := clientFactory.NewSetDefinitionsClient().CreateOrUpdateAtManagementGroup(ctx, "CostManagement", "MyManagementGroup", armpolicy.SetDefinition{ - Properties: &armpolicy.SetDefinitionProperties{ - Description: to.Ptr("Policies to enforce low cost storage SKUs"), - DisplayName: to.Ptr("Cost Management"), - Metadata: map[string]any{ - "category": "Cost Management", - }, - PolicyDefinitions: []*armpolicy.DefinitionReference{ - { - Parameters: map[string]*armpolicy.ParameterValuesValue{ - "listOfAllowedSKUs": { - Value: []any{ - "Standard_GRS", - "Standard_LRS", - }, - }, - }, - PolicyDefinitionID: to.Ptr("/providers/Microsoft.Management/managementgroups/MyManagementGroup/providers/Microsoft.Authorization/policyDefinitions/7433c107-6db4-4ad1-b57a-a76dce0154a1"), - PolicyDefinitionReferenceID: to.Ptr("Limit_Skus"), - }, - { - Parameters: map[string]*armpolicy.ParameterValuesValue{ - "prefix": { - Value: "DeptA", - }, - "suffix": { - Value: "-LC", - }, - }, - PolicyDefinitionID: to.Ptr("/providers/Microsoft.Management/managementgroups/MyManagementGroup/providers/Microsoft.Authorization/policyDefinitions/ResourceNaming"), - PolicyDefinitionReferenceID: to.Ptr("Resource_Naming"), - }}, - }, - }, nil) - if err != nil { - log.Fatalf("failed to finish the request: %v", err) - } - // You could use response here. We use blank identifier for just demo purposes. - _ = res - // If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes. - // res.SetDefinition = armpolicy.SetDefinition{ - // Name: to.Ptr("CostManagement"), - // Type: to.Ptr("Microsoft.Authorization/policySetDefinitions"), - // ID: to.Ptr("/providers/Microsoft.Management/managementgroups/MyManagementGroup/providers/Microsoft.Authorization/policySetDefinitions/CostManagement"), - // Properties: &armpolicy.SetDefinitionProperties{ - // Description: to.Ptr("Policies to enforce low cost storage SKUs"), - // DisplayName: to.Ptr("Cost Management"), - // Metadata: map[string]any{ - // "category": "Cost Management", - // }, - // PolicyDefinitions: []*armpolicy.DefinitionReference{ - // { - // Parameters: map[string]*armpolicy.ParameterValuesValue{ - // "listOfAllowedSKUs": &armpolicy.ParameterValuesValue{ - // Value: []any{ - // "Standard_GRS", - // "Standard_LRS", - // }, - // }, - // }, - // PolicyDefinitionID: to.Ptr("/providers/Microsoft.Authorization/policyDefinitions/7433c107-6db4-4ad1-b57a-a76dce0154a1"), - // PolicyDefinitionReferenceID: to.Ptr("Limit_Skus"), - // }, - // { - // Parameters: map[string]*armpolicy.ParameterValuesValue{ - // "prefix": &armpolicy.ParameterValuesValue{ - // Value: "DeptA", - // }, - // "suffix": &armpolicy.ParameterValuesValue{ - // Value: "-LC", - // }, - // }, - // PolicyDefinitionID: to.Ptr("/providers/Microsoft.Management/managementgroups/MyManagementGroup/providers/Microsoft.Authorization/policyDefinitions/ResourceNaming"), - // PolicyDefinitionReferenceID: to.Ptr("Resource_Naming"), - // }}, - // }, - // } -} - -// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/d55b8005f05b040b852c15e74a0f3e36494a15e1/specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/createOrUpdatePolicySetDefinitionWithGroupsAtManagementGroup.json -func ExampleSetDefinitionsClient_CreateOrUpdateAtManagementGroup_createOrUpdateAPolicySetDefinitionWithGroupsAtManagementGroupLevel() { - cred, err := azidentity.NewDefaultAzureCredential(nil) - if err != nil { - log.Fatalf("failed to obtain a credential: %v", err) - } - ctx := context.Background() - clientFactory, err := armpolicy.NewClientFactory("", cred, nil) - if err != nil { - log.Fatalf("failed to create client: %v", err) - } - res, err := clientFactory.NewSetDefinitionsClient().CreateOrUpdateAtManagementGroup(ctx, "CostManagement", "MyManagementGroup", armpolicy.SetDefinition{ - Properties: &armpolicy.SetDefinitionProperties{ - Description: to.Ptr("Policies to enforce low cost storage SKUs"), - DisplayName: to.Ptr("Cost Management"), - Metadata: map[string]any{ - "category": "Cost Management", - }, - PolicyDefinitionGroups: []*armpolicy.DefinitionGroup{ - { - Name: to.Ptr("CostSaving"), - Description: to.Ptr("Policies designed to control spend within a subscription."), - DisplayName: to.Ptr("Cost Management Policies"), - }, - { - Name: to.Ptr("Organizational"), - Description: to.Ptr("Policies that help enforce resource organization standards within a subscription."), - DisplayName: to.Ptr("Organizational Policies"), - }}, - PolicyDefinitions: []*armpolicy.DefinitionReference{ - { - GroupNames: []*string{ - to.Ptr("CostSaving")}, - Parameters: map[string]*armpolicy.ParameterValuesValue{ - "listOfAllowedSKUs": { - Value: []any{ - "Standard_GRS", - "Standard_LRS", - }, - }, - }, - PolicyDefinitionID: to.Ptr("/subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2/providers/Microsoft.Authorization/policyDefinitions/7433c107-6db4-4ad1-b57a-a76dce0154a1"), - PolicyDefinitionReferenceID: to.Ptr("Limit_Skus"), - }, - { - GroupNames: []*string{ - to.Ptr("Organizational")}, - Parameters: map[string]*armpolicy.ParameterValuesValue{ - "prefix": { - Value: "DeptA", - }, - "suffix": { - Value: "-LC", - }, - }, - PolicyDefinitionID: to.Ptr("/subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2/providers/Microsoft.Authorization/policyDefinitions/ResourceNaming"), - PolicyDefinitionReferenceID: to.Ptr("Resource_Naming"), - }}, - }, - }, nil) - if err != nil { - log.Fatalf("failed to finish the request: %v", err) - } - // You could use response here. We use blank identifier for just demo purposes. - _ = res - // If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes. - // res.SetDefinition = armpolicy.SetDefinition{ - // Name: to.Ptr("CostManagement"), - // Type: to.Ptr("Microsoft.Authorization/policySetDefinitions"), - // ID: to.Ptr("/providers/Microsoft.Management/managementgroups/MyManagementGroup/providers/Microsoft.Authorization/policySetDefinitions/CostManagement"), - // Properties: &armpolicy.SetDefinitionProperties{ - // Description: to.Ptr("Policies to enforce low cost storage SKUs"), - // DisplayName: to.Ptr("Cost Management"), - // Metadata: map[string]any{ - // "category": "Cost Management", - // }, - // PolicyDefinitionGroups: []*armpolicy.DefinitionGroup{ - // { - // Name: to.Ptr("CostSaving"), - // Description: to.Ptr("Policies designed to control spend within a subscription."), - // DisplayName: to.Ptr("Cost Management Policies"), - // }, - // { - // Name: to.Ptr("Organizational"), - // Description: to.Ptr("Policies that help enforce resource organization standards within a subscription."), - // DisplayName: to.Ptr("Organizational Policies"), - // }}, - // PolicyDefinitions: []*armpolicy.DefinitionReference{ - // { - // GroupNames: []*string{ - // to.Ptr("CostSaving")}, - // Parameters: map[string]*armpolicy.ParameterValuesValue{ - // "listOfAllowedSKUs": &armpolicy.ParameterValuesValue{ - // Value: []any{ - // "Standard_GRS", - // "Standard_LRS", - // }, - // }, - // }, - // PolicyDefinitionID: to.Ptr("/subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2/providers/Microsoft.Authorization/policyDefinitions/7433c107-6db4-4ad1-b57a-a76dce0154a1"), - // PolicyDefinitionReferenceID: to.Ptr("Limit_Skus"), - // }, - // { - // GroupNames: []*string{ - // to.Ptr("Organizational")}, - // Parameters: map[string]*armpolicy.ParameterValuesValue{ - // "prefix": &armpolicy.ParameterValuesValue{ - // Value: "DeptA", - // }, - // "suffix": &armpolicy.ParameterValuesValue{ - // Value: "-LC", - // }, - // }, - // PolicyDefinitionID: to.Ptr("/subscriptions/ae640e6b-ba3e-4256-9d62-2993eecfa6f2/providers/Microsoft.Authorization/policyDefinitions/ResourceNaming"), - // PolicyDefinitionReferenceID: to.Ptr("Resource_Naming"), - // }}, - // }, - // } -} - -// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/d55b8005f05b040b852c15e74a0f3e36494a15e1/specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/deletePolicySetDefinitionAtManagementGroup.json -func ExampleSetDefinitionsClient_DeleteAtManagementGroup() { - cred, err := azidentity.NewDefaultAzureCredential(nil) - if err != nil { - log.Fatalf("failed to obtain a credential: %v", err) - } - ctx := context.Background() - clientFactory, err := armpolicy.NewClientFactory("", cred, nil) - if err != nil { - log.Fatalf("failed to create client: %v", err) - } - _, err = clientFactory.NewSetDefinitionsClient().DeleteAtManagementGroup(ctx, "CostManagement", "MyManagementGroup", nil) - if err != nil { - log.Fatalf("failed to finish the request: %v", err) - } -} - -// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/d55b8005f05b040b852c15e74a0f3e36494a15e1/specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/getPolicySetDefinitionAtManagementGroup.json -func ExampleSetDefinitionsClient_GetAtManagementGroup() { - cred, err := azidentity.NewDefaultAzureCredential(nil) - if err != nil { - log.Fatalf("failed to obtain a credential: %v", err) - } - ctx := context.Background() - clientFactory, err := armpolicy.NewClientFactory("", cred, nil) - if err != nil { - log.Fatalf("failed to create client: %v", err) - } - res, err := clientFactory.NewSetDefinitionsClient().GetAtManagementGroup(ctx, "CostManagement", "MyManagementGroup", nil) - if err != nil { - log.Fatalf("failed to finish the request: %v", err) - } - // You could use response here. We use blank identifier for just demo purposes. - _ = res - // If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes. - // res.SetDefinition = armpolicy.SetDefinition{ - // Name: to.Ptr("CostManagement"), - // Type: to.Ptr("Microsoft.Authorization/policySetDefinitions"), - // ID: to.Ptr("/providers/Microsoft.Management/managementgroups/MyManagementGroup/providers/Microsoft.Authorization/policySetDefinitions/CostManagement"), - // Properties: &armpolicy.SetDefinitionProperties{ - // Description: to.Ptr("Policies to enforce low cost storage SKUs"), - // DisplayName: to.Ptr("Cost Management"), - // Metadata: map[string]any{ - // "category": "Cost Management", - // }, - // PolicyDefinitions: []*armpolicy.DefinitionReference{ - // { - // Parameters: map[string]*armpolicy.ParameterValuesValue{ - // "listOfAllowedSKUs": &armpolicy.ParameterValuesValue{ - // Value: []any{ - // "Standard_GRS", - // "Standard_LRS", - // }, - // }, - // }, - // PolicyDefinitionID: to.Ptr("/providers/Microsoft.Authorization/policyDefinitions/7433c107-6db4-4ad1-b57a-a76dce0154a1"), - // PolicyDefinitionReferenceID: to.Ptr("Limit_Skus"), - // }, - // { - // Parameters: map[string]*armpolicy.ParameterValuesValue{ - // "prefix": &armpolicy.ParameterValuesValue{ - // Value: "DeptA", - // }, - // "suffix": &armpolicy.ParameterValuesValue{ - // Value: "-LC", - // }, - // }, - // PolicyDefinitionID: to.Ptr("/providers/Microsoft.Management/managementgroups/MyManagementGroup/providers/Microsoft.Authorization/policyDefinitions/ResourceNaming"), - // PolicyDefinitionReferenceID: to.Ptr("Resource_Naming"), - // }}, - // }, - // } -} - -// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/d55b8005f05b040b852c15e74a0f3e36494a15e1/specification/resources/resource-manager/Microsoft.Authorization/stable/2021-06-01/examples/listPolicySetDefinitionsByManagementGroup.json -func ExampleSetDefinitionsClient_NewListByManagementGroupPager() { - cred, err := azidentity.NewDefaultAzureCredential(nil) - if err != nil { - log.Fatalf("failed to obtain a credential: %v", err) - } - ctx := context.Background() - clientFactory, err := armpolicy.NewClientFactory("", cred, nil) - if err != nil { - log.Fatalf("failed to create client: %v", err) - } - pager := clientFactory.NewSetDefinitionsClient().NewListByManagementGroupPager("MyManagementGroup", &armpolicy.SetDefinitionsClientListByManagementGroupOptions{Filter: nil, - Top: nil, - }) - for pager.More() { - page, err := pager.NextPage(ctx) - if err != nil { - log.Fatalf("failed to advance page: %v", err) - } - for _, v := range page.Value { - // You could use page here. We use blank identifier for just demo purposes. - _ = v - } - // If the HTTP response code is 200 as defined in example definition, your page structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes. - // page.SetDefinitionListResult = armpolicy.SetDefinitionListResult{ - // Value: []*armpolicy.SetDefinition{ - // { - // Name: to.Ptr("1f3afdf9-d0c9-4c3d-847f-89da613e70a8"), - // Type: to.Ptr("Microsoft.Authorization/policySetDefinitions"), - // ID: to.Ptr("/providers/Microsoft.Authorization/policySetDefinitions/1f3afdf9-d0c9-4c3d-847f-89da613e70a8"), - // Properties: &armpolicy.SetDefinitionProperties{ - // Description: to.Ptr("Monitor all the available security recommendations in Azure Security Center. This is the default policy for Azure Security Center."), - // DisplayName: to.Ptr("[Preview]: Enable Monitoring in Azure Security Center"), - // Metadata: map[string]any{ - // "category": "Security Center", - // }, - // Parameters: map[string]*armpolicy.ParameterDefinitionsValue{ - // }, - // PolicyDefinitions: []*armpolicy.DefinitionReference{ - // { - // PolicyDefinitionID: to.Ptr("/providers/Microsoft.Authorization/policyDefinitions/a8bef009-a5c9-4d0f-90d7-6018734e8a16"), - // PolicyDefinitionReferenceID: to.Ptr("RefId1"), - // }, - // { - // PolicyDefinitionID: to.Ptr("/providers/Microsoft.Authorization/policyDefinitions/af8051bf-258b-44e2-a2bf-165330459f9d"), - // PolicyDefinitionReferenceID: to.Ptr("RefId2"), - // }, - // { - // PolicyDefinitionID: to.Ptr("/providers/Microsoft.Authorization/policyDefinitions/86b3d65f-7626-441e-b690-81a8b71cff60"), - // PolicyDefinitionReferenceID: to.Ptr("RefId3"), - // }, - // { - // PolicyDefinitionID: to.Ptr("/providers/Microsoft.Authorization/policyDefinitions/655cb504-bcee-4362-bd4c-402e6aa38759"), - // PolicyDefinitionReferenceID: to.Ptr("RefId4"), - // }, - // { - // PolicyDefinitionID: to.Ptr("/providers/Microsoft.Authorization/policyDefinitions/b0f33259-77d7-4c9e-aac6-3aabcfae693c"), - // PolicyDefinitionReferenceID: to.Ptr("RefId5"), - // }, - // { - // PolicyDefinitionID: to.Ptr("/providers/Microsoft.Authorization/policyDefinitions/47a6b606-51aa-4496-8bb7-64b11cf66adc"), - // PolicyDefinitionReferenceID: to.Ptr("RefId6"), - // }, - // { - // PolicyDefinitionID: to.Ptr("/providers/Microsoft.Authorization/policyDefinitions/44452482-524f-4bf4-b852-0bff7cc4a3ed"), - // PolicyDefinitionReferenceID: to.Ptr("RefId7"), - // }, - // { - // PolicyDefinitionID: to.Ptr("/providers/Microsoft.Authorization/policyDefinitions/e1e5fd5d-3e4c-4ce1-8661-7d1873ae6b15"), - // PolicyDefinitionReferenceID: to.Ptr("RefId8"), - // }, - // { - // PolicyDefinitionID: to.Ptr("/providers/Microsoft.Authorization/policyDefinitions/af6cd1bd-1635-48cb-bde7-5b15693900b9"), - // PolicyDefinitionReferenceID: to.Ptr("RefId9"), - // }, - // { - // PolicyDefinitionID: to.Ptr("/providers/Microsoft.Authorization/policyDefinitions/0961003e-5a0a-4549-abde-af6a37f2724d"), - // PolicyDefinitionReferenceID: to.Ptr("RefId10"), - // }}, - // PolicyType: to.Ptr(armpolicy.PolicyTypeBuiltIn), - // }, - // }, - // { - // Name: to.Ptr("CostManagement"), - // Type: to.Ptr("Microsoft.Authorization/policySetDefinitions"), - // ID: to.Ptr("/providers/Microsoft.Management/managementgroups/MyManagementGroup/providers/Microsoft.Authorization/policySetDefinitions/CostManagement"), - // Properties: &armpolicy.SetDefinitionProperties{ - // Description: to.Ptr("Policies to enforce low cost storage SKUs"), - // DisplayName: to.Ptr("Cost Management"), - // Metadata: map[string]any{ - // "category": "Cost Management", - // }, - // PolicyDefinitions: []*armpolicy.DefinitionReference{ - // { - // Parameters: map[string]*armpolicy.ParameterValuesValue{ - // "listOfAllowedSKUs": &armpolicy.ParameterValuesValue{ - // Value: []any{ - // "Standard_GRS", - // "Standard_LRS", - // }, - // }, - // }, - // PolicyDefinitionID: to.Ptr("/providers/Microsoft.Authorization/policyDefinitions/7433c107-6db4-4ad1-b57a-a76dce0154a1"), - // PolicyDefinitionReferenceID: to.Ptr("Limit_Skus"), - // }, - // { - // Parameters: map[string]*armpolicy.ParameterValuesValue{ - // "prefix": &armpolicy.ParameterValuesValue{ - // Value: "DeptA", - // }, - // "suffix": &armpolicy.ParameterValuesValue{ - // Value: "-LC", - // }, - // }, - // PolicyDefinitionID: to.Ptr("/providers/Microsoft.Management/managementgroups/MyManagementGroup/providers/Microsoft.Authorization/policyDefinitions/ResourceNaming"), - // PolicyDefinitionReferenceID: to.Ptr("Resource_Naming"), - // }}, - // }, - // }}, - // } - } -} diff --git a/sdk/resourcemanager/resources/armpolicy/variables_client.go b/sdk/resourcemanager/resources/armpolicy/variables_client.go new file mode 100644 index 000000000000..473490c3f445 --- /dev/null +++ b/sdk/resourcemanager/resources/armpolicy/variables_client.go @@ -0,0 +1,475 @@ +//go:build go1.18 +// +build go1.18 + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. +// DO NOT EDIT. + +package armpolicy + +import ( + "context" + "errors" + "github.com/Azure/azure-sdk-for-go/sdk/azcore" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/arm" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/policy" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime" + "net/http" + "net/url" + "strings" +) + +// VariablesClient contains the methods for the Variables group. +// Don't use this type directly, use NewVariablesClient() instead. +type VariablesClient struct { + internal *arm.Client + subscriptionID string +} + +// NewVariablesClient creates a new instance of VariablesClient with the specified values. +// - subscriptionID - The ID of the target subscription. +// - credential - used to authorize requests. Usually a credential from azidentity. +// - options - pass nil to accept the default values. +func NewVariablesClient(subscriptionID string, credential azcore.TokenCredential, options *arm.ClientOptions) (*VariablesClient, error) { + cl, err := arm.NewClient(moduleName+".VariablesClient", moduleVersion, credential, options) + if err != nil { + return nil, err + } + client := &VariablesClient{ + subscriptionID: subscriptionID, + internal: cl, + } + return client, nil +} + +// CreateOrUpdate - This operation creates or updates a variable with the given subscription and name. Policy variables can +// only be used by a policy definition at the scope they are created or below. +// If the operation fails it returns an *azcore.ResponseError type. +// +// Generated from API version 2022-08-01-preview +// - variableName - The name of the variable to operate on. +// - parameters - Parameters for the variable. +// - options - VariablesClientCreateOrUpdateOptions contains the optional parameters for the VariablesClient.CreateOrUpdate +// method. +func (client *VariablesClient) CreateOrUpdate(ctx context.Context, variableName string, parameters Variable, options *VariablesClientCreateOrUpdateOptions) (VariablesClientCreateOrUpdateResponse, error) { + req, err := client.createOrUpdateCreateRequest(ctx, variableName, parameters, options) + if err != nil { + return VariablesClientCreateOrUpdateResponse{}, err + } + resp, err := client.internal.Pipeline().Do(req) + if err != nil { + return VariablesClientCreateOrUpdateResponse{}, err + } + if !runtime.HasStatusCode(resp, http.StatusOK, http.StatusCreated) { + return VariablesClientCreateOrUpdateResponse{}, runtime.NewResponseError(resp) + } + return client.createOrUpdateHandleResponse(resp) +} + +// createOrUpdateCreateRequest creates the CreateOrUpdate request. +func (client *VariablesClient) createOrUpdateCreateRequest(ctx context.Context, variableName string, parameters Variable, options *VariablesClientCreateOrUpdateOptions) (*policy.Request, error) { + urlPath := "/subscriptions/{subscriptionId}/providers/Microsoft.Authorization/variables/{variableName}" + if client.subscriptionID == "" { + return nil, errors.New("parameter client.subscriptionID cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) + if variableName == "" { + return nil, errors.New("parameter variableName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{variableName}", url.PathEscape(variableName)) + req, err := runtime.NewRequest(ctx, http.MethodPut, runtime.JoinPaths(client.internal.Endpoint(), urlPath)) + if err != nil { + return nil, err + } + reqQP := req.Raw().URL.Query() + reqQP.Set("api-version", "2022-08-01-preview") + req.Raw().URL.RawQuery = reqQP.Encode() + req.Raw().Header["Accept"] = []string{"application/json"} + return req, runtime.MarshalAsJSON(req, parameters) +} + +// createOrUpdateHandleResponse handles the CreateOrUpdate response. +func (client *VariablesClient) createOrUpdateHandleResponse(resp *http.Response) (VariablesClientCreateOrUpdateResponse, error) { + result := VariablesClientCreateOrUpdateResponse{} + if err := runtime.UnmarshalAsJSON(resp, &result.Variable); err != nil { + return VariablesClientCreateOrUpdateResponse{}, err + } + return result, nil +} + +// CreateOrUpdateAtManagementGroup - This operation creates or updates a variable with the given management group and name. +// Policy variables can only be used by a policy definition at the scope they are created or below. +// If the operation fails it returns an *azcore.ResponseError type. +// +// Generated from API version 2022-08-01-preview +// - managementGroupID - The ID of the management group. +// - variableName - The name of the variable to operate on. +// - parameters - Parameters for the variable. +// - options - VariablesClientCreateOrUpdateAtManagementGroupOptions contains the optional parameters for the VariablesClient.CreateOrUpdateAtManagementGroup +// method. +func (client *VariablesClient) CreateOrUpdateAtManagementGroup(ctx context.Context, managementGroupID string, variableName string, parameters Variable, options *VariablesClientCreateOrUpdateAtManagementGroupOptions) (VariablesClientCreateOrUpdateAtManagementGroupResponse, error) { + req, err := client.createOrUpdateAtManagementGroupCreateRequest(ctx, managementGroupID, variableName, parameters, options) + if err != nil { + return VariablesClientCreateOrUpdateAtManagementGroupResponse{}, err + } + resp, err := client.internal.Pipeline().Do(req) + if err != nil { + return VariablesClientCreateOrUpdateAtManagementGroupResponse{}, err + } + if !runtime.HasStatusCode(resp, http.StatusOK, http.StatusCreated) { + return VariablesClientCreateOrUpdateAtManagementGroupResponse{}, runtime.NewResponseError(resp) + } + return client.createOrUpdateAtManagementGroupHandleResponse(resp) +} + +// createOrUpdateAtManagementGroupCreateRequest creates the CreateOrUpdateAtManagementGroup request. +func (client *VariablesClient) createOrUpdateAtManagementGroupCreateRequest(ctx context.Context, managementGroupID string, variableName string, parameters Variable, options *VariablesClientCreateOrUpdateAtManagementGroupOptions) (*policy.Request, error) { + urlPath := "/providers/Microsoft.Management/managementGroups/{managementGroupId}/providers/Microsoft.Authorization/variables/{variableName}" + if managementGroupID == "" { + return nil, errors.New("parameter managementGroupID cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{managementGroupId}", url.PathEscape(managementGroupID)) + if variableName == "" { + return nil, errors.New("parameter variableName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{variableName}", url.PathEscape(variableName)) + req, err := runtime.NewRequest(ctx, http.MethodPut, runtime.JoinPaths(client.internal.Endpoint(), urlPath)) + if err != nil { + return nil, err + } + reqQP := req.Raw().URL.Query() + reqQP.Set("api-version", "2022-08-01-preview") + req.Raw().URL.RawQuery = reqQP.Encode() + req.Raw().Header["Accept"] = []string{"application/json"} + return req, runtime.MarshalAsJSON(req, parameters) +} + +// createOrUpdateAtManagementGroupHandleResponse handles the CreateOrUpdateAtManagementGroup response. +func (client *VariablesClient) createOrUpdateAtManagementGroupHandleResponse(resp *http.Response) (VariablesClientCreateOrUpdateAtManagementGroupResponse, error) { + result := VariablesClientCreateOrUpdateAtManagementGroupResponse{} + if err := runtime.UnmarshalAsJSON(resp, &result.Variable); err != nil { + return VariablesClientCreateOrUpdateAtManagementGroupResponse{}, err + } + return result, nil +} + +// Delete - This operation deletes a variable, given its name and the subscription it was created in. The scope of a variable +// is the part of its ID preceding +// '/providers/Microsoft.Authorization/variables/{variableName}'. +// If the operation fails it returns an *azcore.ResponseError type. +// +// Generated from API version 2022-08-01-preview +// - variableName - The name of the variable to operate on. +// - options - VariablesClientDeleteOptions contains the optional parameters for the VariablesClient.Delete method. +func (client *VariablesClient) Delete(ctx context.Context, variableName string, options *VariablesClientDeleteOptions) (VariablesClientDeleteResponse, error) { + req, err := client.deleteCreateRequest(ctx, variableName, options) + if err != nil { + return VariablesClientDeleteResponse{}, err + } + resp, err := client.internal.Pipeline().Do(req) + if err != nil { + return VariablesClientDeleteResponse{}, err + } + if !runtime.HasStatusCode(resp, http.StatusOK, http.StatusNoContent) { + return VariablesClientDeleteResponse{}, runtime.NewResponseError(resp) + } + return VariablesClientDeleteResponse{}, nil +} + +// deleteCreateRequest creates the Delete request. +func (client *VariablesClient) deleteCreateRequest(ctx context.Context, variableName string, options *VariablesClientDeleteOptions) (*policy.Request, error) { + urlPath := "/subscriptions/{subscriptionId}/providers/Microsoft.Authorization/variables/{variableName}" + if client.subscriptionID == "" { + return nil, errors.New("parameter client.subscriptionID cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) + if variableName == "" { + return nil, errors.New("parameter variableName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{variableName}", url.PathEscape(variableName)) + req, err := runtime.NewRequest(ctx, http.MethodDelete, runtime.JoinPaths(client.internal.Endpoint(), urlPath)) + if err != nil { + return nil, err + } + reqQP := req.Raw().URL.Query() + reqQP.Set("api-version", "2022-08-01-preview") + req.Raw().URL.RawQuery = reqQP.Encode() + req.Raw().Header["Accept"] = []string{"application/json"} + return req, nil +} + +// DeleteAtManagementGroup - This operation deletes a variable, given its name and the management group it was created in. +// The scope of a variable is the part of its ID preceding +// '/providers/Microsoft.Authorization/variables/{variableName}'. +// If the operation fails it returns an *azcore.ResponseError type. +// +// Generated from API version 2022-08-01-preview +// - managementGroupID - The ID of the management group. +// - variableName - The name of the variable to operate on. +// - options - VariablesClientDeleteAtManagementGroupOptions contains the optional parameters for the VariablesClient.DeleteAtManagementGroup +// method. +func (client *VariablesClient) DeleteAtManagementGroup(ctx context.Context, managementGroupID string, variableName string, options *VariablesClientDeleteAtManagementGroupOptions) (VariablesClientDeleteAtManagementGroupResponse, error) { + req, err := client.deleteAtManagementGroupCreateRequest(ctx, managementGroupID, variableName, options) + if err != nil { + return VariablesClientDeleteAtManagementGroupResponse{}, err + } + resp, err := client.internal.Pipeline().Do(req) + if err != nil { + return VariablesClientDeleteAtManagementGroupResponse{}, err + } + if !runtime.HasStatusCode(resp, http.StatusOK, http.StatusNoContent) { + return VariablesClientDeleteAtManagementGroupResponse{}, runtime.NewResponseError(resp) + } + return VariablesClientDeleteAtManagementGroupResponse{}, nil +} + +// deleteAtManagementGroupCreateRequest creates the DeleteAtManagementGroup request. +func (client *VariablesClient) deleteAtManagementGroupCreateRequest(ctx context.Context, managementGroupID string, variableName string, options *VariablesClientDeleteAtManagementGroupOptions) (*policy.Request, error) { + urlPath := "/providers/Microsoft.Management/managementGroups/{managementGroupId}/providers/Microsoft.Authorization/variables/{variableName}" + if managementGroupID == "" { + return nil, errors.New("parameter managementGroupID cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{managementGroupId}", url.PathEscape(managementGroupID)) + if variableName == "" { + return nil, errors.New("parameter variableName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{variableName}", url.PathEscape(variableName)) + req, err := runtime.NewRequest(ctx, http.MethodDelete, runtime.JoinPaths(client.internal.Endpoint(), urlPath)) + if err != nil { + return nil, err + } + reqQP := req.Raw().URL.Query() + reqQP.Set("api-version", "2022-08-01-preview") + req.Raw().URL.RawQuery = reqQP.Encode() + req.Raw().Header["Accept"] = []string{"application/json"} + return req, nil +} + +// Get - This operation retrieves a single variable, given its name and the subscription it was created at. +// If the operation fails it returns an *azcore.ResponseError type. +// +// Generated from API version 2022-08-01-preview +// - variableName - The name of the variable to operate on. +// - options - VariablesClientGetOptions contains the optional parameters for the VariablesClient.Get method. +func (client *VariablesClient) Get(ctx context.Context, variableName string, options *VariablesClientGetOptions) (VariablesClientGetResponse, error) { + req, err := client.getCreateRequest(ctx, variableName, options) + if err != nil { + return VariablesClientGetResponse{}, err + } + resp, err := client.internal.Pipeline().Do(req) + if err != nil { + return VariablesClientGetResponse{}, err + } + if !runtime.HasStatusCode(resp, http.StatusOK) { + return VariablesClientGetResponse{}, runtime.NewResponseError(resp) + } + return client.getHandleResponse(resp) +} + +// getCreateRequest creates the Get request. +func (client *VariablesClient) getCreateRequest(ctx context.Context, variableName string, options *VariablesClientGetOptions) (*policy.Request, error) { + urlPath := "/subscriptions/{subscriptionId}/providers/Microsoft.Authorization/variables/{variableName}" + if client.subscriptionID == "" { + return nil, errors.New("parameter client.subscriptionID cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) + if variableName == "" { + return nil, errors.New("parameter variableName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{variableName}", url.PathEscape(variableName)) + req, err := runtime.NewRequest(ctx, http.MethodGet, runtime.JoinPaths(client.internal.Endpoint(), urlPath)) + if err != nil { + return nil, err + } + reqQP := req.Raw().URL.Query() + reqQP.Set("api-version", "2022-08-01-preview") + req.Raw().URL.RawQuery = reqQP.Encode() + req.Raw().Header["Accept"] = []string{"application/json"} + return req, nil +} + +// getHandleResponse handles the Get response. +func (client *VariablesClient) getHandleResponse(resp *http.Response) (VariablesClientGetResponse, error) { + result := VariablesClientGetResponse{} + if err := runtime.UnmarshalAsJSON(resp, &result.Variable); err != nil { + return VariablesClientGetResponse{}, err + } + return result, nil +} + +// GetAtManagementGroup - This operation retrieves a single variable, given its name and the management group it was created +// at. +// If the operation fails it returns an *azcore.ResponseError type. +// +// Generated from API version 2022-08-01-preview +// - managementGroupID - The ID of the management group. +// - variableName - The name of the variable to operate on. +// - options - VariablesClientGetAtManagementGroupOptions contains the optional parameters for the VariablesClient.GetAtManagementGroup +// method. +func (client *VariablesClient) GetAtManagementGroup(ctx context.Context, managementGroupID string, variableName string, options *VariablesClientGetAtManagementGroupOptions) (VariablesClientGetAtManagementGroupResponse, error) { + req, err := client.getAtManagementGroupCreateRequest(ctx, managementGroupID, variableName, options) + if err != nil { + return VariablesClientGetAtManagementGroupResponse{}, err + } + resp, err := client.internal.Pipeline().Do(req) + if err != nil { + return VariablesClientGetAtManagementGroupResponse{}, err + } + if !runtime.HasStatusCode(resp, http.StatusOK) { + return VariablesClientGetAtManagementGroupResponse{}, runtime.NewResponseError(resp) + } + return client.getAtManagementGroupHandleResponse(resp) +} + +// getAtManagementGroupCreateRequest creates the GetAtManagementGroup request. +func (client *VariablesClient) getAtManagementGroupCreateRequest(ctx context.Context, managementGroupID string, variableName string, options *VariablesClientGetAtManagementGroupOptions) (*policy.Request, error) { + urlPath := "/providers/Microsoft.Management/managementGroups/{managementGroupId}/providers/Microsoft.Authorization/variables/{variableName}" + if managementGroupID == "" { + return nil, errors.New("parameter managementGroupID cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{managementGroupId}", url.PathEscape(managementGroupID)) + if variableName == "" { + return nil, errors.New("parameter variableName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{variableName}", url.PathEscape(variableName)) + req, err := runtime.NewRequest(ctx, http.MethodGet, runtime.JoinPaths(client.internal.Endpoint(), urlPath)) + if err != nil { + return nil, err + } + reqQP := req.Raw().URL.Query() + reqQP.Set("api-version", "2022-08-01-preview") + req.Raw().URL.RawQuery = reqQP.Encode() + req.Raw().Header["Accept"] = []string{"application/json"} + return req, nil +} + +// getAtManagementGroupHandleResponse handles the GetAtManagementGroup response. +func (client *VariablesClient) getAtManagementGroupHandleResponse(resp *http.Response) (VariablesClientGetAtManagementGroupResponse, error) { + result := VariablesClientGetAtManagementGroupResponse{} + if err := runtime.UnmarshalAsJSON(resp, &result.Variable); err != nil { + return VariablesClientGetAtManagementGroupResponse{}, err + } + return result, nil +} + +// NewListPager - This operation retrieves the list of all variables associated with the given subscription. +// +// Generated from API version 2022-08-01-preview +// - options - VariablesClientListOptions contains the optional parameters for the VariablesClient.NewListPager method. +func (client *VariablesClient) NewListPager(options *VariablesClientListOptions) *runtime.Pager[VariablesClientListResponse] { + return runtime.NewPager(runtime.PagingHandler[VariablesClientListResponse]{ + More: func(page VariablesClientListResponse) bool { + return page.NextLink != nil && len(*page.NextLink) > 0 + }, + Fetcher: func(ctx context.Context, page *VariablesClientListResponse) (VariablesClientListResponse, error) { + var req *policy.Request + var err error + if page == nil { + req, err = client.listCreateRequest(ctx, options) + } else { + req, err = runtime.NewRequest(ctx, http.MethodGet, *page.NextLink) + } + if err != nil { + return VariablesClientListResponse{}, err + } + resp, err := client.internal.Pipeline().Do(req) + if err != nil { + return VariablesClientListResponse{}, err + } + if !runtime.HasStatusCode(resp, http.StatusOK) { + return VariablesClientListResponse{}, runtime.NewResponseError(resp) + } + return client.listHandleResponse(resp) + }, + }) +} + +// listCreateRequest creates the List request. +func (client *VariablesClient) listCreateRequest(ctx context.Context, options *VariablesClientListOptions) (*policy.Request, error) { + urlPath := "/subscriptions/{subscriptionId}/providers/Microsoft.Authorization/variables" + if client.subscriptionID == "" { + return nil, errors.New("parameter client.subscriptionID cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) + req, err := runtime.NewRequest(ctx, http.MethodGet, runtime.JoinPaths(client.internal.Endpoint(), urlPath)) + if err != nil { + return nil, err + } + reqQP := req.Raw().URL.Query() + reqQP.Set("api-version", "2022-08-01-preview") + req.Raw().URL.RawQuery = reqQP.Encode() + req.Raw().Header["Accept"] = []string{"application/json"} + return req, nil +} + +// listHandleResponse handles the List response. +func (client *VariablesClient) listHandleResponse(resp *http.Response) (VariablesClientListResponse, error) { + result := VariablesClientListResponse{} + if err := runtime.UnmarshalAsJSON(resp, &result.VariableListResult); err != nil { + return VariablesClientListResponse{}, err + } + return result, nil +} + +// NewListForManagementGroupPager - This operation retrieves the list of all variables applicable to the management group. +// +// Generated from API version 2022-08-01-preview +// - managementGroupID - The ID of the management group. +// - options - VariablesClientListForManagementGroupOptions contains the optional parameters for the VariablesClient.NewListForManagementGroupPager +// method. +func (client *VariablesClient) NewListForManagementGroupPager(managementGroupID string, options *VariablesClientListForManagementGroupOptions) *runtime.Pager[VariablesClientListForManagementGroupResponse] { + return runtime.NewPager(runtime.PagingHandler[VariablesClientListForManagementGroupResponse]{ + More: func(page VariablesClientListForManagementGroupResponse) bool { + return page.NextLink != nil && len(*page.NextLink) > 0 + }, + Fetcher: func(ctx context.Context, page *VariablesClientListForManagementGroupResponse) (VariablesClientListForManagementGroupResponse, error) { + var req *policy.Request + var err error + if page == nil { + req, err = client.listForManagementGroupCreateRequest(ctx, managementGroupID, options) + } else { + req, err = runtime.NewRequest(ctx, http.MethodGet, *page.NextLink) + } + if err != nil { + return VariablesClientListForManagementGroupResponse{}, err + } + resp, err := client.internal.Pipeline().Do(req) + if err != nil { + return VariablesClientListForManagementGroupResponse{}, err + } + if !runtime.HasStatusCode(resp, http.StatusOK) { + return VariablesClientListForManagementGroupResponse{}, runtime.NewResponseError(resp) + } + return client.listForManagementGroupHandleResponse(resp) + }, + }) +} + +// listForManagementGroupCreateRequest creates the ListForManagementGroup request. +func (client *VariablesClient) listForManagementGroupCreateRequest(ctx context.Context, managementGroupID string, options *VariablesClientListForManagementGroupOptions) (*policy.Request, error) { + urlPath := "/providers/Microsoft.Management/managementGroups/{managementGroupId}/providers/Microsoft.Authorization/variables" + if managementGroupID == "" { + return nil, errors.New("parameter managementGroupID cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{managementGroupId}", url.PathEscape(managementGroupID)) + req, err := runtime.NewRequest(ctx, http.MethodGet, runtime.JoinPaths(client.internal.Endpoint(), urlPath)) + if err != nil { + return nil, err + } + reqQP := req.Raw().URL.Query() + reqQP.Set("api-version", "2022-08-01-preview") + req.Raw().URL.RawQuery = reqQP.Encode() + req.Raw().Header["Accept"] = []string{"application/json"} + return req, nil +} + +// listForManagementGroupHandleResponse handles the ListForManagementGroup response. +func (client *VariablesClient) listForManagementGroupHandleResponse(resp *http.Response) (VariablesClientListForManagementGroupResponse, error) { + result := VariablesClientListForManagementGroupResponse{} + if err := runtime.UnmarshalAsJSON(resp, &result.VariableListResult); err != nil { + return VariablesClientListForManagementGroupResponse{}, err + } + return result, nil +} diff --git a/sdk/resourcemanager/resources/armpolicy/variablevalues_client.go b/sdk/resourcemanager/resources/armpolicy/variablevalues_client.go new file mode 100644 index 000000000000..45b55e51d9c4 --- /dev/null +++ b/sdk/resourcemanager/resources/armpolicy/variablevalues_client.go @@ -0,0 +1,518 @@ +//go:build go1.18 +// +build go1.18 + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. +// DO NOT EDIT. + +package armpolicy + +import ( + "context" + "errors" + "github.com/Azure/azure-sdk-for-go/sdk/azcore" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/arm" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/policy" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime" + "net/http" + "net/url" + "strings" +) + +// VariableValuesClient contains the methods for the VariableValues group. +// Don't use this type directly, use NewVariableValuesClient() instead. +type VariableValuesClient struct { + internal *arm.Client + subscriptionID string +} + +// NewVariableValuesClient creates a new instance of VariableValuesClient with the specified values. +// - subscriptionID - The ID of the target subscription. +// - credential - used to authorize requests. Usually a credential from azidentity. +// - options - pass nil to accept the default values. +func NewVariableValuesClient(subscriptionID string, credential azcore.TokenCredential, options *arm.ClientOptions) (*VariableValuesClient, error) { + cl, err := arm.NewClient(moduleName+".VariableValuesClient", moduleVersion, credential, options) + if err != nil { + return nil, err + } + client := &VariableValuesClient{ + subscriptionID: subscriptionID, + internal: cl, + } + return client, nil +} + +// CreateOrUpdate - This operation creates or updates a variable value with the given subscription and name for a given variable. +// Variable values are scoped to the variable for which they are created for. +// If the operation fails it returns an *azcore.ResponseError type. +// +// Generated from API version 2022-08-01-preview +// - variableName - The name of the variable to operate on. +// - variableValueName - The name of the variable value to operate on. +// - parameters - Parameters for the variable value. +// - options - VariableValuesClientCreateOrUpdateOptions contains the optional parameters for the VariableValuesClient.CreateOrUpdate +// method. +func (client *VariableValuesClient) CreateOrUpdate(ctx context.Context, variableName string, variableValueName string, parameters VariableValue, options *VariableValuesClientCreateOrUpdateOptions) (VariableValuesClientCreateOrUpdateResponse, error) { + req, err := client.createOrUpdateCreateRequest(ctx, variableName, variableValueName, parameters, options) + if err != nil { + return VariableValuesClientCreateOrUpdateResponse{}, err + } + resp, err := client.internal.Pipeline().Do(req) + if err != nil { + return VariableValuesClientCreateOrUpdateResponse{}, err + } + if !runtime.HasStatusCode(resp, http.StatusOK, http.StatusCreated) { + return VariableValuesClientCreateOrUpdateResponse{}, runtime.NewResponseError(resp) + } + return client.createOrUpdateHandleResponse(resp) +} + +// createOrUpdateCreateRequest creates the CreateOrUpdate request. +func (client *VariableValuesClient) createOrUpdateCreateRequest(ctx context.Context, variableName string, variableValueName string, parameters VariableValue, options *VariableValuesClientCreateOrUpdateOptions) (*policy.Request, error) { + urlPath := "/subscriptions/{subscriptionId}/providers/Microsoft.Authorization/variables/{variableName}/values/{variableValueName}" + if client.subscriptionID == "" { + return nil, errors.New("parameter client.subscriptionID cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) + if variableName == "" { + return nil, errors.New("parameter variableName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{variableName}", url.PathEscape(variableName)) + if variableValueName == "" { + return nil, errors.New("parameter variableValueName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{variableValueName}", url.PathEscape(variableValueName)) + req, err := runtime.NewRequest(ctx, http.MethodPut, runtime.JoinPaths(client.internal.Endpoint(), urlPath)) + if err != nil { + return nil, err + } + reqQP := req.Raw().URL.Query() + reqQP.Set("api-version", "2022-08-01-preview") + req.Raw().URL.RawQuery = reqQP.Encode() + req.Raw().Header["Accept"] = []string{"application/json"} + return req, runtime.MarshalAsJSON(req, parameters) +} + +// createOrUpdateHandleResponse handles the CreateOrUpdate response. +func (client *VariableValuesClient) createOrUpdateHandleResponse(resp *http.Response) (VariableValuesClientCreateOrUpdateResponse, error) { + result := VariableValuesClientCreateOrUpdateResponse{} + if err := runtime.UnmarshalAsJSON(resp, &result.VariableValue); err != nil { + return VariableValuesClientCreateOrUpdateResponse{}, err + } + return result, nil +} + +// CreateOrUpdateAtManagementGroup - This operation creates or updates a variable value with the given management group and +// name for a given variable. Variable values are scoped to the variable for which they are created for. +// If the operation fails it returns an *azcore.ResponseError type. +// +// Generated from API version 2022-08-01-preview +// - managementGroupID - The ID of the management group. +// - variableName - The name of the variable to operate on. +// - variableValueName - The name of the variable value to operate on. +// - parameters - Parameters for the variable value. +// - options - VariableValuesClientCreateOrUpdateAtManagementGroupOptions contains the optional parameters for the VariableValuesClient.CreateOrUpdateAtManagementGroup +// method. +func (client *VariableValuesClient) CreateOrUpdateAtManagementGroup(ctx context.Context, managementGroupID string, variableName string, variableValueName string, parameters VariableValue, options *VariableValuesClientCreateOrUpdateAtManagementGroupOptions) (VariableValuesClientCreateOrUpdateAtManagementGroupResponse, error) { + req, err := client.createOrUpdateAtManagementGroupCreateRequest(ctx, managementGroupID, variableName, variableValueName, parameters, options) + if err != nil { + return VariableValuesClientCreateOrUpdateAtManagementGroupResponse{}, err + } + resp, err := client.internal.Pipeline().Do(req) + if err != nil { + return VariableValuesClientCreateOrUpdateAtManagementGroupResponse{}, err + } + if !runtime.HasStatusCode(resp, http.StatusOK, http.StatusCreated) { + return VariableValuesClientCreateOrUpdateAtManagementGroupResponse{}, runtime.NewResponseError(resp) + } + return client.createOrUpdateAtManagementGroupHandleResponse(resp) +} + +// createOrUpdateAtManagementGroupCreateRequest creates the CreateOrUpdateAtManagementGroup request. +func (client *VariableValuesClient) createOrUpdateAtManagementGroupCreateRequest(ctx context.Context, managementGroupID string, variableName string, variableValueName string, parameters VariableValue, options *VariableValuesClientCreateOrUpdateAtManagementGroupOptions) (*policy.Request, error) { + urlPath := "/providers/Microsoft.Management/managementGroups/{managementGroupId}/providers/Microsoft.Authorization/variables/{variableName}/values/{variableValueName}" + if managementGroupID == "" { + return nil, errors.New("parameter managementGroupID cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{managementGroupId}", url.PathEscape(managementGroupID)) + if variableName == "" { + return nil, errors.New("parameter variableName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{variableName}", url.PathEscape(variableName)) + if variableValueName == "" { + return nil, errors.New("parameter variableValueName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{variableValueName}", url.PathEscape(variableValueName)) + req, err := runtime.NewRequest(ctx, http.MethodPut, runtime.JoinPaths(client.internal.Endpoint(), urlPath)) + if err != nil { + return nil, err + } + reqQP := req.Raw().URL.Query() + reqQP.Set("api-version", "2022-08-01-preview") + req.Raw().URL.RawQuery = reqQP.Encode() + req.Raw().Header["Accept"] = []string{"application/json"} + return req, runtime.MarshalAsJSON(req, parameters) +} + +// createOrUpdateAtManagementGroupHandleResponse handles the CreateOrUpdateAtManagementGroup response. +func (client *VariableValuesClient) createOrUpdateAtManagementGroupHandleResponse(resp *http.Response) (VariableValuesClientCreateOrUpdateAtManagementGroupResponse, error) { + result := VariableValuesClientCreateOrUpdateAtManagementGroupResponse{} + if err := runtime.UnmarshalAsJSON(resp, &result.VariableValue); err != nil { + return VariableValuesClientCreateOrUpdateAtManagementGroupResponse{}, err + } + return result, nil +} + +// Delete - This operation deletes a variable value, given its name, the subscription it was created in, and the variable +// it belongs to. The scope of a variable value is the part of its ID preceding +// '/providers/Microsoft.Authorization/variables/{variableName}'. +// If the operation fails it returns an *azcore.ResponseError type. +// +// Generated from API version 2022-08-01-preview +// - variableName - The name of the variable to operate on. +// - variableValueName - The name of the variable value to operate on. +// - options - VariableValuesClientDeleteOptions contains the optional parameters for the VariableValuesClient.Delete method. +func (client *VariableValuesClient) Delete(ctx context.Context, variableName string, variableValueName string, options *VariableValuesClientDeleteOptions) (VariableValuesClientDeleteResponse, error) { + req, err := client.deleteCreateRequest(ctx, variableName, variableValueName, options) + if err != nil { + return VariableValuesClientDeleteResponse{}, err + } + resp, err := client.internal.Pipeline().Do(req) + if err != nil { + return VariableValuesClientDeleteResponse{}, err + } + if !runtime.HasStatusCode(resp, http.StatusOK, http.StatusNoContent) { + return VariableValuesClientDeleteResponse{}, runtime.NewResponseError(resp) + } + return VariableValuesClientDeleteResponse{}, nil +} + +// deleteCreateRequest creates the Delete request. +func (client *VariableValuesClient) deleteCreateRequest(ctx context.Context, variableName string, variableValueName string, options *VariableValuesClientDeleteOptions) (*policy.Request, error) { + urlPath := "/subscriptions/{subscriptionId}/providers/Microsoft.Authorization/variables/{variableName}/values/{variableValueName}" + if client.subscriptionID == "" { + return nil, errors.New("parameter client.subscriptionID cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) + if variableName == "" { + return nil, errors.New("parameter variableName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{variableName}", url.PathEscape(variableName)) + if variableValueName == "" { + return nil, errors.New("parameter variableValueName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{variableValueName}", url.PathEscape(variableValueName)) + req, err := runtime.NewRequest(ctx, http.MethodDelete, runtime.JoinPaths(client.internal.Endpoint(), urlPath)) + if err != nil { + return nil, err + } + reqQP := req.Raw().URL.Query() + reqQP.Set("api-version", "2022-08-01-preview") + req.Raw().URL.RawQuery = reqQP.Encode() + req.Raw().Header["Accept"] = []string{"application/json"} + return req, nil +} + +// DeleteAtManagementGroup - This operation deletes a variable value, given its name, the management group it was created +// in, and the variable it belongs to. The scope of a variable value is the part of its ID preceding +// '/providers/Microsoft.Authorization/variables/{variableName}'. +// If the operation fails it returns an *azcore.ResponseError type. +// +// Generated from API version 2022-08-01-preview +// - managementGroupID - The ID of the management group. +// - variableName - The name of the variable to operate on. +// - variableValueName - The name of the variable value to operate on. +// - options - VariableValuesClientDeleteAtManagementGroupOptions contains the optional parameters for the VariableValuesClient.DeleteAtManagementGroup +// method. +func (client *VariableValuesClient) DeleteAtManagementGroup(ctx context.Context, managementGroupID string, variableName string, variableValueName string, options *VariableValuesClientDeleteAtManagementGroupOptions) (VariableValuesClientDeleteAtManagementGroupResponse, error) { + req, err := client.deleteAtManagementGroupCreateRequest(ctx, managementGroupID, variableName, variableValueName, options) + if err != nil { + return VariableValuesClientDeleteAtManagementGroupResponse{}, err + } + resp, err := client.internal.Pipeline().Do(req) + if err != nil { + return VariableValuesClientDeleteAtManagementGroupResponse{}, err + } + if !runtime.HasStatusCode(resp, http.StatusOK, http.StatusNoContent) { + return VariableValuesClientDeleteAtManagementGroupResponse{}, runtime.NewResponseError(resp) + } + return VariableValuesClientDeleteAtManagementGroupResponse{}, nil +} + +// deleteAtManagementGroupCreateRequest creates the DeleteAtManagementGroup request. +func (client *VariableValuesClient) deleteAtManagementGroupCreateRequest(ctx context.Context, managementGroupID string, variableName string, variableValueName string, options *VariableValuesClientDeleteAtManagementGroupOptions) (*policy.Request, error) { + urlPath := "/providers/Microsoft.Management/managementGroups/{managementGroupId}/providers/Microsoft.Authorization/variables/{variableName}/values/{variableValueName}" + if managementGroupID == "" { + return nil, errors.New("parameter managementGroupID cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{managementGroupId}", url.PathEscape(managementGroupID)) + if variableName == "" { + return nil, errors.New("parameter variableName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{variableName}", url.PathEscape(variableName)) + if variableValueName == "" { + return nil, errors.New("parameter variableValueName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{variableValueName}", url.PathEscape(variableValueName)) + req, err := runtime.NewRequest(ctx, http.MethodDelete, runtime.JoinPaths(client.internal.Endpoint(), urlPath)) + if err != nil { + return nil, err + } + reqQP := req.Raw().URL.Query() + reqQP.Set("api-version", "2022-08-01-preview") + req.Raw().URL.RawQuery = reqQP.Encode() + req.Raw().Header["Accept"] = []string{"application/json"} + return req, nil +} + +// Get - This operation retrieves a single variable value; given its name, subscription it was created at and the variable +// it's created for. +// If the operation fails it returns an *azcore.ResponseError type. +// +// Generated from API version 2022-08-01-preview +// - variableName - The name of the variable to operate on. +// - variableValueName - The name of the variable value to operate on. +// - options - VariableValuesClientGetOptions contains the optional parameters for the VariableValuesClient.Get method. +func (client *VariableValuesClient) Get(ctx context.Context, variableName string, variableValueName string, options *VariableValuesClientGetOptions) (VariableValuesClientGetResponse, error) { + req, err := client.getCreateRequest(ctx, variableName, variableValueName, options) + if err != nil { + return VariableValuesClientGetResponse{}, err + } + resp, err := client.internal.Pipeline().Do(req) + if err != nil { + return VariableValuesClientGetResponse{}, err + } + if !runtime.HasStatusCode(resp, http.StatusOK) { + return VariableValuesClientGetResponse{}, runtime.NewResponseError(resp) + } + return client.getHandleResponse(resp) +} + +// getCreateRequest creates the Get request. +func (client *VariableValuesClient) getCreateRequest(ctx context.Context, variableName string, variableValueName string, options *VariableValuesClientGetOptions) (*policy.Request, error) { + urlPath := "/subscriptions/{subscriptionId}/providers/Microsoft.Authorization/variables/{variableName}/values/{variableValueName}" + if client.subscriptionID == "" { + return nil, errors.New("parameter client.subscriptionID cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) + if variableName == "" { + return nil, errors.New("parameter variableName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{variableName}", url.PathEscape(variableName)) + if variableValueName == "" { + return nil, errors.New("parameter variableValueName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{variableValueName}", url.PathEscape(variableValueName)) + req, err := runtime.NewRequest(ctx, http.MethodGet, runtime.JoinPaths(client.internal.Endpoint(), urlPath)) + if err != nil { + return nil, err + } + reqQP := req.Raw().URL.Query() + reqQP.Set("api-version", "2022-08-01-preview") + req.Raw().URL.RawQuery = reqQP.Encode() + req.Raw().Header["Accept"] = []string{"application/json"} + return req, nil +} + +// getHandleResponse handles the Get response. +func (client *VariableValuesClient) getHandleResponse(resp *http.Response) (VariableValuesClientGetResponse, error) { + result := VariableValuesClientGetResponse{} + if err := runtime.UnmarshalAsJSON(resp, &result.VariableValue); err != nil { + return VariableValuesClientGetResponse{}, err + } + return result, nil +} + +// GetAtManagementGroup - This operation retrieves a single variable value; given its name, management group it was created +// at and the variable it's created for. +// If the operation fails it returns an *azcore.ResponseError type. +// +// Generated from API version 2022-08-01-preview +// - managementGroupID - The ID of the management group. +// - variableName - The name of the variable to operate on. +// - variableValueName - The name of the variable value to operate on. +// - options - VariableValuesClientGetAtManagementGroupOptions contains the optional parameters for the VariableValuesClient.GetAtManagementGroup +// method. +func (client *VariableValuesClient) GetAtManagementGroup(ctx context.Context, managementGroupID string, variableName string, variableValueName string, options *VariableValuesClientGetAtManagementGroupOptions) (VariableValuesClientGetAtManagementGroupResponse, error) { + req, err := client.getAtManagementGroupCreateRequest(ctx, managementGroupID, variableName, variableValueName, options) + if err != nil { + return VariableValuesClientGetAtManagementGroupResponse{}, err + } + resp, err := client.internal.Pipeline().Do(req) + if err != nil { + return VariableValuesClientGetAtManagementGroupResponse{}, err + } + if !runtime.HasStatusCode(resp, http.StatusOK) { + return VariableValuesClientGetAtManagementGroupResponse{}, runtime.NewResponseError(resp) + } + return client.getAtManagementGroupHandleResponse(resp) +} + +// getAtManagementGroupCreateRequest creates the GetAtManagementGroup request. +func (client *VariableValuesClient) getAtManagementGroupCreateRequest(ctx context.Context, managementGroupID string, variableName string, variableValueName string, options *VariableValuesClientGetAtManagementGroupOptions) (*policy.Request, error) { + urlPath := "/providers/Microsoft.Management/managementGroups/{managementGroupId}/providers/Microsoft.Authorization/variables/{variableName}/values/{variableValueName}" + if managementGroupID == "" { + return nil, errors.New("parameter managementGroupID cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{managementGroupId}", url.PathEscape(managementGroupID)) + if variableName == "" { + return nil, errors.New("parameter variableName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{variableName}", url.PathEscape(variableName)) + if variableValueName == "" { + return nil, errors.New("parameter variableValueName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{variableValueName}", url.PathEscape(variableValueName)) + req, err := runtime.NewRequest(ctx, http.MethodGet, runtime.JoinPaths(client.internal.Endpoint(), urlPath)) + if err != nil { + return nil, err + } + reqQP := req.Raw().URL.Query() + reqQP.Set("api-version", "2022-08-01-preview") + req.Raw().URL.RawQuery = reqQP.Encode() + req.Raw().Header["Accept"] = []string{"application/json"} + return req, nil +} + +// getAtManagementGroupHandleResponse handles the GetAtManagementGroup response. +func (client *VariableValuesClient) getAtManagementGroupHandleResponse(resp *http.Response) (VariableValuesClientGetAtManagementGroupResponse, error) { + result := VariableValuesClientGetAtManagementGroupResponse{} + if err := runtime.UnmarshalAsJSON(resp, &result.VariableValue); err != nil { + return VariableValuesClientGetAtManagementGroupResponse{}, err + } + return result, nil +} + +// NewListPager - This operation retrieves the list of all variable values associated with the given variable that is at a +// subscription level. +// +// Generated from API version 2022-08-01-preview +// - variableName - The name of the variable to operate on. +// - options - VariableValuesClientListOptions contains the optional parameters for the VariableValuesClient.NewListPager method. +func (client *VariableValuesClient) NewListPager(variableName string, options *VariableValuesClientListOptions) *runtime.Pager[VariableValuesClientListResponse] { + return runtime.NewPager(runtime.PagingHandler[VariableValuesClientListResponse]{ + More: func(page VariableValuesClientListResponse) bool { + return page.NextLink != nil && len(*page.NextLink) > 0 + }, + Fetcher: func(ctx context.Context, page *VariableValuesClientListResponse) (VariableValuesClientListResponse, error) { + var req *policy.Request + var err error + if page == nil { + req, err = client.listCreateRequest(ctx, variableName, options) + } else { + req, err = runtime.NewRequest(ctx, http.MethodGet, *page.NextLink) + } + if err != nil { + return VariableValuesClientListResponse{}, err + } + resp, err := client.internal.Pipeline().Do(req) + if err != nil { + return VariableValuesClientListResponse{}, err + } + if !runtime.HasStatusCode(resp, http.StatusOK) { + return VariableValuesClientListResponse{}, runtime.NewResponseError(resp) + } + return client.listHandleResponse(resp) + }, + }) +} + +// listCreateRequest creates the List request. +func (client *VariableValuesClient) listCreateRequest(ctx context.Context, variableName string, options *VariableValuesClientListOptions) (*policy.Request, error) { + urlPath := "/subscriptions/{subscriptionId}/providers/Microsoft.Authorization/variables/{variableName}/values" + if client.subscriptionID == "" { + return nil, errors.New("parameter client.subscriptionID cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) + if variableName == "" { + return nil, errors.New("parameter variableName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{variableName}", url.PathEscape(variableName)) + req, err := runtime.NewRequest(ctx, http.MethodGet, runtime.JoinPaths(client.internal.Endpoint(), urlPath)) + if err != nil { + return nil, err + } + reqQP := req.Raw().URL.Query() + reqQP.Set("api-version", "2022-08-01-preview") + req.Raw().URL.RawQuery = reqQP.Encode() + req.Raw().Header["Accept"] = []string{"application/json"} + return req, nil +} + +// listHandleResponse handles the List response. +func (client *VariableValuesClient) listHandleResponse(resp *http.Response) (VariableValuesClientListResponse, error) { + result := VariableValuesClientListResponse{} + if err := runtime.UnmarshalAsJSON(resp, &result.VariableValueListResult); err != nil { + return VariableValuesClientListResponse{}, err + } + return result, nil +} + +// NewListForManagementGroupPager - This operation retrieves the list of all variable values applicable the variable indicated +// at the management group scope. +// +// Generated from API version 2022-08-01-preview +// - managementGroupID - The ID of the management group. +// - variableName - The name of the variable to operate on. +// - options - VariableValuesClientListForManagementGroupOptions contains the optional parameters for the VariableValuesClient.NewListForManagementGroupPager +// method. +func (client *VariableValuesClient) NewListForManagementGroupPager(managementGroupID string, variableName string, options *VariableValuesClientListForManagementGroupOptions) *runtime.Pager[VariableValuesClientListForManagementGroupResponse] { + return runtime.NewPager(runtime.PagingHandler[VariableValuesClientListForManagementGroupResponse]{ + More: func(page VariableValuesClientListForManagementGroupResponse) bool { + return page.NextLink != nil && len(*page.NextLink) > 0 + }, + Fetcher: func(ctx context.Context, page *VariableValuesClientListForManagementGroupResponse) (VariableValuesClientListForManagementGroupResponse, error) { + var req *policy.Request + var err error + if page == nil { + req, err = client.listForManagementGroupCreateRequest(ctx, managementGroupID, variableName, options) + } else { + req, err = runtime.NewRequest(ctx, http.MethodGet, *page.NextLink) + } + if err != nil { + return VariableValuesClientListForManagementGroupResponse{}, err + } + resp, err := client.internal.Pipeline().Do(req) + if err != nil { + return VariableValuesClientListForManagementGroupResponse{}, err + } + if !runtime.HasStatusCode(resp, http.StatusOK) { + return VariableValuesClientListForManagementGroupResponse{}, runtime.NewResponseError(resp) + } + return client.listForManagementGroupHandleResponse(resp) + }, + }) +} + +// listForManagementGroupCreateRequest creates the ListForManagementGroup request. +func (client *VariableValuesClient) listForManagementGroupCreateRequest(ctx context.Context, managementGroupID string, variableName string, options *VariableValuesClientListForManagementGroupOptions) (*policy.Request, error) { + urlPath := "/providers/Microsoft.Management/managementGroups/{managementGroupId}/providers/Microsoft.Authorization/variables/{variableName}/values" + if managementGroupID == "" { + return nil, errors.New("parameter managementGroupID cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{managementGroupId}", url.PathEscape(managementGroupID)) + if variableName == "" { + return nil, errors.New("parameter variableName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{variableName}", url.PathEscape(variableName)) + req, err := runtime.NewRequest(ctx, http.MethodGet, runtime.JoinPaths(client.internal.Endpoint(), urlPath)) + if err != nil { + return nil, err + } + reqQP := req.Raw().URL.Query() + reqQP.Set("api-version", "2022-08-01-preview") + req.Raw().URL.RawQuery = reqQP.Encode() + req.Raw().Header["Accept"] = []string{"application/json"} + return req, nil +} + +// listForManagementGroupHandleResponse handles the ListForManagementGroup response. +func (client *VariableValuesClient) listForManagementGroupHandleResponse(resp *http.Response) (VariableValuesClientListForManagementGroupResponse, error) { + result := VariableValuesClientListForManagementGroupResponse{} + if err := runtime.UnmarshalAsJSON(resp, &result.VariableValueListResult); err != nil { + return VariableValuesClientListForManagementGroupResponse{}, err + } + return result, nil +}