-
Notifications
You must be signed in to change notification settings - Fork 27
Add Test-EntraScript to submodules #1454
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
Closed
Closed
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
1be0323
Test-entrascript for v1.0
emmanuel-karanja 0d2744f
Added md files and beta versions
emmanuel-karanja 0a6bc4b
Fixes to the docs
emmanuel-karanja 34ca9b4
fix to misnaming
emmanuel-karanja b42dc47
Comment missing cmdlets
KenitoInc e246bda
Merge branch 'main' into enganga/add-test-entrascript-to-submodules
SteveMutungi254 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
110 changes: 110 additions & 0 deletions
110
module/Entra/Microsoft.Entra/Applications/Test-EntraScript.ps1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
# ------------------------------------------------------------------------------ | ||
# Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License. See License in the project root for license information. | ||
# ------------------------------------------------------------------------------ | ||
|
||
function Test-EntraScript { | ||
[CmdletBinding()] | ||
param ( | ||
[Parameter(Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)] | ||
[Alias('FullName', 'Name')] | ||
[string[]] | ||
$Path, | ||
|
||
[Parameter(ValueFromPipelineByPropertyName = $true)] | ||
[string] | ||
$Content, | ||
|
||
[switch] | ||
$Quiet | ||
) | ||
|
||
begin { | ||
function Test-ScriptCommand { | ||
[CmdletBinding()] | ||
param ( | ||
[Parameter(Mandatory = $true)] | ||
[Alias('FullName')] | ||
[string] | ||
$Name, | ||
|
||
[Parameter(Mandatory = $true)] | ||
[string] | ||
$Content, | ||
|
||
[switch] | ||
$Quiet, | ||
|
||
[AllowEmptyCollection()] | ||
[string[]] | ||
$RequiredCommands, | ||
|
||
[AllowEmptyCollection()] | ||
[string[]] | ||
$ForbiddenCommands | ||
) | ||
|
||
$ast = [System.Management.Automation.Language.Parser]::ParseInput($Content, [ref]$null, [ref]$null) | ||
$allCommands = $ast.FindAll({ $args[0] -is [System.Management.Automation.Language.CommandAst] }, $true) | ||
$allCommandNames = @($allCommands).ForEach{ $_.CommandElements[0].Value } | ||
|
||
$findings = @() | ||
foreach ($command in $allCommands) { | ||
if ($command.CommandElements[0].Value -notin $ForbiddenCommands) { continue } | ||
$findings += [PSCustomObject]@{ | ||
PSTypeName = 'Microsoft.Entra.CommandRequirement' | ||
Name = $Name | ||
Line = $command.Extent.StartLineNumber | ||
Type = 'UnsupportedCommand' | ||
Command = $command.CommandElements[0].Value | ||
Code = $command.Extent.Text | ||
} | ||
} | ||
foreach ($requiredCommand in $RequiredCommands) { | ||
if ($requiredCommand -notin $allCommandNames) { continue } | ||
$findings += [PSCustomObject]@{ | ||
PSTypeName = 'Microsoft.Entra.CommandRequirement' | ||
Name = $Name | ||
Line = -1 | ||
Type = 'RequiredCommandMissing' | ||
Command = $requiredCommand | ||
Code = '' | ||
} | ||
} | ||
|
||
if (-not $Quiet) { | ||
$findings | ||
return | ||
} | ||
|
||
$findings -as [bool] | ||
} | ||
|
||
$testParam = @{ | ||
Quiet = $Quiet | ||
#ForbiddenCommands = $script:MISSING_CMDS # Originally set when using the Compat builder | ||
} | ||
} | ||
process { | ||
if ($Path -and $Content) { | ||
Test-ScriptCommand -Name @($Path)[0] -Content $Content | ||
return | ||
} | ||
foreach ($entry in $Path) { | ||
try { $resolvedPaths = Resolve-Path -Path $entry -ErrorAction Stop } | ||
catch { | ||
Write-Error $_ | ||
continue | ||
} | ||
|
||
foreach ($resolvedPath in $resolvedPaths) { | ||
if (-not (Test-Path -Path $resolvedPath -PathType Leaf)) { | ||
Write-Warning "Not a file: $resolvedPath" | ||
continue | ||
} | ||
|
||
$scriptContent = (Get-Content -LiteralPath $resolvedPath) -join "`n" | ||
Test-ScriptCommand -Name $resolvedPath -Content $scriptContent @testParam | ||
} | ||
} | ||
} | ||
} |
110 changes: 110 additions & 0 deletions
110
module/Entra/Microsoft.Entra/Authentication/Test-EntraScript.ps1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
# ------------------------------------------------------------------------------ | ||
# Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License. See License in the project root for license information. | ||
# ------------------------------------------------------------------------------ | ||
|
||
function Test-EntraScript { | ||
[CmdletBinding()] | ||
param ( | ||
[Parameter(Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)] | ||
[Alias('FullName', 'Name')] | ||
[string[]] | ||
$Path, | ||
|
||
[Parameter(ValueFromPipelineByPropertyName = $true)] | ||
[string] | ||
$Content, | ||
|
||
[switch] | ||
$Quiet | ||
) | ||
|
||
begin { | ||
function Test-ScriptCommand { | ||
[CmdletBinding()] | ||
param ( | ||
[Parameter(Mandatory = $true)] | ||
[Alias('FullName')] | ||
[string] | ||
$Name, | ||
|
||
[Parameter(Mandatory = $true)] | ||
[string] | ||
$Content, | ||
|
||
[switch] | ||
$Quiet, | ||
|
||
[AllowEmptyCollection()] | ||
[string[]] | ||
$RequiredCommands, | ||
|
||
[AllowEmptyCollection()] | ||
[string[]] | ||
$ForbiddenCommands | ||
) | ||
|
||
$ast = [System.Management.Automation.Language.Parser]::ParseInput($Content, [ref]$null, [ref]$null) | ||
$allCommands = $ast.FindAll({ $args[0] -is [System.Management.Automation.Language.CommandAst] }, $true) | ||
$allCommandNames = @($allCommands).ForEach{ $_.CommandElements[0].Value } | ||
|
||
$findings = @() | ||
foreach ($command in $allCommands) { | ||
if ($command.CommandElements[0].Value -notin $ForbiddenCommands) { continue } | ||
$findings += [PSCustomObject]@{ | ||
PSTypeName = 'Microsoft.Entra.CommandRequirement' | ||
Name = $Name | ||
Line = $command.Extent.StartLineNumber | ||
Type = 'UnsupportedCommand' | ||
Command = $command.CommandElements[0].Value | ||
Code = $command.Extent.Text | ||
} | ||
} | ||
foreach ($requiredCommand in $RequiredCommands) { | ||
if ($requiredCommand -notin $allCommandNames) { continue } | ||
$findings += [PSCustomObject]@{ | ||
PSTypeName = 'Microsoft.Entra.CommandRequirement' | ||
Name = $Name | ||
Line = -1 | ||
Type = 'RequiredCommandMissing' | ||
Command = $requiredCommand | ||
Code = '' | ||
} | ||
} | ||
|
||
if (-not $Quiet) { | ||
$findings | ||
return | ||
} | ||
|
||
$findings -as [bool] | ||
} | ||
|
||
$testParam = @{ | ||
Quiet = $Quiet | ||
#ForbiddenCommands = $script:MISSING_CMDS # Originally set when using the Compat builder | ||
} | ||
} | ||
process { | ||
if ($Path -and $Content) { | ||
Test-ScriptCommand -Name @($Path)[0] -Content $Content | ||
return | ||
} | ||
foreach ($entry in $Path) { | ||
try { $resolvedPaths = Resolve-Path -Path $entry -ErrorAction Stop } | ||
catch { | ||
Write-Error $_ | ||
continue | ||
} | ||
|
||
foreach ($resolvedPath in $resolvedPaths) { | ||
if (-not (Test-Path -Path $resolvedPath -PathType Leaf)) { | ||
Write-Warning "Not a file: $resolvedPath" | ||
continue | ||
} | ||
|
||
$scriptContent = (Get-Content -LiteralPath $resolvedPath) -join "`n" | ||
Test-ScriptCommand -Name $resolvedPath -Content $scriptContent @testParam | ||
} | ||
} | ||
} | ||
} |
110 changes: 110 additions & 0 deletions
110
module/Entra/Microsoft.Entra/DirectoryManagement/Test-EntraScript.ps1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
# ------------------------------------------------------------------------------ | ||
# Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License. See License in the project root for license information. | ||
# ------------------------------------------------------------------------------ | ||
|
||
function Test-EntraScript { | ||
[CmdletBinding()] | ||
param ( | ||
[Parameter(Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)] | ||
[Alias('FullName', 'Name')] | ||
[string[]] | ||
$Path, | ||
|
||
[Parameter(ValueFromPipelineByPropertyName = $true)] | ||
[string] | ||
$Content, | ||
|
||
[switch] | ||
$Quiet | ||
) | ||
|
||
begin { | ||
function Test-ScriptCommand { | ||
[CmdletBinding()] | ||
param ( | ||
[Parameter(Mandatory = $true)] | ||
[Alias('FullName')] | ||
[string] | ||
$Name, | ||
|
||
[Parameter(Mandatory = $true)] | ||
[string] | ||
$Content, | ||
|
||
[switch] | ||
$Quiet, | ||
|
||
[AllowEmptyCollection()] | ||
[string[]] | ||
$RequiredCommands, | ||
|
||
[AllowEmptyCollection()] | ||
[string[]] | ||
$ForbiddenCommands | ||
) | ||
|
||
$ast = [System.Management.Automation.Language.Parser]::ParseInput($Content, [ref]$null, [ref]$null) | ||
$allCommands = $ast.FindAll({ $args[0] -is [System.Management.Automation.Language.CommandAst] }, $true) | ||
$allCommandNames = @($allCommands).ForEach{ $_.CommandElements[0].Value } | ||
|
||
$findings = @() | ||
foreach ($command in $allCommands) { | ||
if ($command.CommandElements[0].Value -notin $ForbiddenCommands) { continue } | ||
$findings += [PSCustomObject]@{ | ||
PSTypeName = 'Microsoft.Entra.CommandRequirement' | ||
Name = $Name | ||
Line = $command.Extent.StartLineNumber | ||
Type = 'UnsupportedCommand' | ||
Command = $command.CommandElements[0].Value | ||
Code = $command.Extent.Text | ||
} | ||
} | ||
foreach ($requiredCommand in $RequiredCommands) { | ||
if ($requiredCommand -notin $allCommandNames) { continue } | ||
$findings += [PSCustomObject]@{ | ||
PSTypeName = 'Microsoft.Entra.CommandRequirement' | ||
Name = $Name | ||
Line = -1 | ||
Type = 'RequiredCommandMissing' | ||
Command = $requiredCommand | ||
Code = '' | ||
} | ||
} | ||
|
||
if (-not $Quiet) { | ||
$findings | ||
return | ||
} | ||
|
||
$findings -as [bool] | ||
} | ||
|
||
$testParam = @{ | ||
Quiet = $Quiet | ||
#ForbiddenCommands = $script:MISSING_CMDS # Originally set when using the Compat builder | ||
} | ||
} | ||
process { | ||
if ($Path -and $Content) { | ||
Test-ScriptCommand -Name @($Path)[0] -Content $Content | ||
return | ||
} | ||
foreach ($entry in $Path) { | ||
try { $resolvedPaths = Resolve-Path -Path $entry -ErrorAction Stop } | ||
catch { | ||
Write-Error $_ | ||
continue | ||
} | ||
|
||
foreach ($resolvedPath in $resolvedPaths) { | ||
if (-not (Test-Path -Path $resolvedPath -PathType Leaf)) { | ||
Write-Warning "Not a file: $resolvedPath" | ||
continue | ||
} | ||
|
||
$scriptContent = (Get-Content -LiteralPath $resolvedPath) -join "`n" | ||
Test-ScriptCommand -Name $resolvedPath -Content $scriptContent @testParam | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this logic correct? should we continue when a required command is not found?