Skip to content

Commit 97401fa

Browse files
authored
Component governance fix and build scan error fix (#264)
1 parent 5f7baa4 commit 97401fa

12 files changed

+67
-232
lines changed

Tools/PowershellModule/src/Library/Find-WinGetManifest.ps1

+21-7
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ Function Find-WinGetManifest
7979

8080
$FunctionAppId = $FunctionApp.Id
8181
$DefaultHostName = $FunctionApp.DefaultHostName
82-
82+
8383
$TriggerName = "ManifestSearchPost"
8484
$ApiContentType = "application/json"
8585
$ApiMethod = "Post"
@@ -95,21 +95,35 @@ Function Find-WinGetManifest
9595
PROCESS
9696
{
9797
Write-Verbose -Message "Invoking the REST API call."
98-
98+
99+
## Internal scan does not recognize ternary oprator, use if else here
100+
if ($Exact) {
101+
$QueryMatchType = "Exact"
102+
}
103+
else {
104+
$QueryMatchType = "Substring"
105+
}
99106
$RequestBody = @{
100107
Query = @{
101108
KeyWord = $Query
102-
MatchType = $Exact ? "Exact" : "Substring"
109+
MatchType = $QueryMatchType
103110
}
104111
Filters = @()
105112
}
106113

114+
## Internal scan does not recognize ternary oprator, use if else here
115+
if ($Exact) {
116+
$FilterMatchType = "Exact"
117+
}
118+
else {
119+
$FilterMatchType = "CaseInsensitive"
120+
}
107121
if (![string]::IsNullOrWhiteSpace($PackageIdentifier)) {
108122
$RequestBody.Filters += @{
109123
PackageMatchField = "PackageIdentifier"
110124
RequestMatch = @{
111125
KeyWord = $PackageIdentifier
112-
MatchType = $Exact ? "Exact" : "CaseInsensitive"
126+
MatchType = $FilterMatchType
113127
}
114128
}
115129
}
@@ -118,7 +132,7 @@ Function Find-WinGetManifest
118132
PackageMatchField = "PackageName"
119133
RequestMatch = @{
120134
KeyWord = $PackageName
121-
MatchType = $Exact ? "Exact" : "CaseInsensitive"
135+
MatchType = $FilterMatchType
122136
}
123137
}
124138
}
@@ -131,7 +145,7 @@ Function Find-WinGetManifest
131145
if ($ContinuationToken) {
132146
$ApiHeader["ContinuationToken"] = $ContinuationToken
133147
}
134-
148+
135149
$Response = Invoke-RestMethod $AzFunctionURL -Headers $ApiHeader -Method $ApiMethod -Body $RequestBodyJson -ContentType $ApiContentType -ErrorVariable ErrorInvoke
136150

137151
if ($ErrorInvoke) {
@@ -164,7 +178,7 @@ Function Find-WinGetManifest
164178
$Return += $ManifestInfo
165179
}
166180
}
167-
181+
168182
$ContinuationToken = $Response.ContinuationToken
169183
} while (![string]::IsNullOrWhiteSpace($ContinuationToken))
170184
}

Tools/PowershellModule/src/Library/New-ARMObjects.ps1

+17-3
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,20 @@ Function New-ARMObjects
6565
return $true
6666
}
6767

68+
function Get-SecureString
69+
{
70+
param(
71+
[string] $InputString
72+
)
73+
74+
$Result = New-Object SecureString
75+
foreach ($char in $InputString.ToCharArray()) {
76+
$Result.AppendChar($char)
77+
}
78+
79+
return $Result
80+
}
81+
6882
## TODO: Consider multiple instances of same Azure Resource in the future
6983
## Azure resource names retrieved from the Parameter files.
7084
$StorageAccountName = $ARMObjects.Where({$_.ObjectType -eq "StorageAccount"}).Parameters.Parameters.storageAccountName.value
@@ -93,15 +107,15 @@ Function New-ARMObjects
93107

