Skip to content

Commit 0309b66

Browse files
authored
Merge pull request #665 from MicrosoftDocs/fix/credscan
Fix/credscan
2 parents ddc1a97 + cccd26e commit 0309b66

File tree

3 files changed

+69
-68
lines changed

3 files changed

+69
-68
lines changed

azure-pipelines/config/credscan/credscan-suppressions.json

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,19 @@
6161
"msgraph-sdk-powershell\\src\\Users.Actions\\v1.0\\examples\\Update-MgUserPassword.md",
6262
"msgraph-sdk-powershell\\src\\Users.Actions\\v1.0\\examples\\Reset-MgUserAuthenticationMethodPassword.md",
6363
"microsoftgraph\\graph-powershell-beta\\Microsoft.Graph.Beta.Users.Actions\\Reset-MgBetaUserAuthenticationMethodPassword.md",
64-
"microsoftgraph\\graph-powershell-1.0\\Microsoft.Graph.Users.Actions\\Reset-MgUserAuthenticationMethodPassword.md"
64+
"microsoftgraph\\graph-powershell-1.0\\Microsoft.Graph.Users.Actions\\Reset-MgUserAuthenticationMethodPassword.md",
65+
"microsoftgraph\\graph-powershell-beta\\Microsoft.Graph.Beta.Users.Actions\\Convert-MgBetaUserExternalToInternalMemberUser.md"
6566
],
6667
"_justification": "[Users.Actions] Examples contain random values recognized as secret"
6768
},
69+
{
70+
"file": [
71+
"microsoftgraph\\graph-powershell-beta\\Microsoft.Graph.Beta.Identity.SignIns\\Reset-MgBetaUserAuthenticationMethodPassword.md",
72+
"microsoftgraph\\graph-powershell-1.0\\Microsoft.Graph.Identity.SignIns\\Reset-MgUserAuthenticationMethodPassword.md"
73+
],
74+
"_justification": "[Identity.SignIns] Examples contain random values recognized as secret"
75+
},
76+
6877
{
6978
"file": [
7079
"msgraph-sdk-powershell\\src\\DeviceManagement.Actions\\beta\\examples\\Update-MgBetaDeviceManagementVirtualEndpointOnPremiseConnectionAdDomainPassword.md",

msgraph-sdk-powershell

scripts/GenerateMarkDown.ps1

Lines changed: 58 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -4,49 +4,33 @@
44
Param(
55
$ModulesToGenerate = @(),
66
[string] $ModuleMappingConfigPath = (Join-Path $PSScriptRoot "../microsoftgraph/config\ModulesMapping.jsonc"),
7-
[string] $WorkLoadDocsPath = (Join-Path $PSScriptRoot "../microsoftgraph"),
8-
[string] $CmdletMetadataPath = (Join-Path $PSScriptRoot "../msgraph-sdk-powershell/src/Authentication/Authentication/custom/common/MgCommandMetadata.json")
7+
[string] $WorkLoadDocsPath = (Join-Path $PSScriptRoot "../microsoftgraph")
98
)
109
function Get-GraphMapping {
1110
$graphMapping = @{}
1211
$graphMapping.Add("v1.0", "graph-powershell-1.0")
1312
$graphMapping.Add("beta", "graph-powershell-beta")
1413
return $graphMapping
1514
}
16-
function Set-Help {
15+
function Generate-Help {
1716
param (
1817
[ValidateNotNullOrEmpty()]
1918
[string] $ModuleDocsPath,
2019
[ValidateNotNullOrEmpty()]
21-
[string] $Command,
22-
[ValidateNotNullOrEmpty()]
23-
[string]$Module
20+
[string] $Module
2421
)
25-
2622
$generationParams = @{
27-
Command = $Command
23+
Module = $Module
2824
OutputFolder = $ModuleDocsPath
2925
AlphabeticParamsOrder = $true
26+
WithModulePage = $true
3027
ExcludeDontShow = $true
31-
Force = $true
3228
Encoding = [System.Text.Encoding]::UTF8
3329
}
34-
35-
if ($Module -eq "Microsoft.Graph.Authentication") {
36-
$generationParams = @{
37-
Module = $Module
38-
OutputFolder = $ModuleDocsPath
39-
AlphabeticParamsOrder = $true
40-
ExcludeDontShow = $true
41-
WithModulePage = $true
42-
Encoding = [System.Text.Encoding]::UTF8
43-
}
44-
Import-Module $Module -Force -Global
45-
}
4630
New-MarkdownHelp @generationParams
4731
}
4832

49-
function Start-GraphHelp {
33+
function Generate-GraphHelp {
5034
Param(
5135
$ModulesToGenerate = @()
5236
)
@@ -56,6 +40,7 @@ function Start-GraphHelp {
5640
$AuthPath = "$ModulePrefix.Authentication"
5741
$AuthDestination = Join-Path $WorkLoadDocsPath "graph-powershell-1.0" $AuthPath
5842
Get-ChildItem -Path $AuthDestination * -File -Recurse | foreach { $_.Delete() }
43+
Generate-GraphModuleHelp -GraphProfile "v1.0" -GraphProfilePath "graph-powershell-1.0" -ModuleName "Authentication" -ModulePrefix $ModulePrefix
5944

6045
Import-Module Microsoft.Graph.Authentication -Global
6146
$GraphMapping = Get-GraphMapping
@@ -65,10 +50,8 @@ function Start-GraphHelp {
6550
if ($graphProfile -eq "beta") {
6651
$profilePath = "graph-powershell-beta"
6752
}
68-
69-
$AuthenticationDocsPath = Join-Path $PSScriptRoot "..\microsoftgraph\graph-powershell-1.0\Microsoft.Graph.Authentication"
70-
Set-Help -ModuleDocsPath $AuthenticationDocsPath -Command "AuthCommands" -Module "Microsoft.Graph.Authentication"
71-
Get-FolderByProfile -GraphProfile $graphProfile -GraphProfilePath $profilePath -ModulePrefix $ModulePrefix -ModulesToGenerate $ModulesToGenerate
53+
Get-FolderByProfile -GraphProfile $graphProfile -GraphProfilePath $profilePath -ModulePrefix $ModulePrefix -ModulesToGenerate $ModulesToGenerate
54+
Generate-GraphHelpByProfile -GraphProfile $graphProfile -GraphProfilePath $GraphMapping[$graphProfile] -ModulePrefix $ModulePrefix -ModulesToGenerate $ModulesToGenerate
7255
}
7356
git config --global user.email "[email protected]"
7457
git config --global user.name "Microsoft Graph DevX Tooling"
@@ -87,61 +70,70 @@ function Get-FolderByProfile {
8770
[ValidateNotNullOrEmpty()]
8871
$ModulesToGenerate = @()
8972
)
90-
$CommandMetadataContent = Get-Content $CmdletMetadataPath | ConvertFrom-Json
9173

9274
$ModulesToGenerate | ForEach-Object {
9375
$ModuleName = $_
94-
$ModName = $ModuleName
9576
$Path = "$ModulePrefix.$ModuleName"
9677
if ($GraphProfile -eq 'beta') {
9778
$Path = "$ModulePrefix.Beta.$ModuleName"
98-
$ModName = "Beta.$ModuleName"
9979
}
10080
$Destination = Join-Path $WorkLoadDocsPath $GraphProfilePath $Path
10181
if (-not(Test-Path $Destination)) {
10282
New-Item -Path $Destination -ItemType Directory
10383
}
10484

10585
Get-ChildItem -Path $Destination * -File -Recurse | foreach { $_.Delete() }
106-
$CmdletCount = 0
107-
# Generate table of contents for each module
108-
$TocFileName = "$Path.md"
109-
$ModuleGuid = [guid]::NewGuid().ToString()
110-
$LinkProfile = $GraphProfile.Replace("v", "")
111-
$LinkModuleName = $Path.ToLower()
112-
$HelpVersion = "1.0.0.0"
113-
$HelpLocale = "en-US"
114-
$DownloadLink = "https://learn.microsoft.com/en-us/powershell/module/$LinkModuleName/?view=graph-powershell-$LinkProfile"
115-
New-Item -Path $Destination -Name $TocFileName -ItemType File -Force
116-
Add-Content -Path $Destination\$TocFileName -Value "---"
117-
Add-Content -Path $Destination\$TocFileName -Value "Module Name: $Path"
118-
Add-Content -Path $Destination\$TocFileName -Value "Module Guid: $ModuleGuid"
119-
Add-Content -Path $Destination\$TocFileName -Value "Download Help Link: $DownloadLink"
120-
Add-Content -Path $Destination\$TocFileName -Value "Help Version: $HelpVersion"
121-
Add-Content -Path $Destination\$TocFileName -Value "Locale: $HelpLocale"
122-
Add-Content -Path $Destination\$TocFileName -Value "---"
123-
Add-Content -Path $Destination\$TocFileName -Value ""
124-
Add-Content -Path $Destination\$TocFileName -Value "# $Path Module"
125-
Add-Content -Path $Destination\$TocFileName -Value "## Description"
126-
Add-Content -Path $Destination\$TocFileName -Value "Microsoft Graph PowerShell Cmdlets"
127-
Add-Content -Path $Destination\$TocFileName -Value ""
128-
Add-Content -Path $Destination\$TocFileName -Value "## $Path Cmdlets"
129-
$CommandMetadataContent | Where-Object { $_.Module -eq $ModName -and $_.ApiVersion -eq $GraphProfile } | ForEach-Object {
130-
$Command = $_.Command
131-
$CmdletDocsPath = Join-Path $WorkLoadDocsPath $GraphProfilePath $Path "$Command.md"
132-
if (-not(Test-Path $CmdletDocsPath)) {
133-
Set-Help -ModuleDocsPath $Destination -Command $Command -Module $Path
86+
}
87+
88+
}
89+
function Generate-GraphHelpByProfile {
90+
Param(
91+
[ValidateSet("beta", "v1.0")]
92+
[string] $GraphProfile = "v1.0",
93+
[ValidateNotNullOrEmpty()]
94+
[string] $GraphProfilePath = "graph-powershell-1.0",
95+
[ValidateNotNullOrEmpty()]
96+
[string] $ModulePrefix = "Microsoft.Graph",
97+
[ValidateNotNullOrEmpty()]
98+
$ModulesToGenerate = @()
99+
)
100+
$ModulesToGenerate | ForEach-Object {
101+
$ModuleName = $_
102+
Generate-GraphModuleHelp -GraphProfile $GraphProfile -GraphProfilePath $GraphProfilePath -ModuleName $ModuleName -ModulePrefix $ModulePrefix
103+
}
104+
}
105+
106+
function Generate-GraphModuleHelp {
107+
param(
108+
[ValidateSet("beta", "v1.0")]
109+
[string] $GraphProfile = "v1.0",
110+
[ValidateNotNullOrEmpty()]
111+
[string] $GraphProfilePath = "graph-powershell-1.0",
112+
[ValidateNotNullOrEmpty()]
113+
[string] $ModuleName = "Users",
114+
[ValidateNotNullOrEmpty()]
115+
[string] $ModulePrefix = "Microsoft.Graph"
116+
)
117+
try {
118+
$Module = "$ModulePrefix.$ModuleName"
119+
if ($Module -ne "Microsoft.Graph.WindowsUpdates") {
120+
$Path = "$ModulePrefix.$ModuleName"
121+
if ($GraphProfile -eq 'beta') {
122+
$Module = "$ModulePrefix.Beta.$ModuleName"
123+
$Path = "$ModulePrefix.Beta.$ModuleName"
134124
}
135-
Add-Content -Path $Destination\$TocFileName -Value "### [$Command]($Command.md)"
136-
Add-Content -Path $Destination\$TocFileName -Value ""
137-
$CmdletCount++
138-
}
139-
if($CmdletCount -eq 0){
140-
Remove-Item -LiteralPath $Destination -Force -Recurse
141-
}
125+
$ModuleDocsPath = Join-Path $PSScriptRoot "..\microsoftgraph\$GraphProfilePath\$Path"
142126

127+
Import-Module $Module -Force -Global
128+
Generate-Help -ModuleDocsPath $ModuleDocsPath -Module $Module
129+
}
130+
}
131+
catch {
132+
Write-Host "`nError Message: " $_.Exception.Message
133+
Write-Host "`nError in Line: " $_.InvocationInfo.Line
134+
Write-Host "`nError in Line Number: "$_.InvocationInfo.ScriptLineNumber
135+
Write-Host "`nError Item Name: "$_.Exception.ItemName
143136
}
144-
145137
}
146138
# Install PlatyPS
147139
if (!(Get-Module -Name PlatyPS -ListAvailable)) {
@@ -162,5 +154,5 @@ if ($ModulesToGenerate.Count -eq 0) {
162154
$ModulesToGenerate = $ModuleMapping.Keys
163155
}
164156
Write-Host -ForegroundColor Green "-------------finished checking out to today's branch-------------"
165-
Start-GraphHelp -ModulesToGenerate $ModulesToGenerate
157+
Generate-GraphHelp -ModulesToGenerate $ModulesToGenerate
166158
Write-Host -ForegroundColor Green "-------------Done-------------"

0 commit comments

Comments
 (0)