Skip to content

Commit 01645cf

Browse files
authored
Merge pull request #273 from vivsriaus/vivsriaus/AddAppliance
Add policy set definition cmdlets
2 parents 1bbcd8c + d5c2b5b commit 01645cf

File tree

44 files changed

+2845
-367
lines changed

Some content is hidden

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

44 files changed

+2845
-367
lines changed

src/ResourceManager/Resources/AzureRM.Resources.psd1

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -104,12 +104,12 @@ CmdletsToExport = 'Get-AzureRmProviderOperation', 'Remove-AzureRmRoleAssignment'
104104
'Get-AzureRmResourceLock', 'Invoke-AzureRmResourceAction',
105105
'Find-AzureRmResource', 'Move-AzureRmResource',
106106
'New-AzureRmResourceLock', 'Get-AzureRmPolicyAssignment',
107-
'Get-AzureRmPolicyDefinition', 'New-AzureRmPolicyAssignment',
108-
'New-AzureRmPolicyDefinition', 'Remove-AzureRmPolicyAssignment',
109-
'Remove-AzureRmPolicyDefinition', 'Set-AzureRmPolicyAssignment',
110-
'Set-AzureRmPolicyDefinition', 'Remove-AzureRmResource',
111-
'Remove-AzureRmResourceLock', 'Set-AzureRmResource',
112-
'New-AzureRmResource', 'Set-AzureRmResourceLock',
107+
'Get-AzureRmPolicyDefinition', 'Get-AzureRmPolicySetDefinition', 'New-AzureRmPolicyAssignment',
108+
'New-AzureRmPolicyDefinition', 'New-AzureRmPolicySetDefinition', 'Remove-AzureRmPolicyAssignment',
109+
'Remove-AzureRmPolicyDefinition', 'Remove-AzureRmPolicySetDefinition', 'Set-AzureRmPolicyAssignment',
110+
'Set-AzureRmPolicyDefinition', 'Set-AzureRmPolicySetDefinition', 'Remove-AzureRmResource',
111+
'Remove-AzureRmResourceLock', 'Set-AzureRmResource',
112+
'New-AzureRmResource', 'Set-AzureRmResourceLock',
113113
'Get-AzureRmResource'
114114

115115
# Variables to export from this module

src/ResourceManager/Resources/ChangeLog.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,14 @@
1818
- Additional information about change #1
1919
-->
2020
## Current Release
21+
* Add PolicySetDefinition cmdlets
22+
- New-AzureRmPolicySetDefinition cmdlet to create a policy set definition
23+
- Get-AzureRmPolicySetDefinition cmdlet to list all policy set definitions or to get a specific policy set definition
24+
- Remove-AzureRmPolicySetDefinition cmdlet to delete a policy set definition
25+
- Set-AzureRmPolicySetDefinition cmdlet to update an existing policy set definition
26+
* Add -PolicySetDefinition, -Sku and -NotScope parameters to New-AzureRmPolicyAssignment and Set-AzureRmPolicyAssignment cmdlets
27+
* Add support to pass in policy url to New-AzureRmPolicyDefinition and Set-AzureRmPolicyDefinition cmdlets
28+
* Add -Mode parameter to New-AzureRmPolicyDefinition cmdlet
2129

2230
## Version 4.3.1
2331

