forked from dotnet/dnceng
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcodeql.ps1
More file actions
206 lines (166 loc) · 6.42 KB
/
codeql.ps1
File metadata and controls
206 lines (166 loc) · 6.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
function Install-Gdn {
param(
[Parameter(Mandatory)]
[string]$Path,
[string]$Version
)
$installArgs = @("install", "Microsoft.Guardian.Cli", "-Source https://securitytools.pkgs.visualstudio.com/_packaging/Guardian/nuget/v3/index.json", "-OutputDirectory $Path", "-NonInteractive", "-NoCache")
if($Version)
{
$installArgs += "-Version $Version"
}
Start-Process nuget -Verbose -ArgumentList $installArgs -NoNewWindow -Wait
$gdnCliPath = Get-ChildItem -Filter guardian.cmd -Recurse -Path $Path
return $gdnCliPath.FullName
}
function Initialize-Gdn {
param(
[Parameter(Mandatory)]
[string]$GuardianCliLocation,
[Parameter(Mandatory)]
[string]$WorkingDirectory,
[ValidateSet("Trace", "Verbose", "Standard", "Warning", "Error")]
[string]$LoggerLevel = "Standard"
)
if (!(Test-Path $GuardianCliLocation)) {
throw "GuardianCliLocation not found"
}
& $GuardianCliLocation init --working-directory $WorkingDirectory --logger-level $LoggerLevel
}
function New-GdnSemmleConfig {
param(
[Parameter(Mandatory)]
[string]$GuardianCliLocation,
[Parameter(Mandatory)]
[string]$Language,
[Parameter(Mandatory)]
[string]$WorkingDirectory,
[ValidateSet("Trace", "Verbose", "Standard", "Warning", "Error")]
[string]$LoggerLevel = "Standard",
[ValidateSet("SuiteSDLRequired", "SuiteSDLRecommended")]
[string]$Suite = "SuiteSDLRequired",
[string]$BuildCommand,
[Parameter(Mandatory)]
[string]$SourceCodeDirectory,
[Parameter(Mandatory)]
[string]$OutputPath,
# Additional semmle configuration in splat form, "ParameterName < ParameterValue"
[string[]]$AdditionalSemmleParameters,
[switch]$Force
)
if (!(Test-Path $GuardianCliLocation)) {
throw "GuardianCliLocation not found"
}
[string[]]$splatParameters = "SourceCodeDirectory < $SourceCodeDirectory", "Language < $Language"
if ($BuildCommand) {
$splatParameters = $splatParameters + "BuildCommands < $BuildCommand"
}
if ($Suite) {
$splatParameters = $splatParameters + "Suite < `$($Suite)"
}
if ($AdditionalSemmleParameters) {
$splatParameters = $splatParameters + $AdditionalSemmleParameters
}
# Surround each parameter name-value pair with quotes and separate with a comma
$splatParametersString = '"' + $($splatParameters -Join '" "') + '"'
if ($Force) {
Start-Process -Verbose -NoNewWindow -Wait $GuardianCliLocation -ArgumentList "configure", "--noninteractive", "--working-directory $WorkingDirectory", "--tool semmle", "--output-path $OutputPath", "--logger-level $LoggerLevel", "--args $splatParametersString", "-Force"
} else {
Start-Process -Verbose -NoNewWindow -Wait $GuardianCliLocation -ArgumentList "configure", "--noninteractive", "--working-directory $WorkingDirectory", "--tool semmle", "--output-path $OutputPath", "--logger-level $LoggerLevel", "--args $splatParametersString"
}
Get-Content $OutputPath
}
function Invoke-GdnSemmle {
param(
[Parameter(Mandatory)]
[string]$GuardianCliLocation,
[Parameter(Mandatory)]
[string]$ConfigurationPath,
[Parameter(Mandatory)]
[string]$WorkingDirectory,
[ValidateSet("Trace", "Verbose", "Standard", "Warning", "Error")]
[string]$LoggerLevel = "Standard"
)
if (!(Test-Path $GuardianCliLocation)) {
throw "GuardianCliLocation not found"
}
& $GuardianCliLocation run --not-break-on-detections --working-directory $WorkingDirectory --logger-level $LoggerLevel --config $ConfigurationPath
}
function Publish-GdnArtifacts {
param(
[Parameter(Mandatory)]
[string]$GuardianCliLocation,
[Parameter(Mandatory)]
[string]$WorkingDirectory,
[ValidateSet("Trace", "Verbose", "Standard", "Warning", "Error")]
[string]$LoggerLevel = "Standard"
)
if (!(Test-Path $GuardianCliLocation)) {
throw "GuardianCliLocation not found"
}
& $GuardianCliLocation publish-artifacts --working-directory $WorkingDirectory --logger-level $LoggerLevel
}
function Invoke-GdnBuildBreak {
param (
[Parameter(Mandatory)]
[string]$GuardianCliLocation,
[Parameter(Mandatory)]
[string]$WorkingDirectory,
[ValidateSet("Trace", "Verbose", "Standard", "Warning", "Error")]
[string]$LoggerLevel = "Standard"
)
if (!(Test-Path $GuardianCliLocation)) {
throw "GuardianCliLocation not found"
}
& $GuardianCliLocation break --working-directory $WorkingDirectory --logger-level $LoggerLevel
}
function Publish-GdnTsa {
param (
[Parameter(Mandatory)]
[string]$GuardianCliLocation,
[Parameter(Mandatory)]
[string]$WorkingDirectory,
[ValidateSet("Trace", "Verbose", "Standard", "Warning", "Error")]
[string]$LoggerLevel = 'Standard',
[Parameter(Mandatory)]
[string]$TsaRepositoryName,
[Parameter(Mandatory)]
[string]$TsaCodebaseName,
[Parameter(Mandatory)]
[string]$TsaNotificationEmail,
[Parameter(Mandatory)]
[string]$TsaCodebaseAdmin,
[Parameter(Mandatory)]
# Must be known to TSA
[string]$TsaInstanceUrl,
[Parameter(Mandatory)]
# Must be known to TSA
[string]$TsaProjectName,
[Parameter(Mandatory)]
[string]$TsaBugAreaPath,
[Parameter(Mandatory)]
[string]$TsaIterationPath,
[bool]$OnBoard = $true,
[bool]$TsaPublish = $true
)
if (!$TsaPublish)
{
Write-Host "TsaPublish is 'false', skipping publish"
return
}
if (!(Test-Path $GuardianCliLocation)) {
throw "GuardianCliLocation not found"
}
& $guardianCliLocation tsa-publish --all-tools `
--working-directory $workingDirectory `
--logger-level $LoggerLevel `
--repository-name "$TsaRepositoryName" `
--codebase-name "$TsaCodebaseName" `
--notification-alias "$TsaNotificationEmail" `
--codebase-admin "$TsaCodebaseAdmin" `
--instance-url "$TsaInstanceUrl" `
--project-name "$TsaProjectName" `
--area-path "$TsaBugAreaPath" `
--iteration-path "$TsaIterationPath" `
--onboard $OnBoard
}