94108
## Pre ARM deployment operations
95109
if ($Object.ObjectType -eq "Function") {
96-
$CosmosAccountEndpointValue = $(Get-AzCosmosDBAccount -Name $CosmosAccountName -ResourceGroupName $ResourceGroup).DocumentEndpoint | ConvertTo-SecureString -AsPlainText -Force
110+
$CosmosAccountEndpointValue = Get-SecureString($(Get-AzCosmosDBAccount -Name $CosmosAccountName -ResourceGroupName $ResourceGroup).DocumentEndpoint)
97111
Write-Verbose "Creating Keyvault Secret for Azure CosmosDB endpoint."
98112
$Result = Set-AzKeyVaultSecret -VaultName $KeyVaultName -Name $CosmosAccountEndpointKeyName -SecretValue $CosmosAccountEndpointValue -ErrorVariable ErrorSet
99113
if ($ErrorSet) {
100114
Write-Error "Failed to set keyvault secret. Name: $CosmosAccountEndpointKeyName Error: $ErrorSet"
101115
return $false
102116
}
103117

104-
$AppConfigEndpointValue = $(Get-AzAppConfigurationStore -Name $AppConfigName -ResourceGroupName $ResourceGroup).Endpoint | ConvertTo-SecureString -AsPlainText -Force
118+
$AppConfigEndpointValue = Get-SecureString($(Get-AzAppConfigurationStore -Name $AppConfigName -ResourceGroupName $ResourceGroup).Endpoint)
105119
Write-Verbose "Creating Keyvault Secret for Azure App Config endpoint."
106120
$Result = Set-AzKeyVaultSecret -VaultName $KeyVaultName -Name $AppConfigPrimaryEndpointName -SecretValue $AppConfigEndpointValue -ErrorVariable ErrorSet
107121
if ($ErrorSet) {
@@ -210,7 +224,7 @@ Function New-ARMObjects
210224
}
211225

212226
Write-Information -MessageData "Add Function App host key to keyvault."
213-
$Result = Set-AzKeyVaultSecret -VaultName $KeyVaultName -Name $AzureFunctionHostKeyName -SecretValue ($NewFunctionKeyValue | ConvertTo-SecureString -AsPlainText -Force) -ErrorVariable ErrorSet
227+
$Result = Set-AzKeyVaultSecret -VaultName $KeyVaultName -Name $AzureFunctionHostKeyName -SecretValue (Get-SecureString($NewFunctionKeyValue)) -ErrorVariable ErrorSet
214228
if ($ErrorSet) {
215229
Write-Error "Failed to set keyvault secret. Name: $AzureFunctionHostKeyName Error: $ErrorSet"
216230
return $false

Tools/PowershellModule/src/Library/New-ARMParameterObjects.ps1

+2-2
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ Function New-ARMParameterObjects
261261
Parameters = @{
262262
name = @{ value = $KeyVaultName }
263263
location = @{ value = $Region }
264-
sku = @{ value = $KeyVaultSKU}
264+
sku = @{ value = $KeyVaultSKU }
265265
accessPolicies = @{
266266
value = @(
267267
@{
@@ -505,4 +505,4 @@ Function New-ARMParameterObjects
505505

506506
## Returns the completed object.
507507
return $ARMObjects
508-
}
508+
}

pipelines/templates/binSkim.yml

-43
This file was deleted.

pipelines/templates/compliance.yml

-28
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Template helper to copy PowerShell scripts and all dependencies
22
parameters:
3-
helperLibsPath: '$(Build.SourcesDirectory)\src\WinGet.RestSource.PowershellSupport\bin\$(BuildConfiguration)\netcoreapp3.1'
3+
powershellSupportPath: '$(Build.SourcesDirectory)\src\WinGet.RestSource.PowershellSupport\bin\$(BuildConfiguration)\net8.0'
44
templatesPath: '$(Build.SourcesDirectory)\src\WinGet.RestSource.Infrastructure\bin\$(BuildConfiguration)\Templates'
55

66
steps:
@@ -13,26 +13,31 @@ steps:
1313
OverWrite: true
1414

1515
# Publish Helper Libs - win-x86
16-
- task: DotNetCoreCLI@2
17-
displayName: 'Package Helper Libs: Portable'
16+
- task: CopyFiles@2
17+
displayName: 'Copy Files: WinGet.RestSource.PowershellSupport'
1818
inputs:
19-
command: publish
20-
publishWebProjects: false
21-
projects: '$(Build.SourcesDirectory)\src\WinGet.RestSource.PowershellSupport\WinGet.RestSource.PowershellSupport.csproj'
22-
arguments: '--configuration $(BuildConfiguration) --output $(Build.ArtifactStagingDirectory)\Winget.PowerShell.Source\Library --no-restore'
23-
zipAfterPublish: false
19+
SourceFolder: ${{ parameters.powershellSupportPath }}
20+
Contents: |
21+
Microsoft.Extensions.Logging.Abstractions.dll
22+
Microsoft.WinGet.PowershellSupport.dll
23+
Microsoft.WinGet.RestSource.Utils.dll
24+
WinGetUtilInterop.dll
25+
YamlDotNet.dll
26+
runtimes\**\native\WinGetUtil.dll
27+
TargetFolder: '$(Build.ArtifactStagingDirectory)\Winget.PowerShell.Source\Library\WinGet.RestSource.PowershellSupport'
28+
OverWrite: true
2429

2530
- task: CopyFiles@2
2631
displayName: 'Copy Files: Arm Templates'
2732
inputs:
2833
Contents: ${{ parameters.templatesPath }}\**\*.json
29-
TargetFolder: '$(Build.ArtifactStagingDirectory)\Winget.PowerShell.Source\Library\ARMTemplate'
34+
TargetFolder: '$(Build.ArtifactStagingDirectory)\Winget.PowerShell.Source\Data\ARMTemplates'
3035
OverWrite: true
3136
flattenFolders: true
3237

3338
- task: CopyFiles@2
3439
displayName: 'Copy Files: azure function'
3540
inputs:
3641
SourceFolder: '$(Build.ArtifactStagingDirectory)\WinGet.RestSource.Functions'
37-
TargetFolder: '$(Build.ArtifactStagingDirectory)\Winget.PowerShell.Source\Library\RestAPI'
42+
TargetFolder: '$(Build.ArtifactStagingDirectory)\Winget.PowerShell.Source\Data'
3843
OverWrite: true

pipelines/templates/package.yml renamed to pipelines/templates/publish.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Template helper to package projects (using DotNetCoreCLI Publish Command)
1+
# Template helper to publish projects (using DotNetCoreCLI Publish Command)
22
parameters:
33
name: ''
44
projects: ''
@@ -7,7 +7,7 @@ parameters:
77

88
steps:
99
- task: DotNetCoreCLI@2
10-
displayName: 'Package Azure Function: WinGet.RestSource-${{ parameters.name }}'
10+
displayName: 'Publish: WinGet.RestSource-${{ parameters.name }}'
1111
inputs:
1212
command: publish
1313
publishWebProjects: false

pipelines/templates/restore-build-publish-test.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,15 @@ steps:
3939
source: '$(Build.SourcesDirectory)\scripts\Release'
4040

4141
# Publish Rest Function App
42-
- template: package.yml@self
42+
- template: publish.yml@self
4343
parameters:
4444
name: WinGet.RestSource.Functions
4545
projects: '$(Build.SourcesDirectory)\src\WinGet.RestSource.Functions\WinGet.RestSource.Functions.csproj'
4646
buildconfig: '$(BuildConfiguration)'
4747
zipAfterPublish: True
4848

4949
# Publish Rest Function App
50-
- template: package.yml@self
50+
- template: publish.yml@self
5151
parameters:
5252
name: WinGet.RestSource.IntegrationTest
5353
projects: '$(Build.SourcesDirectory)\src\WinGet.RestSource.IntegrationTest\WinGet.RestSource.IntegrationTest.csproj'

0 commit comments

Comments
 (0)