src/ResourceManager/Resources/Commands.ResourceManager/Cmdlets/Commands.Resources.Rest.csproj

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,13 @@
7575
<Compile Include="Entities\Operations\AzureAsyncOperationResource.cs" />
7676
<Compile Include="Entities\Policy\PolicyAssignment.cs" />
7777
<Compile Include="Entities\Policy\PolicyAssignmentProperties.cs" />
78+
<Compile Include="Entities\Policy\PolicyDefinitionMode.cs" />
79+
<Compile Include="Entities\Policy\PolicySetDefinition.cs" />
7880
<Compile Include="Entities\Policy\PolicyDefinition.cs" />
81+
<Compile Include="Entities\Policy\PolicySetDefinitionProperties.cs" />
7982
<Compile Include="Entities\Policy\PolicyDefinitionProperties.cs" />
8083
<Compile Include="Entities\Policy\PolicyRule.cs" />
84+
<Compile Include="Entities\Policy\PolicySku.cs" />
8185
<Compile Include="Entities\Providers\ResourceProviderDefinition.cs" />
8286
<Compile Include="Entities\Providers\ResourceTypeDefinition.cs" />
8387
<Compile Include="Entities\ProvisioningState\ProvisioningState.cs" />
@@ -104,6 +108,11 @@
104108
<Compile Include="Implementation\Features\GetAzureProviderFeatureCmdlet.cs" />
105109
<Compile Include="Implementation\Features\RegisterAzureProviderFeatureCmdlet.cs" />
106110
<Compile Include="Implementation\Locations\GetAzureLocationCmdlet.cs" />
111+
<Compile Include="Implementation\Policy\GetAzurePolicySetDefinition.cs" />
112+
<Compile Include="Implementation\Policy\NewAzurePolicySetDefinition.cs" />
113+
<Compile Include="Implementation\Policy\PolicyCmdletBase.cs" />
114+
<Compile Include="Implementation\Policy\RemoveAzurePolicySetDefinition.cs" />
115+
<Compile Include="Implementation\Policy\SetAzurePolicySetDefinition.cs" />
107116
<Compile Include="Implementation\ResourceGroups\FindAzureResourceGroupCmdlet.cs" />
108117
<Compile Include="Implementation\ResourceGroups\ExportAzureResourceGroupCmdlet.cs" />
109118
<Compile Include="Implementation\Providers\GetAzureProviderCmdlet.cs" />
@@ -130,8 +139,6 @@
130139
<Compile Include="Implementation\Policy\GetAzurePolicyDefinition.cs" />
131140
<Compile Include="Implementation\Policy\NewAzurePolicyAssignment.cs" />
132141
<Compile Include="Implementation\Policy\NewAzurePolicyDefinition.cs" />
133-
<Compile Include="Implementation\Policy\PolicyAssignmentCmdletBase.cs" />
134-
<Compile Include="Implementation\Policy\PolicyDefinitionCmdletBase.cs" />
135142
<Compile Include="Implementation\Policy\RemoveAzurePolicyAssignment.cs" />
136143
<Compile Include="Implementation\Policy\RemoveAzurePolicyDefinition.cs" />
137144
<Compile Include="Implementation\Policy\SetAzurePolicyAssignment.cs" />

src/ResourceManager/Resources/Commands.ResourceManager/Cmdlets/Components/Constants.cs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,19 @@ public static class Constants
6161
public static readonly string ResourcesApiVersion = "2016-09-01";
6262

6363
/// <summary>
64-
/// The default policy API version.
64+
/// The default policy definition API version.
6565
/// </summary>
66-
public static readonly string PolicyApiVersion = "2016-12-01";
66+
public static readonly string PolicyDefinitionApiVersion = "2016-12-01";
67+
68+
/// <summary>
69+
/// The default policy set definition API version.
70+
/// </summary>
71+
public static readonly string PolicySetDefintionApiVersion = "2017-06-01-preview";
72+
73+
/// <summary>
74+
/// The default policy assignment API version.
75+
/// </summary>
76+
public static readonly string PolicyAssignmentApiVersion = "2017-06-01-preview";
6777

6878
/// <summary>
6979
/// The default providers API version.
@@ -110,6 +120,11 @@ public static class Constants
110120
/// </summary>
111121
public static readonly string MicrosoftAuthorizationPolicyDefinitionType = Constants.MicrosoftAuthorizationNamespace + "/policydefinitions";
112122

123+
/// <summary>
124+
/// The policy set definition resource type.
125+
/// </summary>
126+
public static readonly string MicrosoftAuthorizationPolicySetDefinitionType = Constants.MicrosoftAuthorizationNamespace + "/policysetdefinitions";
127+
113128
/// <summary>
114129
/// The policy definition resource type.
115130
/// </summary>

src/ResourceManager/Resources/Commands.ResourceManager/Cmdlets/Entities/Policy/PolicyAssignment.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,19 @@ public class PolicyAssignment
2424
/// <summary>
2525
/// The policy assignment properties.
2626
/// </summary>
27-
[JsonProperty(Required = Required.Default)]
27+
[JsonProperty(Required = Required.Always)]
2828
public PolicyAssignmentProperties Properties { get; set; }
2929

