Setting the file. One moment.
Scan Aspire Functions Secrets · Azure Validate · microsoft/azure-skills · Skills Docs
ContentsBack to the top of the page 28.8
Errors · azd
(opens in a new tab)
references/scripts/ scan-aspire-functions-secrets.ps1
PowerShell · 84 lines · 3 KB
15 a non-zero exit only indicates a usage/environment error.
16 . PARAMETER Path
17 Directory to scan. Defaults to the current directory.
18 . EXAMPLE
19 .\scan-aspire-functions-secrets.ps1
20 # Scan the current directory
21 . EXAMPLE
22 .\scan-aspire-functions-secrets.ps1 -Path ./src
23 # Scan a specific directory
24 #>
25 param (
26 [ string ]$Path = "."
27 )
28
29 # Leave $ErrorActionPreference at its default ("Continue") so that Write-Error
30 # below is non-terminating and the explicit `exit` codes are honored.
31
32 if ( -not ( Test-Path - LiteralPath $Path - PathType Container)) {
33 Write-Error "' $Path ' is not a directory."
34 exit 2
35 }
36
37 $call = "AddAzureFunctionsProject"
38 $setting = "AzureWebJobsSecretStorageType"
39
40 # Collect *.cs files that reference AddAzureFunctionsProject.
41 $matches = Get-ChildItem - Path $Path - Recurse - File - Filter "*.cs" |
42 Where-Object { Select-String - Path $_ .FullName - SimpleMatch - Pattern $call - Quiet }
43
44 if ( -not $matches ) {
45 Write-Output "VERDICT: NOT APPLICABLE"
46 Write-Output "No ' $call ' call found in any *.cs file under ' $Path '."
47 Write-Output "The Functions secret-storage check does not apply - skip it."
48 exit 0
49 }
50
51 # Partition matching files by whether they already configure the setting.
52 $needsFix = @ ()
53 $configured = @ ()
54 foreach ($file in $matches ) {
55 if ( Select-String - Path $file.FullName - SimpleMatch - Pattern $setting - Quiet) {
56 $configured += $file
57 } else {
58 $needsFix += $file
59 }
60 }
61
62 if ($needsFix.Count -eq 0 ) {
63 Write-Output "VERDICT: ALREADY CONFIGURED"
64 Write-Output "Every file that calls ' $call ' already sets ' $setting ':"
65 foreach ($file in $configured) {
66 $line = ( Select-String - Path $file.FullName - SimpleMatch - Pattern $setting |
67 Select-Object - First 1 ).LineNumber
68 Write-Output " - $( $file.FullName ) (line $line )"
69 }
70 Write-Output "No change required."
71 exit 0
72 }
73
74 Write-Output "VERDICT: FIX REQUIRED"
75 Write-Output "The following file(s) call ' $call ' but do NOT set ' $setting ':"
76 foreach ($file in $needsFix) {
77 $line = ( Select-String - Path $file.FullName - SimpleMatch - Pattern $call |
78 Select-Object - First 1 ).LineNumber
79 Write-Output " - $( $file.FullName ) (line $line )"
80 }
81 Write-Output ""
82 Write-Output "Add .WithEnvironment( `" $setting `" , `" Files `" ) to the AddAzureFunctionsProject"
83 Write-Output "builder chain in each file above BEFORE running 'azd provision'."
84 exit 0