Skip to content

Commit 3875dea

Browse files
authored
Merge pull request #950 from Azure/feature/apy/Get-AzExemptions_Fix946
fixed issue with exemptions output and starterkit remediation yaml
2 parents eb81bf6 + e4f6703 commit 3875dea

File tree

4 files changed

+39
-31
lines changed

4 files changed

+39
-31
lines changed

Scripts/Helpers/Get-CustomMetadata.ps1

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,16 @@ function Get-CustomMetadata {
77

88
# remove system generated metadata
99
$metadataTemp = ConvertTo-HashTable $Metadata
10-
if ($metadataTemp.ContainsKey("createdBy")) {
10+
if ($metadataTemp.Keys -contains "createdBy") {
1111
$metadataTemp.Remove("createdBy")
1212
}
13-
if ($metadataTemp.ContainsKey("createdOn")) {
13+
if ($metadataTemp.Keys -contains "createdOn") {
1414
$metadataTemp.Remove("createdOn")
1515
}
16-
if ($metadataTemp.ContainsKey("updatedBy")) {
16+
if ($metadataTemp.Keys -contains "updatedBy") {
1717
$metadataTemp.Remove("updatedBy")
1818
}
19-
if ($metadataTemp.ContainsKey("updatedOn")) {
19+
if ($metadataTemp.Keys -contains "updatedOn") {
2020
$metadataTemp.Remove("updatedOn")
2121
}
2222
if ($null -ne $Remove) {

Scripts/Helpers/Out-PolicyExemptions.ps1

Lines changed: 32 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -158,12 +158,14 @@ function Out-PolicyExemptions {
158158
}
159159
# Logic to force the order of the Metadata property (DeployedBy first, then epacMetadata)
160160
foreach ($array in $jsonArray) {
161-
$meta = $array.Metadata
162-
$orderedMeta = [ordered]@{
163-
deployedBy = $meta['deployedBy']
164-
epacMetadata = $meta['epacMetadata']
161+
if ($null -ne $array.Metadata) {
162+
$meta = $array.Metadata
163+
$orderedMeta = [ordered]@{
164+
deployedBy = $meta['deployedBy']
165+
epacMetadata = $meta['epacMetadata']
166+
}
167+
$array.Metadata = $orderedMeta
165168
}
166-
$array.Metadata = $orderedMeta
167169
}
168170
$jsonFile = "$stem.$FileExtension"
169171
if (Test-Path $jsonFile) {
@@ -193,14 +195,16 @@ function Out-PolicyExemptions {
193195
}
194196
# Logic to force the order of the Metadata property (DeployedBy first, then epacMetadata)
195197
foreach ($array in $excelArray) {
196-
$metaString = $array.Metadata
197-
$meta = $metaString | ConvertFrom-Json -Depth 100
198-
$orderedMeta = [ordered]@{
199-
deployedBy = $meta.deployedBy
200-
epacMetadata = $meta.epacMetadata
198+
if ($null -ne $array.Metadata) {
199+
$metaString = $array.Metadata
200+
$meta = $metaString | ConvertFrom-Json -Depth 100
201+
$orderedMeta = [ordered]@{
202+
deployedBy = $meta.deployedBy
203+
epacMetadata = $meta.epacMetadata
204+
}
205+
$orderedMetadata = (ConvertTo-Json $orderedMeta -Depth 100 -Compress).ToString()
206+
$array.Metadata = $orderedMetadata
201207
}
202-
$orderedMetadata = (ConvertTo-Json $orderedMeta -Depth 100 -Compress).ToString()
203-
$array.Metadata = $orderedMetadata
204208
}
205209
$csvFile = "$stem.csv"
206210
if (Test-Path $csvFile) {
@@ -246,12 +250,14 @@ function Out-PolicyExemptions {
246250
}
247251
# Logic to force the order of the Metadata property (DeployedBy first, then epacMetadata)
248252
foreach ($array in $jsonArray) {
249-
$meta = $array.Metadata
250-
$orderedMeta = [ordered]@{
251-
deployedBy = $meta['deployedBy']
252-
epacMetadata = $meta['epacMetadata']
253+
if ($null -ne $array.Metadata) {
254+
$meta = $array.Metadata
255+
$orderedMeta = [ordered]@{
256+
deployedBy = $meta['deployedBy']
257+
epacMetadata = $meta['epacMetadata']
258+
}
259+
$array.Metadata = $orderedMeta
253260
}
254-
$array.Metadata = $orderedMeta
255261
}
256262
$jsonFile = "$stem.$FileExtension"
257263
if (Test-Path $jsonFile) {
@@ -283,14 +289,16 @@ function Out-PolicyExemptions {
283289
}
284290
# Logic to force the order of the Metadata property (DeployedBy first, then epacMetadata)
285291
foreach ($array in $excelArray) {
286-
$metaString = $array.Metadata
287-
$meta = $metaString | ConvertFrom-Json -Depth 100
288-
$orderedMeta = [ordered]@{
289-
deployedBy = $meta.deployedBy
290-
epacMetadata = $meta.epacMetadata
292+
if ($null -ne $array.Metadata) {
293+
$metaString = $array.Metadata
294+
$meta = $metaString | ConvertFrom-Json -Depth 100
295+
$orderedMeta = [ordered]@{
296+
deployedBy = $meta.deployedBy
297+
epacMetadata = $meta.epacMetadata
298+
}
299+
$orderedMetadata = (ConvertTo-Json $orderedMeta -Depth 100 -Compress).ToString()
300+
$array.Metadata = $orderedMetadata
291301
}
292-
$orderedMetadata = (ConvertTo-Json $orderedMeta -Depth 100 -Compress).ToString()
293-
$array.Metadata = $orderedMetadata
294302
}
295303
$csvFile = "$stem.csv"
296304
if (Test-Path $csvFile) {

StarterKit/Pipelines/AzureDevOps/GitHub-Flow/epac-remediation-pipeline.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ schedules:
3333

3434
stages:
3535
- ${{ each pacEnvironment in parameters.pacEnvironmentsToRemediate }}:
36-
- stage: Remediate${{ pacEnvironment }}
36+
- stage: Remediate ${{ replace(pacEnvironment, '-', '') }}
3737
dependsOn: []
3838
displayName: "Remediate ${{ pacEnvironment }} environment"
3939
jobs:
@@ -43,4 +43,4 @@ stages:
4343
- template: templates/remediate.yml
4444
parameters:
4545
serviceConnection: $(remediationServiceConnection)
46-
pacEnvironmentSelector: ${{ pacEnvironment }}
46+
pacEnvironmentSelector: ${{ pacEnvironment }}

StarterKit/Pipelines/AzureDevOps/Release-Flow/epac-remediation-pipeline.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ schedules:
3434

3535
stages:
3636
- ${{ each pacEnvironment in parameters.pacEnvironmentsToRemediate }}:
37-
- stage: Remediate${{ pacEnvironment }}
37+
- stage: Remediate ${{ replace(pacEnvironment, '-', '') }}
3838
dependsOn: []
3939
displayName: "Remediate ${{ pacEnvironment }} environment"
4040
jobs:

0 commit comments

Comments
 (0)