3030
/// <summary>
3131
/// The policy assignment name.
3232
/// </summary>
3333
[JsonProperty(Required = Required.Default)]
3434
public string Name { get; set; }
35+
36+
/// <summary>
37+
/// The policy sku.
38+
/// </summary>
39+
[JsonProperty(Required = Required.Always)]
40+
public PolicySku Sku { get; set; }
3541
}
3642
}

src/ResourceManager/Resources/Commands.ResourceManager/Cmdlets/Entities/Policy/PolicyAssignmentProperties.cs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,34 @@ public class PolicyAssignmentProperties
2828
[JsonProperty(Required = Required.Always)]
2929
public string Scope { get; set; }
3030

31+
/// <summary>
32+
/// The not scopes array.
33+
/// </summary>
34+
[JsonProperty(Required = Required.Default)]
35+
public string[] NotScopes { get; set; }
36+
3137
/// <summary>
3238
/// The display name.
3339
/// </summary>
3440
[JsonProperty(Required = Required.Default)]
3541
public string DisplayName { get; set; }
3642

43+
/// <summary>
44+
/// The description.
45+
/// </summary>
46+
[JsonProperty(Required = Required.Default)]
47+
public string Description { get; set; }
48+
49+
/// <summary>
50+
/// The policy assignment metadata.
51+
/// </summary>
52+
[JsonProperty(Required = Required.Default)]
53+
public JObject Metadata { get; set; }
54+
3755
/// <summary>
3856
/// The policy definition id.
3957
/// </summary>
40-
[JsonProperty(Required = Required.Always)]
58+
[JsonProperty(Required = Required.Default)]
4159
public string PolicyDefinitionId { get; set; }
4260

4361
/// <summary>
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// ----------------------------------------------------------------------------------
2+
//
3+
// Copyright Microsoft Corporation
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
// ----------------------------------------------------------------------------------
14+
15+
namespace Microsoft.Azure.Commands.ResourceManager.Cmdlets.Entities.Policy
16+
{
17+
/// <summary>
18+
/// The policy definition mode.
19+
/// </summary>
20+
public enum PolicyDefinitionMode
21+
{
22+
/// <summary>
23+
/// The policy definition mode is indexed.
24+
/// </summary>
25+
Indexed,
26+
27+
/// <summary>
28+
/// The policy definition mode is all.
29+
/// </summary>
30+
All
31+
}
32+
}

src/ResourceManager/Resources/Commands.ResourceManager/Cmdlets/Entities/Policy/PolicyDefinitionProperties.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,22 @@ public class PolicyDefinitionProperties
4040
[JsonProperty(Required = Required.Always)]
4141
public JObject PolicyRule { get; set; }
4242

