Skip to content

Commit 8c1d35d

Browse files
Migrate Resources from generation to main (#25408)
* Move Resources to main * Update ChangeLog.md --------- Co-authored-by: Yabo Hu <[email protected]>
1 parent ff38392 commit 8c1d35d

File tree

162 files changed

+14058
-13325
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

162 files changed

+14058
-13325
lines changed

src/Resources/Authorization.Autorest/Az.Authorization.psd1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
@{
2-
GUID = '388baeac-1156-4ec3-9395-3805a9094a78'
2+
GUID = 'c9f907de-d9b2-4db4-b439-78ce632c122e'
33
RootModule = './Az.Authorization.psm1'
44
ModuleVersion = '0.1.0'
55
CompatiblePSEditions = 'Core', 'Desktop'

src/Resources/Authorization.Autorest/help/Az.Authorization.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
Module Name: Az.Authorization
3-
Module Guid: 388baeac-1156-4ec3-9395-3805a9094a78
3+
Module Guid: c9f907de-d9b2-4db4-b439-78ce632c122e
44
Download Help Link: https://learn.microsoft.com/powershell/module/az.authorization
55
Help Version: 1.0.0.0
66
Locale: en-US

src/Resources/Policy.Autorest/README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,29 @@ directive:
174174
where: $.definitions.PolicySetDefinitionProperties.properties.policyDefinition.groupNames
175175
transform: $['additionalProperties'] = true;
176176

177+
# versioning serialization
178+
- from: swagger-document
179+
where: $.definitions.PolicyDefinitionVersionProperties.properties.policyRule
180+
transform: $['additionalProperties'] = true
181+
- from: swagger-document
182+
where: $.definitions.PolicyDefinitionVersionProperties.properties.metadata
183+
transform: $['additionalProperties'] = true
184+
- from: swagger-document
185+
where: $.definitions.PolicySetDefinitionVersionProperties.properties.metadata
186+
transform: $['additionalProperties'] = true;
187+
- from: swagger-document
188+
where: $.definitions.PolicySetDefinitionVersionProperties.properties.policyDefinition.policyDefinitionId
189+
transform: $['additionalProperties'] = true;
190+
- from: swagger-document
191+
where: $.definitions.PolicySetDefinitionVersionProperties.properties.policyDefinition.parameters
192+
transform: $['additionalProperties'] = true;
193+
- from: swagger-document
194+
where: $.definitions.PolicySetDefinitionVersionProperties.properties.policyDefinition.policyDefinitionReferenceId
195+
transform: $['additionalProperties'] = true;
196+
- from: swagger-document
197+
where: $.definitions.PolicySetDefinitionVersionProperties.properties.policyDefinition.groupNames
198+
transform: $['additionalProperties'] = true;
199+
177200
# previous approach that partially supported "any type" serialization
178201
- from: swagger-document
179202
where: $.definitions.ParameterDefinitionsValue.properties.allowedValues.items

src/Resources/Policy.Autorest/custom/Helpers.ps1

Lines changed: 62 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -43,52 +43,12 @@ function ParsePolicyId {
4343
$parts = $resourceId -split $mark
4444
$scope = $parts[0]
4545
$name = ''
46-
$version = ''
47-
$major = ''
48-
$minor = ''
49-
$patch = ''
50-
$suffix = ''
51-
$versionRef = ''
52-
$versionMajorRef = ''
53-
$versionMinorRef = ''
5446

5547
if ($parts.Length -gt 1) {
5648
$parts = $parts[1] -split '/'
5749
$name = $parts[0]
5850
if (($parts.Length -gt 2) -and ($parts[1] -eq 'versions')) {
59-
$version = $parts[2]
60-
$parts = $version -split '\.'
61-
$major = $parts[0]
62-
if ($parts.Length -gt 1) {
63-
$minor = $parts[1]
64-
}
65-
if ($parts.Length -gt 2) {
66-
$parts = $parts[2] -split '-'
67-
$patch = $parts[0]
68-
if ($parts.Length -gt 1) {
69-
$suffix = $parts[1]
70-
}
71-
}
72-
73-
$versionMajorRef = @($major,'*','*') -join '.'
74-
if ($minor -ne '*') {
75-
$versionMinorRef = @($major,$minor,'*') -join '.'
76-
}
77-
78-
if ($suffix) {
79-
if ($versionMinorRef) {
80-
$versionMinorRef = $versionMinorRef + '-' + $suffix
81-
}
82-
83-
$versionMajorRef = $versionMajorRef + '-' + $suffix
84-
}
85-
86-
if ($versionMinorRef) {
87-
$versionRef = $versionMinorRef
88-
}
89-
else {
90-
$versionRef = $versionMajorRef
91-
}
51+
$parsedVersion = ParsePolicyVersion $parts[2]
9252
}
9353
}
9454

@@ -139,8 +99,8 @@ function ParsePolicyId {
13999
$artifactRef = ''
140100

141101
$artifact = $scope + $mark + $name
142-
if ($versionRef) {
143-
$artifactRef = "$artifact/versions/$versionRef"
102+
if ($parsedVersion.VersionRef) {
103+
$artifactRef = "$artifact/versions/$($parsedVersion.VersionRef)"
144104
}
145105

146106
return @{
@@ -155,13 +115,70 @@ function ParsePolicyId {
155115
ResourceType = $resType
156116
ResourceName = $resName
157117
Name = $name
118+
Artifact = $artifact
119+
ArtifactRef = $artifactRef
120+
Version = $parsedVersion.Version
121+
Major = $parsedVersion.Major
122+
Minor = $parsedVersion.Minor
123+
Patch = $parsedVersion.Patch
124+
Suffix = $parsedVersion.Suffix
125+
VersionRef = $parsedVersion.VersionRef
126+
VersionMajorRef = $parsedVersion.VersionMajorRef
127+
VersionMinorRef = $parsedVersion.VersionMinorRef
128+
}
129+
}
130+
131+
# parse policy version with format: (ddd|*).(ddd|*).(ddd|*)[-suffix]
132+
function ParsePolicyVersion {
133+
[Microsoft.Azure.PowerShell.Cmdlets.Policy.DoNotExportAttribute()]
134+
# the resource Id of a policy definition
135+
param($version)
136+
137+
$parts = $version -split '\.'
138+
$major = $parts[0]
139+
$minor = ''
140+
if ($parts.Length -gt 1) {
141+
$minor = $parts[1]
142+
}
143+
144+
$patch = ''
145+
$suffix = ''
146+
if ($parts.Length -gt 2) {
147+
$parts = $parts[2] -split '-'
148+
$patch = $parts[0]
149+
if ($parts.Length -gt 1) {
150+
$suffix = $parts[1]
151+
}
152+
}
153+
154+
$versionMinorRef = ''
155+
$versionMajorRef = @($major,'*','*') -join '.'
156+
if ($minor -ne '*') {
157+
$versionMinorRef = @($major,$minor,'*') -join '.'
158+
}
159+
160+
if ($suffix) {
161+
if ($versionMinorRef) {
162+
$versionMinorRef = $versionMinorRef + '-' + $suffix
163+
}
164+
165+
$versionMajorRef = $versionMajorRef + '-' + $suffix
166+
}
167+
168+
$versionRef = ''
169+
if ($versionMinorRef) {
170+
$versionRef = $versionMinorRef
171+
}
172+
else {
173+
$versionRef = $versionMajorRef
174+
}
175+
176+
return @{
158177
Version = $version
159178
Major = $major
160179
Minor = $minor
161180
Patch = $patch
162181
Suffix = $suffix
163-
Artifact = $artifact
164-
ArtifactRef = $artifactRef
165182
VersionRef = $versionRef
166183
VersionMajorRef = $versionMajorRef
167184
VersionMinorRef = $versionMinorRef

src/Resources/Policy.Autorest/custom/New-AzPolicyAssignment.ps1

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,14 @@ param(
7878
# Accept policy definition or policy set definition object
7979
${PolicyDefinition},
8080

81+
[Parameter(ParameterSetName='ParameterObject')]
82+
[Parameter(ParameterSetName='ParameterString')]
83+
[Parameter(ParameterSetName='PolicyDefinitionOrPolicySetDefinition')]
84+
[Microsoft.Azure.PowerShell.Cmdlets.Policy.Category('Body')]
85+
[System.String]
86+
# Indicate version of policy definition or policy set definition
87+
${DefinitionVersion},
88+
8189
[Parameter(ParameterSetName='ParameterObject', Mandatory)]
8290
[ValidateNotNullOrEmpty()]
8391
[Microsoft.Azure.PowerShell.Cmdlets.Policy.Category('Body')]
@@ -302,11 +310,29 @@ process {
302310
# route the input policy id to the correct place
303311
if ($calledParameters.ContainsKey('PolicyDefinition')) {
304312

313+
$definitionId = $PolicyDefinition
314+
if ($PolicyDefinition.Id) {
315+
$definitionId = $PolicyDefinition.Id
316+
}
317+
305318
# parse the definition Id to determine the format (policy [set] definition and versioned or not)
306-
$parsedPolicyId = parsePolicyId $PolicyDefinition.Id
319+
$parsedPolicyId = ParsePolicyId $definitionId
307320
if ($parsedPolicyId.ArtifactRef) {
308-
# handle versioned policy [set] references
309-
$calledParameters.DefinitionVersion = $parsedPolicyId.VersionRef
321+
if ($DefinitionVersion) {
322+
$parsedVersion = ParsePolicyVersion $DefinitionVersion
323+
324+
if ($writeln) {
325+
Write-Host -ForegroundColor Cyan "Artifact: $($parsedPolicyId.Artifact), VersionRef: $($parsedVersion.VersionRef)."
326+
}
327+
328+
if ($parsedPolicyId.VersionRef -ne $parsedVersion.VersionRef) {
329+
throw "Definition version is ambiguous. PolicyDefinition version resolved to $($parsedPolicyId.VersionRef), but DefinitionVersion was $DefinitionVersion."
330+
}
331+
}
332+
else {
333+
# handle versioned policy [set] references
334+
$calledParameters.DefinitionVersion = $parsedPolicyId.VersionRef
335+
}
310336
}
311337

312338
$calledParameters.PolicyDefinitionId = $parsedPolicyId.Artifact

src/Resources/Policy.Autorest/custom/New-AzPolicyDefinition.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ process {
177177

178178
# convert input/legacy policy parameter to correct set of parameters and remove
179179
if ($Policy) {
180-
$resolved = resolvePolicyParameter -ParameterName 'Policy' -ParameterValue $Policy -Debug $writeln
180+
$resolved = ResolvePolicyParameter -ParameterName 'Policy' -ParameterValue $Policy -Debug $writeln
181181
if ($resolved.policyRule) {
182182
foreach ($key in $resolved.Keys) {
183183

@@ -219,7 +219,7 @@ process {
219219

220220
# resolve [string] 'parameter' input parameter (could be a path)
221221
if ($Parameter) {
222-
$calledParameters.Parameter = (resolvePolicyParameter -ParameterName 'Parameter' -ParameterValue $Parameter -Debug $writeln)
222+
$calledParameters.Parameter = (ResolvePolicyParameter -ParameterName 'Parameter' -ParameterValue $Parameter -Debug $writeln)
223223
}
224224

225225
# rename [string] 'parameter' parameter to 'parametertable' (needs to be string to construct properly)
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License. See License.txt in the project root for license information.
3+
// Code generated by Microsoft (R) AutoRest Code Generator.
4+
// Changes may cause incorrect behavior and will be lost if the code is regenerated.
5+
6+
namespace Microsoft.Azure.PowerShell.Cmdlets.Policy.Models
7+
{
8+
using Microsoft.Azure.PowerShell.Cmdlets.Policy.Runtime.Json;
9+
10+
/// <summary>The policy rule.</summary>
11+
public partial class PolicyDefinitionPropertiesPolicyRule
12+
{
13+
14+
/// <summary>
15+
/// <c>AfterFromJson</c> will be called after the json deserialization has finished, allowing customization of the object
16+
/// before it is returned. Implement this method in a partial class to enable this behavior
17+
/// </summary>
18+
/// <param name="json">The JsonNode that should be deserialized into this object.</param>
19+
20+
partial void AfterFromJson(Microsoft.Azure.PowerShell.Cmdlets.Policy.Runtime.Json.JsonObject json)
21+
{
22+
}
23+
24+
/// <summary>
25+
/// <c>AfterToJson</c> will be called after the json serialization has finished, allowing customization of the <see cref="Microsoft.Azure.PowerShell.Cmdlets.Policy.Runtime.Json.JsonObject"
26+
/// /> before it is returned. Implement this method in a partial class to enable this behavior
27+
/// </summary>
28+
/// <param name="container">The JSON container that the serialization result will be placed in.</param>
29+
30+
partial void AfterToJson(ref Microsoft.Azure.PowerShell.Cmdlets.Policy.Runtime.Json.JsonObject container)
31+
{
32+
}
33+
34+
/// <summary>
35+
/// <c>BeforeFromJson</c> will be called before the json deserialization has commenced, allowing complete customization of
36+
/// the object before it is deserialized.
37+
/// If you wish to disable the default deserialization entirely, return <c>true</c> in the <paramref name= "returnNow" />
38+
/// output parameter.
39+
/// Implement this method in a partial class to enable this behavior.
40+
/// </summary>
41+
/// <param name="json">The JsonNode that should be deserialized into this object.</param>
42+
/// <param name="returnNow">Determines if the rest of the deserialization should be processed, or if the method should return
43+
/// instantly.</param>
44+
45+
partial void BeforeFromJson(Microsoft.Azure.PowerShell.Cmdlets.Policy.Runtime.Json.JsonObject json, ref bool returnNow)
46+
{
47+
}
48+
49+
/// <summary>
50+
/// <c>BeforeToJson</c> will be called before the json serialization has commenced, allowing complete customization of the
51+
/// object before it is serialized.
52+
/// If you wish to disable the default serialization entirely, return <c>true</c> in the <paramref name="returnNow" /> output
53+
/// parameter.
54+
/// Implement this method in a partial class to enable this behavior.
55+
/// </summary>
56+
/// <param name="container">The JSON container that the serialization result will be placed in.</param>
57+
/// <param name="returnNow">Determines if the rest of the serialization should be processed, or if the method should return
58+
/// instantly.</param>
59+
60+
partial void BeforeToJson(ref JsonObject container, ref bool returnNow)
61+
{
62+
// this call marks null property values properly to allow them to be serialized to JSON correctly
63+
SerializationHelpers.SetSentinel(((Runtime.IAssociativeArray<global::System.Object>)this).AdditionalProperties);
64+
}
65+
}
66+
}

0 commit comments

Comments
 (0)