Skip to content

Commit

Permalink
Migrate Resources from generation to main (Azure#25408)
Browse files Browse the repository at this point in the history
* Move Resources to main

* Update ChangeLog.md

---------

Co-authored-by: Yabo Hu <[email protected]>
  • Loading branch information
azure-powershell-bot and VeryEarly authored Jun 30, 2024
1 parent ff38392 commit 8c1d35d
Show file tree
Hide file tree
Showing 162 changed files with 14,058 additions and 13,325 deletions.
2 changes: 1 addition & 1 deletion src/Resources/Authorization.Autorest/Az.Authorization.psd1
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
@{
GUID = '388baeac-1156-4ec3-9395-3805a9094a78'
GUID = 'c9f907de-d9b2-4db4-b439-78ce632c122e'
RootModule = './Az.Authorization.psm1'
ModuleVersion = '0.1.0'
CompatiblePSEditions = 'Core', 'Desktop'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
Module Name: Az.Authorization
Module Guid: 388baeac-1156-4ec3-9395-3805a9094a78
Module Guid: c9f907de-d9b2-4db4-b439-78ce632c122e
Download Help Link: https://learn.microsoft.com/powershell/module/az.authorization
Help Version: 1.0.0.0
Locale: en-US
Expand Down
23 changes: 23 additions & 0 deletions src/Resources/Policy.Autorest/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,29 @@ directive:
where: $.definitions.PolicySetDefinitionProperties.properties.policyDefinition.groupNames
transform: $['additionalProperties'] = true;

# versioning serialization
- from: swagger-document
where: $.definitions.PolicyDefinitionVersionProperties.properties.policyRule
transform: $['additionalProperties'] = true
- from: swagger-document
where: $.definitions.PolicyDefinitionVersionProperties.properties.metadata
transform: $['additionalProperties'] = true
- from: swagger-document
where: $.definitions.PolicySetDefinitionVersionProperties.properties.metadata
transform: $['additionalProperties'] = true;
- from: swagger-document
where: $.definitions.PolicySetDefinitionVersionProperties.properties.policyDefinition.policyDefinitionId
transform: $['additionalProperties'] = true;
- from: swagger-document
where: $.definitions.PolicySetDefinitionVersionProperties.properties.policyDefinition.parameters
transform: $['additionalProperties'] = true;
- from: swagger-document
where: $.definitions.PolicySetDefinitionVersionProperties.properties.policyDefinition.policyDefinitionReferenceId
transform: $['additionalProperties'] = true;
- from: swagger-document
where: $.definitions.PolicySetDefinitionVersionProperties.properties.policyDefinition.groupNames
transform: $['additionalProperties'] = true;

# previous approach that partially supported "any type" serialization
- from: swagger-document
where: $.definitions.ParameterDefinitionsValue.properties.allowedValues.items
Expand Down
107 changes: 62 additions & 45 deletions src/Resources/Policy.Autorest/custom/Helpers.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -43,52 +43,12 @@ function ParsePolicyId {
$parts = $resourceId -split $mark
$scope = $parts[0]
$name = ''
$version = ''
$major = ''
$minor = ''
$patch = ''
$suffix = ''
$versionRef = ''
$versionMajorRef = ''
$versionMinorRef = ''

if ($parts.Length -gt 1) {
$parts = $parts[1] -split '/'
$name = $parts[0]
if (($parts.Length -gt 2) -and ($parts[1] -eq 'versions')) {
$version = $parts[2]
$parts = $version -split '\.'
$major = $parts[0]
if ($parts.Length -gt 1) {
$minor = $parts[1]
}
if ($parts.Length -gt 2) {
$parts = $parts[2] -split '-'
$patch = $parts[0]
if ($parts.Length -gt 1) {
$suffix = $parts[1]
}
}

$versionMajorRef = @($major,'*','*') -join '.'
if ($minor -ne '*') {
$versionMinorRef = @($major,$minor,'*') -join '.'
}

if ($suffix) {
if ($versionMinorRef) {
$versionMinorRef = $versionMinorRef + '-' + $suffix
}

$versionMajorRef = $versionMajorRef + '-' + $suffix
}

if ($versionMinorRef) {
$versionRef = $versionMinorRef
}
else {
$versionRef = $versionMajorRef
}
$parsedVersion = ParsePolicyVersion $parts[2]
}
}

Expand Down Expand Up @@ -139,8 +99,8 @@ function ParsePolicyId {
$artifactRef = ''

$artifact = $scope + $mark + $name
if ($versionRef) {
$artifactRef = "$artifact/versions/$versionRef"
if ($parsedVersion.VersionRef) {
$artifactRef = "$artifact/versions/$($parsedVersion.VersionRef)"
}

return @{
Expand All @@ -155,13 +115,70 @@ function ParsePolicyId {
ResourceType = $resType
ResourceName = $resName
Name = $name
Artifact = $artifact
ArtifactRef = $artifactRef
Version = $parsedVersion.Version
Major = $parsedVersion.Major
Minor = $parsedVersion.Minor
Patch = $parsedVersion.Patch
Suffix = $parsedVersion.Suffix
VersionRef = $parsedVersion.VersionRef
VersionMajorRef = $parsedVersion.VersionMajorRef
VersionMinorRef = $parsedVersion.VersionMinorRef
}
}

# parse policy version with format: (ddd|*).(ddd|*).(ddd|*)[-suffix]
function ParsePolicyVersion {
[Microsoft.Azure.PowerShell.Cmdlets.Policy.DoNotExportAttribute()]
# the resource Id of a policy definition
param($version)

$parts = $version -split '\.'
$major = $parts[0]
$minor = ''
if ($parts.Length -gt 1) {
$minor = $parts[1]
}

$patch = ''
$suffix = ''
if ($parts.Length -gt 2) {
$parts = $parts[2] -split '-'
$patch = $parts[0]
if ($parts.Length -gt 1) {
$suffix = $parts[1]
}
}

$versionMinorRef = ''
$versionMajorRef = @($major,'*','*') -join '.'
if ($minor -ne '*') {
$versionMinorRef = @($major,$minor,'*') -join '.'
}

if ($suffix) {
if ($versionMinorRef) {
$versionMinorRef = $versionMinorRef + '-' + $suffix
}

$versionMajorRef = $versionMajorRef + '-' + $suffix
}

$versionRef = ''
if ($versionMinorRef) {
$versionRef = $versionMinorRef
}
else {
$versionRef = $versionMajorRef
}

return @{
Version = $version
Major = $major
Minor = $minor
Patch = $patch
Suffix = $suffix
Artifact = $artifact
ArtifactRef = $artifactRef
VersionRef = $versionRef
VersionMajorRef = $versionMajorRef
VersionMinorRef = $versionMinorRef
Expand Down
32 changes: 29 additions & 3 deletions src/Resources/Policy.Autorest/custom/New-AzPolicyAssignment.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,14 @@ param(
# Accept policy definition or policy set definition object
${PolicyDefinition},

[Parameter(ParameterSetName='ParameterObject')]
[Parameter(ParameterSetName='ParameterString')]
[Parameter(ParameterSetName='PolicyDefinitionOrPolicySetDefinition')]
[Microsoft.Azure.PowerShell.Cmdlets.Policy.Category('Body')]
[System.String]
# Indicate version of policy definition or policy set definition
${DefinitionVersion},

[Parameter(ParameterSetName='ParameterObject', Mandatory)]
[ValidateNotNullOrEmpty()]
[Microsoft.Azure.PowerShell.Cmdlets.Policy.Category('Body')]
Expand Down Expand Up @@ -302,11 +310,29 @@ process {
# route the input policy id to the correct place
if ($calledParameters.ContainsKey('PolicyDefinition')) {

$definitionId = $PolicyDefinition
if ($PolicyDefinition.Id) {
$definitionId = $PolicyDefinition.Id
}

# parse the definition Id to determine the format (policy [set] definition and versioned or not)
$parsedPolicyId = parsePolicyId $PolicyDefinition.Id
$parsedPolicyId = ParsePolicyId $definitionId
if ($parsedPolicyId.ArtifactRef) {
# handle versioned policy [set] references
$calledParameters.DefinitionVersion = $parsedPolicyId.VersionRef
if ($DefinitionVersion) {
$parsedVersion = ParsePolicyVersion $DefinitionVersion

if ($writeln) {
Write-Host -ForegroundColor Cyan "Artifact: $($parsedPolicyId.Artifact), VersionRef: $($parsedVersion.VersionRef)."
}

if ($parsedPolicyId.VersionRef -ne $parsedVersion.VersionRef) {
throw "Definition version is ambiguous. PolicyDefinition version resolved to $($parsedPolicyId.VersionRef), but DefinitionVersion was $DefinitionVersion."
}
}
else {
# handle versioned policy [set] references
$calledParameters.DefinitionVersion = $parsedPolicyId.VersionRef
}
}

$calledParameters.PolicyDefinitionId = $parsedPolicyId.Artifact
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ process {

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

Expand Down Expand Up @@ -219,7 +219,7 @@ process {

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

# rename [string] 'parameter' parameter to 'parametertable' (needs to be string to construct properly)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
// 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.

namespace Microsoft.Azure.PowerShell.Cmdlets.Policy.Models
{
using Microsoft.Azure.PowerShell.Cmdlets.Policy.Runtime.Json;

/// <summary>The policy rule.</summary>
public partial class PolicyDefinitionPropertiesPolicyRule
{

/// <summary>
/// <c>AfterFromJson</c> will be called after the json deserialization has finished, allowing customization of the object
/// before it is returned. Implement this method in a partial class to enable this behavior
/// </summary>
/// <param name="json">The JsonNode that should be deserialized into this object.</param>

partial void AfterFromJson(Microsoft.Azure.PowerShell.Cmdlets.Policy.Runtime.Json.JsonObject json)
{
}

/// <summary>
/// <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"
/// /> before it is returned. Implement this method in a partial class to enable this behavior
/// </summary>
/// <param name="container">The JSON container that the serialization result will be placed in.</param>

partial void AfterToJson(ref Microsoft.Azure.PowerShell.Cmdlets.Policy.Runtime.Json.JsonObject container)
{
}

/// <summary>
/// <c>BeforeFromJson</c> will be called before the json deserialization has commenced, allowing complete customization of
/// the object before it is deserialized.
/// If you wish to disable the default deserialization entirely, return <c>true</c> in the <paramref name= "returnNow" />
/// output parameter.
/// Implement this method in a partial class to enable this behavior.
/// </summary>
/// <param name="json">The JsonNode that should be deserialized into this object.</param>
/// <param name="returnNow">Determines if the rest of the deserialization should be processed, or if the method should return
/// instantly.</param>

partial void BeforeFromJson(Microsoft.Azure.PowerShell.Cmdlets.Policy.Runtime.Json.JsonObject json, ref bool returnNow)
{
}

/// <summary>
/// <c>BeforeToJson</c> will be called before the json serialization has commenced, allowing complete customization of the
/// object before it is serialized.
/// If you wish to disable the default serialization entirely, return <c>true</c> in the <paramref name="returnNow" /> output
/// parameter.
/// Implement this method in a partial class to enable this behavior.
/// </summary>
/// <param name="container">The JSON container that the serialization result will be placed in.</param>
/// <param name="returnNow">Determines if the rest of the serialization should be processed, or if the method should return
/// instantly.</param>

partial void BeforeToJson(ref JsonObject container, ref bool returnNow)
{
// this call marks null property values properly to allow them to be serialized to JSON correctly
SerializationHelpers.SetSentinel(((Runtime.IAssociativeArray<global::System.Object>)this).AdditionalProperties);
}
}
}
Loading

0 comments on commit 8c1d35d

Please sign in to comment.