Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement default formatting to all resources #5480

Merged
merged 3 commits into from
Nov 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

# UNRELEASED

* All resources
* Applying project default formatting on all files, to improve
reading and troubleshooting
* IntuneTrustedRootCertificateIOS
* Initial release

Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,29 +1,24 @@
{
"resourceName": "AADAccessReviewDefinition",
"description": "This resource configures an Azure AD Access Review Definition.",
"permissions": {
"graph": {
"delegated": {
"read": [
{
"name": "AccessReview.Read.All"
}
],
"update": [

]
},
"application": {
"read": [
{
"name": "AccessReview.Read.All"
}
],
"update": [

]
}
}
}

"permissions": {
"graph": {
"delegated": {
"read": [
{
"name": "AccessReview.Read.All"
}
],
"update": []
},
"application": {
"read": [
{
"name": "AccessReview.Read.All"
}
],
"update": []
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ function Get-TargetResource

#Azure portal timeout
$timeout = $getValue.Definition | ConvertFrom-Json
$AzurePortalTimeOut = ($timeout.ActivityBasedTimeoutPolicy.ApplicationPolicies | Where-Object{$_.ApplicationId -match "c44b4083-3bb0-49c1-b47d-974e53cbdf3c"}).WebSessionIdleTimeout
$DefaultTimeOut = ($timeout.ActivityBasedTimeoutPolicy.ApplicationPolicies | Where-Object{$_.ApplicationId -match "default"}).WebSessionIdleTimeout
$AzurePortalTimeOut = ($timeout.ActivityBasedTimeoutPolicy.ApplicationPolicies | Where-Object { $_.ApplicationId -match 'c44b4083-3bb0-49c1-b47d-974e53cbdf3c' }).WebSessionIdleTimeout
$DefaultTimeOut = ($timeout.ActivityBasedTimeoutPolicy.ApplicationPolicies | Where-Object { $_.ApplicationId -match 'default' }).WebSessionIdleTimeout

$results = @{
#region resource generator code
Expand Down Expand Up @@ -191,46 +191,47 @@ function Set-TargetResource
$BoundParameters = Remove-M365DSCAuthenticationParameter -BoundParameters $PSBoundParameters
$AzurePortalTimeOutexist = $false
$DefaultTimeOutexistst = $false
if($BoundParameters.ContainsKey('AzurePortalTimeOut') `
if ($BoundParameters.ContainsKey('AzurePortalTimeOut') `
-and $null -ne $BoundParameters.AzurePortalTimeOut `
-and $BoundParameters.AzurePortalTimeOut -ne '' `
-and $BoundParameters.AzurePortalTimeOut -ne $nullString)
{
$AzurePortalTimeOutexist = $true
}
if($BoundParameters.ContainsKey('DefaultTimeOut') `
{
$AzurePortalTimeOutexist = $true
}
if ($BoundParameters.ContainsKey('DefaultTimeOut') `
-and $null -ne $BoundParameters.DefaultTimeOut `
-and $BoundParameters.DefaultTimeOut -ne '' `
-and $BoundParameters.DefaultTimeOut -ne $nullString)
{
$DefaultTimeOutexistst = $true
}
{
$DefaultTimeOutexistst = $true
}
$ApplicationPolicies = @()
if ($Ensure -eq 'Present' -and $currentInstance.Ensure -eq 'Absent')
{
Write-Verbose -Message "Creating an Azure AD Activity Based Timeout Policy with DisplayName {$DisplayName}"
if($AzurePortalTimeOutexist)
if ($AzurePortalTimeOutexist)
{
$ApplicationPolicies += @{
ApplicationId = "c44b4083-3bb0-49c1-b47d-974e53cbdf3c"
WebSessionIdleTimeout = "$AzurePortalTimeOut"
}
ApplicationId = 'c44b4083-3bb0-49c1-b47d-974e53cbdf3c'
WebSessionIdleTimeout = "$AzurePortalTimeOut"
}
}
if($DefaultTimeOutexistst)
if ($DefaultTimeOutexistst)
{
$ApplicationPolicies += @{
ApplicationId = "default"
ApplicationId = 'default'
WebSessionIdleTimeout = "$DefaultTimeOut"
}
}
if($null -eq $ApplicationPolicies)
if ($null -eq $ApplicationPolicies)
{
throw "At least one of the parameters AzurePortalTimeOut or DefaultTimeOut must be specified"
throw 'At least one of the parameters AzurePortalTimeOut or DefaultTimeOut must be specified'
}
elseif($AzurePortalTimeOutexist -or $DefaultTimeOutexistst) {
elseif ($AzurePortalTimeOutexist -or $DefaultTimeOutexistst)
{
$policy = @{
ActivityBasedTimeoutPolicy = @{
Version = 1
Version = 1
ApplicationPolicies = @(
$ApplicationPolicies
)
Expand All @@ -239,10 +240,10 @@ function Set-TargetResource

$json = $policy | ConvertTo-Json -Depth 10 -Compress
$params = @{
definition = @(
definition = @(
"$json"
)
displayName = "displayName-value"
displayName = 'displayName-value'
isOrganizationDefault = $true
}

Expand All @@ -252,28 +253,29 @@ function Set-TargetResource
elseif ($Ensure -eq 'Present' -and $currentInstance.Ensure -eq 'Present')
{
Write-Verbose -Message "Creating an Azure AD Activity Based Timeout Policy with DisplayName {$DisplayName}"
if($AzurePortalTimeOutexist)
if ($AzurePortalTimeOutexist)
{
$ApplicationPolicies += @{
ApplicationId = "c44b4083-3bb0-49c1-b47d-974e53cbdf3c"
WebSessionIdleTimeout = "$AzurePortalTimeOut"
}
ApplicationId = 'c44b4083-3bb0-49c1-b47d-974e53cbdf3c'
WebSessionIdleTimeout = "$AzurePortalTimeOut"
}
}
if($DefaultTimeOutexistst)
if ($DefaultTimeOutexistst)
{
$ApplicationPolicies += @{
ApplicationId = "default"
ApplicationId = 'default'
WebSessionIdleTimeout = "$DefaultTimeOut"
}
}
if($null -eq $ApplicationPolicies)
if ($null -eq $ApplicationPolicies)
{
throw "At least one of the parameters AzurePortalTimeOut or DefaultTimeOut must be specified"
throw 'At least one of the parameters AzurePortalTimeOut or DefaultTimeOut must be specified'
}
elseif($AzurePortalTimeOutexist -or $DefaultTimeOutexistst) {
elseif ($AzurePortalTimeOutexist -or $DefaultTimeOutexistst)
{
$policy = @{
ActivityBasedTimeoutPolicy = @{
Version = 1
Version = 1
ApplicationPolicies = @(
$ApplicationPolicies
)
Expand All @@ -282,10 +284,10 @@ function Set-TargetResource

$json = $policy | ConvertTo-Json -Depth 10 -Compress
$params = @{
definition = @(
definition = @(
"$json"
)
displayName = "displayName-value"
displayName = 'displayName-value'
isOrganizationDefault = $true
}

Expand Down Expand Up @@ -501,14 +503,14 @@ function Export-TargetResource
}
Write-Host " |---[$i/$($getValue.Count)] $displayedKey" -NoNewline
$params = @{
DisplayName = $config.displayName
Ensure = 'Present'
Credential = $Credential
ApplicationId = $ApplicationId
TenantId = $TenantId
ApplicationSecret = $ApplicationSecret
DisplayName = $config.displayName
Ensure = 'Present'
Credential = $Credential
ApplicationId = $ApplicationId
TenantId = $TenantId
ApplicationSecret = $ApplicationSecret
CertificateThumbprint = $CertificateThumbprint
Managedidentity = $ManagedIdentity.IsPresent
Managedidentity = $ManagedIdentity.IsPresent
}

$Results = Get-TargetResource @Params
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ function Get-TargetResource
}
elseif ($reviewer.Query.Contains('directory/roleAssignments?$'))
{
$roleId = $reviewer.Query.Replace("/beta/roleManagement/directory/roleAssignments?`$filter=roleDefinitionId eq ", "").Replace("'", '')
$roleId = $reviewer.Query.Replace("/beta/roleManagement/directory/roleAssignments?`$filter=roleDefinitionId eq ", '').Replace("'", '')
$roleInfo = Get-MgBetaRoleManagementDirectoryRoleDefinition -UnifiedRoleDefinitionId $roleId
$entry = @{
ReviewerType = 'Role'
Expand Down Expand Up @@ -274,8 +274,8 @@ function Set-TargetResource
Write-Verbose -Message "Updating the Entra Id Admin Consent Request Policy with values: $updateJSON"
$Uri = $Global:MSCloudLoginConnectionProfile.MicrosoftGraph.ResourceUrl + 'beta/policies/adminConsentRequestPolicy'
Invoke-MgGraphRequest -Method 'PUT' `
-Uri $Uri `
-Body $updateJSON | Out-Null
-Uri $Uri `
-Body $updateJSON | Out-Null
}

function Test-TargetResource
Expand Down Expand Up @@ -358,7 +358,7 @@ function Test-TargetResource
$testResult = $true
foreach ($reviewer in $Reviewers)
{
$currentEquivalent = $CurrentValues.Reviewers | Where-Object -FilterScript {$_.ReviewerId -eq $reviewer.ReviewerId -and $_.ReviewerType -eq $reviewer.ReviewerType}
$currentEquivalent = $CurrentValues.Reviewers | Where-Object -FilterScript { $_.ReviewerId -eq $reviewer.ReviewerId -and $_.ReviewerType -eq $reviewer.ReviewerType }
if ($null -eq $currentEquivalent)
{
$testResult = $false
Expand Down Expand Up @@ -482,7 +482,7 @@ function Export-TargetResource

if ($Results.Reviewers)
{
$currentDSCBlock = Convert-DSCStringParamToVariable -DSCBlock $currentDSCBlock -ParameterName "Reviewers" -IsCIMArray:$true
$currentDSCBlock = Convert-DSCStringParamToVariable -DSCBlock $currentDSCBlock -ParameterName 'Reviewers' -IsCIMArray:$true
}
$dscContent += $currentDSCBlock
Save-M365DSCPartialExport -Content $currentDSCBlock `
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ function Get-TargetResource
Write-Verbose -Message ($_)
}

#Ensure the proper dependencies are installed in the current environment.
Confirm-M365DSCDependencies
#Ensure the proper dependencies are installed in the current environment.
Confirm-M365DSCDependencies

#region Telemetry
$ResourceName = $MyInvocation.MyCommand.ModuleName.Replace('MSFT_', '')
Expand All @@ -114,7 +114,7 @@ function Get-TargetResource
{
if ($null -ne $Script:exportedInstances -and $Script:ExportMode)
{
$getValue = $Script:exportedInstances | Where-Object -FilterScript {$_.Id -eq $Id}
$getValue = $Script:exportedInstances | Where-Object -FilterScript { $_.Id -eq $Id }
}
else
{
Expand All @@ -129,7 +129,7 @@ function Get-TargetResource
{
if ($null -ne $Script:exportedInstances -and $Script:ExportMode)
{
$getValue = $Script:exportedInstances | Where-Object -FilterScript {$_.DisplayName -eq $DisplayName}
$getValue = $Script:exportedInstances | Where-Object -FilterScript { $_.DisplayName -eq $DisplayName }
}
else
{
Expand Down Expand Up @@ -1020,42 +1020,44 @@ function Export-TargetResource
ErrorAction = 'Stop'
}
$queryTypes = @{
'eq' = @('description')
'startsWith' = @('description')
'eq null' = @(
'description',
'displayName'
)
'eq' = @('description')
'startsWith' = @('description')
'eq null' = @(
'description',
'displayName'
)
}

#extract arguments from the query
# Define the regex pattern to match all words in the query
$pattern = "([^\s,()]+)"
$pattern = '([^\s,()]+)'
$query = $Filter

# Match all words in the query
$matches = [regex]::matches($query, $pattern)

# Extract the matched argument into an array
$arguments = @()
foreach ($match in $matches) {
$arguments += $match.Value
foreach ($match in $matches)
{
$arguments += $match.Value
}

#extracting keys to check vs arguments in the filter
$Keys = $queryTypes.Keys

$matchedKey = $arguments | Where-Object { $_ -in $Keys }
$matchedProperty = $arguments | Where-Object { $_ -in $queryTypes[$matchedKey]}
if ($matchedProperty -and $matchedKey) {
$matchedProperty = $arguments | Where-Object { $_ -in $queryTypes[$matchedKey] }
if ($matchedProperty -and $matchedKey)
{
$allConditionsMatched = $true
}

# If all conditions match the support, add parameters to $ExportParameters
if ($allConditionsMatched -or $Filter -like '*endsWith*')
{
$ExportParameters.Add('CountVariable', 'count')
$ExportParameters.Add('headers', @{"ConsistencyLevel" = "Eventual"})
$ExportParameters.Add('headers', @{'ConsistencyLevel' = 'Eventual' })
}

[array] $Script:exportedInstances = Get-MgBetaDirectoryAdministrativeUnit @ExportParameters
Expand Down Expand Up @@ -1145,9 +1147,9 @@ function Export-TargetResource
if ($null -ne $Results.Members)
{
$currentDSCBlock = Convert-DSCStringParamToVariable -DSCBlock $currentDSCBlock -ParameterName 'Members' -IsCIMArray $true
$currentDSCBlock = $currentDSCBlock.Replace("`",`"`r`n", "")
$currentDSCBlock = $currentDSCBlock.Replace("`",`"`r`n", '')
$currentDSCBlock = $currentDSCBlock.Replace(",`r`n", '').Replace("`");`r`n", ");`r`n")
$currentDSCBlock = $currentDSCBlock.Replace("Members = @(`"", "Members = @(")
$currentDSCBlock = $currentDSCBlock.Replace("Members = @(`"", 'Members = @(')
$currentDSCBlock = $currentDSCBlock.Replace("`$OrganizationName'", "' + `$OrganizationName")
}
$dscContent += $currentDSCBlock
Expand Down
Loading