Skip to content

Commit 8f20059

Browse files
authored
Merge pull request #6375 from bulentelmaci/preview
PolicyInsights RP GA version of cmdlets
2 parents bac96a9 + d120a3d commit 8f20059

File tree

67 files changed

+803
-623
lines changed

Some content is hidden

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

67 files changed

+803
-623
lines changed

src/ResourceManager/PolicyInsights/AzureRM.PolicyInsights.Netcore.psd1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,10 +108,10 @@ PrivateData = @{
108108
# IconUri = ''
109109

110110
# ReleaseNotes of this module
111-
# ReleaseNotes = ''
111+
ReleaseNotes = '* Public release of Policy Insights cmdlets'
112112

113113
# Prerelease string of this module
114-
Prerelease = 'preview'
114+
# Prerelease = ''
115115

116116
# Flag to indicate whether the module requires explicit user acceptance for install/update/save
117117
# RequireLicenseAcceptance = $false

src/ResourceManager/PolicyInsights/AzureRM.PolicyInsights.psd1

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
# RootModule = ''
1313

1414
# Version number of this module.
15-
ModuleVersion = '0.9.1'
15+
ModuleVersion = '1.0.0'
1616

1717
# Supported PSEditions
1818
# CompatiblePSEditions = @()
@@ -110,10 +110,10 @@ PrivateData = @{
110110
# IconUri = ''
111111

112112
# ReleaseNotes of this module
113-
ReleaseNotes = '* Set minimum dependency of module to PowerShell 5.0'
113+
ReleaseNotes = '* Public release of Policy Insights cmdlets'
114114

115115
# Prerelease string of this module
116-
Prerelease = 'preview'
116+
# Prerelease = ''
117117

118118
# Flag to indicate whether the module requires explicit user acceptance for install/update
119119
# RequireLicenseAcceptance = $false

src/ResourceManager/PolicyInsights/ChangeLog.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
- Additional information about change #1
1919
-->
2020
## Current Release
21+
* Public release of Policy Insights cmdlets
22+
- Use API version 2018-04-04
23+
- Add PolicyDefinitionReferenceId to the results of Get-AzureRmPolicyStateSummary
2124

2225
## Version 0.9.1-preview
2326
* Set minimum dependency of module to PowerShell 5.0

src/ResourceManager/PolicyInsights/Commands.PolicyInsights.Test/Commands.PolicyInsights.Test.Netcore.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
</PropertyGroup>
2727

2828
<ItemGroup>
29-
<PackageReference Include="Microsoft.Azure.Management.PolicyInsights" Version="0.9.0-preview" />
29+
<PackageReference Include="Microsoft.Azure.Management.PolicyInsights" Version="1.0.0" />
3030
</ItemGroup>
3131

3232
<ItemGroup>

src/ResourceManager/PolicyInsights/Commands.PolicyInsights.Test/Commands.PolicyInsights.Test.csproj

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -42,17 +42,9 @@
4242
<CodeAnalysisIgnoreBuiltInRules>true</CodeAnalysisIgnoreBuiltInRules>
4343
</PropertyGroup>
4444
<ItemGroup>
45-
<Reference Include="Microsoft.Azure.Management.PolicyInsights, Version=0.9.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
45+
<Reference Include="Microsoft.Azure.Management.PolicyInsights, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
4646
<SpecificVersion>False</SpecificVersion>
47-
<HintPath>..\..\..\packages\Microsoft.Azure.Management.PolicyInsights.0.9.0-preview\lib\net452\Microsoft.Azure.Management.PolicyInsights.dll</HintPath>
48-
<Private>True</Private>
49-
</Reference>
50-
<Reference Include="Microsoft.Rest.ClientRuntime, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
51-
<HintPath>..\..\..\packages\Microsoft.Rest.ClientRuntime.2.3.10\lib\net452\Microsoft.Rest.ClientRuntime.dll</HintPath>
52-
<Private>True</Private>
53-
</Reference>
54-
<Reference Include="Microsoft.Rest.ClientRuntime.Azure, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
55-
<HintPath>..\..\..\packages\Microsoft.Rest.ClientRuntime.Azure.3.3.10\lib\net452\Microsoft.Rest.ClientRuntime.Azure.dll</HintPath>
47+
<HintPath>..\..\..\packages\Microsoft.Azure.Management.PolicyInsights.1.0.0\lib\net452\Microsoft.Azure.Management.PolicyInsights.dll</HintPath>
5648
<Private>True</Private>
5749
</Reference>
5850
<Reference Include="Microsoft.Threading.Tasks, Version=1.0.12.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
@@ -67,10 +59,6 @@
6759
<HintPath>..\..\..\packages\Microsoft.Bcl.Async.1.0.168\lib\net40\Microsoft.Threading.Tasks.Extensions.Desktop.dll</HintPath>
6860
<Private>True</Private>
6961
</Reference>
70-
<Reference Include="Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
71-
<HintPath>..\..\..\packages\Newtonsoft.Json.6.0.8\lib\net45\Newtonsoft.Json.dll</HintPath>
72-
<Private>True</Private>
73-
</Reference>
7462
<Reference Include="Microsoft.Azure.ResourceManager, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
7563
<HintPath>..\..\..\packages\Microsoft.Azure.Management.Resources.2.20.0-preview\lib\net40\Microsoft.Azure.ResourceManager.dll</HintPath>
7664
<Private>True</Private>
@@ -189,7 +177,9 @@
189177
</ItemGroup>
190178
<ItemGroup>
191179
<None Include="MSSharedLibKey.snk" />
192-
<None Include="packages.config" />
180+
<None Include="packages.config">
181+
<SubType>Designer</SubType>
182+
</None>
193183
<None Include="ScenarioTests\Common.ps1">
194184
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
195185
</None>

src/ResourceManager/PolicyInsights/Commands.PolicyInsights.Test/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
[assembly: CLSCompliant(false)]
2727
[assembly: Guid("840516AC-34D7-4F12-925B-37509D240277")]
2828

29-
[assembly: AssemblyVersion("0.9.0")]
30-
[assembly: AssemblyFileVersion("0.9.0")]
29+
[assembly: AssemblyVersion("1.0.0")]
30+
[assembly: AssemblyFileVersion("1.0.0")]
3131

3232
[assembly: CollectionBehavior(DisableTestParallelization = true)]

src/ResourceManager/PolicyInsights/Commands.PolicyInsights.Test/ScenarioTests/Common.ps1

Lines changed: 117 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,114 @@
1212
# limitations under the License.
1313
# ----------------------------------------------------------------------------------
1414

15+
<#
16+
.SYNOPSIS
17+
Gets test management group name
18+
#>
19+
function Get-TestManagementGroupName
20+
{
21+
"azgovtest4"
22+
}
23+
24+
<#
25+
.SYNOPSIS
26+
Gets test resource group group name
27+
#>
28+
function Get-TestResourceGroupName
29+
{
30+
"bulenttestrg"
31+
}
32+
33+
<#
34+
.SYNOPSIS
35+
Gets test resource id
36+
#>
37+
function Get-TestResourceId
38+
{
39+
"/subscriptions/d0610b27-9663-4c05-89f8-5b4be01e86a5/resourcegroups/govintpolicyrp/providers/microsoft.network/trafficmanagerprofiles/gov-int-policy-rp"
40+
}
41+
42+
<#
43+
.SYNOPSIS
44+
Gets test policy set definition name
45+
#>
46+
function Get-TestPolicySetDefinitionName
47+
{
48+
"12b58873-e0f8-4b95-936c-86cbe7c9d697"
49+
}
50+
51+
<#
52+
.SYNOPSIS
53+
Gets test policy definition name
54+
#>
55+
function Get-TestPolicyDefinitionName
56+
{
57+
"24813039-7534-408a-9842-eb99f45721b1"
58+
}
59+
60+
<#
61+
.SYNOPSIS
62+
Gets test policy assignment name
63+
#>
64+
function Get-TestPolicyAssignmentName
65+
{
66+
"45ab2ab7898d45ebb3087573"
67+
}
68+
69+
<#
70+
.SYNOPSIS
71+
Gets test resource group group name for resource group level policy assignment (for event tests)
72+
#>
73+
function Get-TestResourceGroupNameForPolicyAssignmentEvents
74+
{
75+
"jilimpolicytest2"
76+
}
77+
78+
<#
79+
.SYNOPSIS
80+
Gets test policy assignment name (resource group level) (for event tests)
81+
#>
82+
function Get-TestPolicyAssignmentNameResourceGroupLevelEvents
83+
{
84+
"e9860612d8ec4a469f59af06"
85+
}
86+
87+
<#
88+
.SYNOPSIS
89+
Gets test resource group group name for resource group level policy assignment (for state tests)
90+
#>
91+
function Get-TestResourceGroupNameForPolicyAssignmentStates
92+
{
93+
"bulenttestrg"
94+
}
95+
96+
<#
97+
.SYNOPSIS
98+
Gets test policy assignment name (resource group level) (for state tests)
99+
#>
100+
function Get-TestPolicyAssignmentNameResourceGroupLevelStates
101+
{
102+
"f4d1645d-9180-4968-99df-17234d0f7019"
103+
}
104+
105+
<#
106+
.SYNOPSIS
107+
Gets test query interval start
108+
#>
109+
function Get-TestQueryIntervalStart
110+
{
111+
"2018-03-31 00:00:00Z"
112+
}
113+
114+
<#
115+
.SYNOPSIS
116+
Gets test query interval end
117+
#>
118+
function Get-TestQueryIntervalEnd
119+
{
120+
"2018-05-30 00:00:00Z"
121+
}
122+
15123
<#
16124
.SYNOPSIS
17125
Validates a list of policy events
@@ -20,7 +128,8 @@ function Validate-PolicyEvents
20128
{
21129
param([System.Collections.Generic.List`1[[Microsoft.Azure.Commands.PolicyInsights.Models.PolicyEvent]]]$policyEvents, [int]$count)
22130

23-
Assert-AreEqual $count $policyEvents.Count
131+
Assert-True { $count -ge $policyEvents.Count }
132+
Assert-True { $policyEvents.Count -gt 0 }
24133
Foreach($policyEvent in $policyEvents)
25134
{
26135
Validate-PolicyEvent $policyEvent
@@ -56,7 +165,8 @@ function Validate-PolicyStates
56165
{
57166
param([System.Collections.Generic.List`1[[Microsoft.Azure.Commands.PolicyInsights.Models.PolicyState]]]$policyStates, [int]$count)
58167

59-
Assert-AreEqual $count $policyStates.Count
168+
Assert-True { $count -ge $policyStates.Count }
169+
Assert-True { $policyStates.Count -gt 0 }
60170
Foreach($policyState in $policyStates)
61171
{
62172
Validate-PolicyState $policyState
@@ -97,7 +207,8 @@ function Validate-PolicyStateSummary
97207
Assert-NotNull $policyStateSummary.Results.NonCompliantPolicies
98208

99209
Assert-NotNull $policyStateSummary.PolicyAssignments
100-
Assert-AreEqual $policyStateSummary.PolicyAssignments.Count $policyStateSummary.Results.NonCompliantPolicies
210+
Assert-True { $policyStateSummary.PolicyAssignments.Count -le $policyStateSummary.Results.NonCompliantPolicies }
211+
Assert-True { $policyStateSummary.PolicyAssignments.Count -gt 0 }
101212

102213
Foreach($policyAssignmentSummary in $policyStateSummary.PolicyAssignments)
103214
{
@@ -110,7 +221,8 @@ function Validate-PolicyStateSummary
110221
Assert-NotNull $policyAssignmentSummary.Results.NonCompliantPolicies
111222

112223
Assert-NotNull $policyAssignmentSummary.PolicyDefinitions
113-
Assert-AreEqual $policyAssignmentSummary.PolicyDefinitions.Count $policyAssignmentSummary.Results.NonCompliantPolicies
224+
Assert-True { $policyAssignmentSummary.PolicyDefinitions.Count -eq $policyAssignmentSummary.Results.NonCompliantPolicies }
225+
Assert-True { $policyAssignmentSummary.PolicyDefinitions.Count -gt 0 }
114226

115227
if ($policyAssignmentSummary.Results.NonCompliantPolicies -gt 1)
116228
{
@@ -139,6 +251,5 @@ function Assert-NotNullOrEmpty
139251
{
140252
param([string]$value)
141253

142-
Assert-NotNull $value
143-
Assert-AreNotEqual $value ""
254+
Assert-False { [string]::IsNullOrEmpty($value) }
144255
}

src/ResourceManager/PolicyInsights/Commands.PolicyInsights.Test/ScenarioTests/PolicyEventTests.ps1

Lines changed: 36 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,11 @@ Get policy events at management group scope
1818
#>
1919
function Get-AzureRmPolicyEvent-ManagementGroupScope
2020
{
21-
$policyEvents = Get-AzureRmPolicyEvent -ManagementGroupName "AzGovTest1" -Top 5
22-
Validate-PolicyEvents $policyEvents 5
21+
$managementGroupName = Get-TestManagementGroupName
22+
$from = Get-TestQueryIntervalStart
23+
24+
$policyEvents = Get-AzureRmPolicyEvent -ManagementGroupName $managementGroupName -Top 10 -From $from
25+
Validate-PolicyEvents $policyEvents 10
2326
}
2427

2528
<#
@@ -28,8 +31,10 @@ Get policy events at subscription scope
2831
#>
2932
function Get-AzureRmPolicyEvent-SubscriptionScope
3033
{
31-
$policyEvents = Get-AzureRmPolicyEvent -Top 5
32-
Validate-PolicyEvents $policyEvents 5
34+
$from = Get-TestQueryIntervalStart
35+
36+
$policyEvents = Get-AzureRmPolicyEvent -Top 10 -From $from
37+
Validate-PolicyEvents $policyEvents 10
3338
}
3439

3540
<#
@@ -38,8 +43,11 @@ Get policy events at resource group scope
3843
#>
3944
function Get-AzureRmPolicyEvent-ResourceGroupScope
4045
{
41-
$policyEvents = Get-AzureRmPolicyEvent -ResourceGroupName defaultresourcegroup-eus -Top 5
42-
Validate-PolicyEvents $policyEvents 5
46+
$resourceGroupName = Get-TestResourceGroupName
47+
$from = Get-TestQueryIntervalStart
48+
49+
$policyEvents = Get-AzureRmPolicyEvent -ResourceGroupName $resourceGroupName -Top 10 -From $from
50+
Validate-PolicyEvents $policyEvents 10
4351
}
4452

4553
<#
@@ -48,8 +56,11 @@ Get policy events at resource scope
4856
#>
4957
function Get-AzureRmPolicyEvent-ResourceScope
5058
{
51-
$policyEvents = Get-AzureRmPolicyEvent -ResourceId "/subscriptions/d0610b27-9663-4c05-89f8-5b4be01e86a5/resourcegroups/defaultresourcegroup-eus/providers/microsoft.operationalinsights/workspaces/defaultworkspace-d0610b27-9663-4c05-89f8-5b4be01e86a5-eus/linkedServices/Security"
52-
Validate-PolicyEvents $policyEvents 7
59+
$resourceId = Get-TestResourceId
60+
$from = Get-TestQueryIntervalStart
61+
62+
$policyEvents = Get-AzureRmPolicyEvent -ResourceId $resourceId -Top 10 -From $from
63+
Validate-PolicyEvents $policyEvents 10
5364
}
5465

5566
<#
@@ -58,8 +69,10 @@ Get policy events at policy set definition scope
5869
#>
5970
function Get-AzureRmPolicyEvent-PolicySetDefinitionScope
6071
{
61-
$policyEvents = Get-AzureRmPolicyEvent -PolicySetDefinitionName a03db67e-a286-43c3-9098-b2da83d361ad -Top 5
62-
Validate-PolicyEvents $policyEvents 5
72+
$policySetDefinitionName = Get-TestPolicySetDefinitionName
73+
74+
$policyEvents = Get-AzureRmPolicyEvent -PolicySetDefinitionName $policySetDefinitionName -Top 10
75+
Validate-PolicyEvents $policyEvents 10
6376
}
6477

6578
<#
@@ -68,8 +81,10 @@ Get policy events at policy definition scope
6881
#>
6982
function Get-AzureRmPolicyEvent-PolicyDefinitionScope
7083
{
71-
$policyEvents = Get-AzureRmPolicyEvent -PolicyDefinitionName c8b79b49-a579-4045-984e-1b249ab8b474 -Top 5
72-
Validate-PolicyEvents $policyEvents 5
84+
$policyDefinitionName = Get-TestPolicyDefinitionName
85+
86+
$policyEvents = Get-AzureRmPolicyEvent -PolicyDefinitionName $policyDefinitionName -Top 10
87+
Validate-PolicyEvents $policyEvents 10
7388
}
7489

7590
<#
@@ -78,8 +93,10 @@ Get policy events at subscription level policy assignment scope
7893
#>
7994
function Get-AzureRmPolicyEvent-SubscriptionLevelPolicyAssignmentScope
8095
{
81-
$policyEvents = Get-AzureRmPolicyEvent -PolicyAssignmentName e46af646ebdb461dba708e01 -Top 5
82-
Validate-PolicyEvents $policyEvents 5
96+
$policyAssignmentName = Get-TestPolicyAssignmentName
97+
98+
$policyEvents = Get-AzureRmPolicyEvent -PolicyAssignmentName $policyAssignmentName -Top 10
99+
Validate-PolicyEvents $policyEvents 10
83100
}
84101

85102
<#
@@ -88,6 +105,9 @@ Get policy events at resource group level policy assignment scope
88105
#>
89106
function Get-AzureRmPolicyEvent-ResourceGroupLevelPolicyAssignmentScope
90107
{
91-
$policyEvents = Get-AzureRmPolicyEvent -ResourceGroupName cheggpolicy -PolicyAssignmentName d620f2d1462b4426a6b499fc -Top 1
92-
Validate-PolicyEvents $policyEvents 1
108+
$resourceGroupName = Get-TestResourceGroupNameForPolicyAssignmentEvents
109+
$policyAssignmentName = Get-TestPolicyAssignmentNameResourceGroupLevelEvents
110+
111+
$policyEvents = Get-AzureRmPolicyEvent -ResourceGroupName $resourceGroupName -PolicyAssignmentName $policyAssignmentName -Top 10
112+
Validate-PolicyEvents $policyEvents 10
93113
}

0 commit comments

Comments
 (0)