43+
/// <summary>
44+
/// The policy definition metadata.
45+
/// </summary>
46+
[JsonProperty(Required = Required.Default)]
47+
public JObject Metadata { get; set; }
48+
4349
/// <summary>
4450
/// The parameters declaration.
4551
/// </summary>
4652
[JsonProperty(Required = Required.Default)]
4753
public JObject Parameters { get; set; }
54+
55+
/// <summary>
56+
/// The mode.
57+
/// </summary>
58+
[JsonProperty(Required = Required.Default)]
59+
public PolicyDefinitionMode? Mode { get; set; }
4860
}
4961
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// ----------------------------------------------------------------------------------
2+
//
3+
// Copyright Microsoft Corporation
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
// ----------------------------------------------------------------------------------
14+
15+
namespace Microsoft.Azure.Commands.ResourceManager.Cmdlets.Entities.Policy
16+
{
17+
using Newtonsoft.Json;
18+
19+
/// <summary>
20+
/// The policy set definition object.
21+
/// </summary>
22+
public class PolicySetDefinition
23+
{
24+
/// <summary>
25+
/// The policy set definition name.
26+
/// </summary>
27+
[JsonProperty(Required = Required.Default)]
28+
public string Name { get; set; }
29+
30+
/// <summary>
31+
/// The policy set definition properties.
32+
/// </summary>
33+
[JsonProperty(Required = Required.Default)]
34+
public PolicySetDefinitionProperties Properties { get; set; }
35+
}
36+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
// ----------------------------------------------------------------------------------
2+
//
3+
// Copyright Microsoft Corporation
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
// ----------------------------------------------------------------------------------
14+
15+
namespace Microsoft.Azure.Commands.ResourceManager.Cmdlets.Entities.Policy
16+
{
17+
using Newtonsoft.Json;
18+
using Newtonsoft.Json.Linq;
19+
20+
/// <summary>
21+
/// The policy definition properties.
22+
/// </summary>
23+
public class PolicySetDefinitionProperties
24+
{
25+
/// <summary>
26+
/// The description.
27+
/// </summary>
28+
[JsonProperty(Required = Required.Default)]
29+
public string Description { get; set; }
30+
31+
/// <summary>
32+
/// The display name.
33+
/// </summary>
34+
[JsonProperty(Required = Required.Default)]
35+
public string DisplayName { get; set; }
36+
37+
/// <summary>
38+
/// The policy set definition metadata.
39+
/// </summary>
40+
[JsonProperty(Required = Required.Default)]
41+
public JObject Metadata { get; set; }
42+
43+
/// <summary>
44+
/// The policy reference.
45+
/// </summary>
46+
[JsonProperty(Required = Required.Always)]
47+
public JArray PolicyDefinitions { get; set; }
48+
49+
/// <summary>
50+
/// The parameters declaration.
51+
/// </summary>
52+
[JsonProperty(Required = Required.Default)]
53+
public JObject Parameters { get; set; }
54+
}
55+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// ----------------------------------------------------------------------------------
2+
//
3+
// Copyright Microsoft Corporation
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
// ----------------------------------------------------------------------------------
14+
15+
using Newtonsoft.Json;
16+
17+
namespace Microsoft.Azure.Commands.ResourceManager.Cmdlets.Entities.Policy
18+
{
19+
/// <summary>
20+
/// The policy sku object.
21+
/// </summary>
22+
public class PolicySku
23+
{
24+
/// <summary>
25+
/// Gets or sets the <c>sku</c> name.
26+
/// </summary>
27+
[JsonProperty(Required = Required.Always)]
28+
public string Name { get; set; }
29+
30+
/// <summary>
31+
/// Gets or sets the <c>sku</c> tier.
32+
/// </summary>
33+
[JsonProperty(Required = Required.Default)]
34+
public string Tier { get; set; }
35+
}
36+
}
37+

src/ResourceManager/Resources/Commands.ResourceManager/Cmdlets/Implementation/Policy/GetAzurePolicyAssignment.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ namespace Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation
2525
/// Gets the policy assignment.
2626
/// </summary>
2727
[Cmdlet(VerbsCommon.Get, "AzureRmPolicyAssignment", DefaultParameterSetName = GetAzurePolicyAssignmentCmdlet.ParameterlessSet), OutputType(typeof(PSObject))]
28-
public class GetAzurePolicyAssignmentCmdlet : PolicyAssignmentCmdletBase
28+
public class GetAzurePolicyAssignmentCmdlet : PolicyCmdletBase
2929
{
3030
/// <summary>
3131
/// The policy Id parameter set.
@@ -91,7 +91,7 @@ private void RunCmdlet()
9191
getFirstPage: () => this.GetResources(),
9292
getNextPage: nextLink => this.GetNextLink<JObject>(nextLink),
9393
cancellationToken: this.CancellationToken,
94-
action: resources => this.WriteObject(sendToPipeline: this.GetOutputObjects(resources), enumerateCollection: true));
94+
action: resources => this.WriteObject(sendToPipeline: this.GetOutputObjects("PolicyAssignmentId", resources), enumerateCollection: true));
9595
}
9696

9797
/// <summary>
@@ -101,7 +101,7 @@ private async Task<ResponseWithContinuation<JObject[]>> GetResources()
101101
{
102102
string resourceId = this.Id ?? this.GetResourceId();
103103

104-
var apiVersion = string.IsNullOrWhiteSpace(this.ApiVersion) ? Constants.PolicyApiVersion : this.ApiVersion;
104+
var apiVersion = string.IsNullOrWhiteSpace(this.ApiVersion) ? Constants.PolicyAssignmentApiVersion : this.ApiVersion;
105105

106106
if (IsResourceGet(resourceId))
107107
{

0 commit comments

Comments
 (0)