1
1
import * as core from '@actions/core' ;
2
- import { cliScannerURL , iacMode , vmMode } from './scanner' ;
2
+ import { cliScannerResult , cliScannerURL , ComposeFlags , iacMode , scannerURLForVersion , vmMode } from './scanner' ;
3
3
4
4
export const defaultSecureEndpoint = "https://secure.sysdig.com/"
5
5
6
- export interface ActionInputs {
6
+ interface ActionInputParameters {
7
7
cliScannerURL : string ;
8
8
cliScannerVersion : string ;
9
9
registryUser : string ;
@@ -29,89 +29,240 @@ export interface ActionInputs {
29
29
iacScanPath : string ;
30
30
}
31
31
32
- export function parseActionInputs ( ) : ActionInputs {
33
- return {
34
- cliScannerURL : core . getInput ( 'cli-scanner-url' ) || cliScannerURL ,
35
- cliScannerVersion : core . getInput ( 'cli-scanner-version' ) ,
36
- registryUser : core . getInput ( 'registry-user' ) ,
37
- registryPassword : core . getInput ( 'registry-password' ) ,
38
- stopOnFailedPolicyEval : core . getInput ( 'stop-on-failed-policy-eval' ) == 'true' ,
39
- stopOnProcessingError : core . getInput ( 'stop-on-processing-error' ) == 'true' ,
40
- standalone : core . getInput ( 'standalone' ) == 'true' ,
41
- dbPath : core . getInput ( 'db-path' ) ,
42
- skipUpload : core . getInput ( 'skip-upload' ) == 'true' ,
43
- skipSummary : core . getInput ( 'skip-summary' ) == 'true' ,
44
- usePolicies : core . getInput ( 'use-policies' ) ,
45
- overridePullString : core . getInput ( 'override-pullstring' ) ,
46
- imageTag : core . getInput ( 'image-tag' ) ,
47
- sysdigSecureToken : core . getInput ( 'sysdig-secure-token' ) ,
48
- sysdigSecureURL : core . getInput ( 'sysdig-secure-url' ) || defaultSecureEndpoint ,
49
- sysdigSkipTLS : core . getInput ( 'sysdig-skip-tls' ) == 'true' ,
50
- severityAtLeast : core . getInput ( 'severity-at-least' ) || undefined ,
51
- groupByPackage : core . getInput ( 'group-by-package' ) == 'true' ,
52
- extraParameters : core . getInput ( 'extra-parameters' ) ,
53
- mode : core . getInput ( 'mode' ) || vmMode ,
54
- recursive : core . getInput ( 'recursive' ) == 'true' ,
55
- minimumSeverity : core . getInput ( 'minimum-severity' ) ,
56
- iacScanPath : core . getInput ( 'iac-scan-path' ) || './'
32
+ export class ActionInputs {
33
+ private readonly _params : ActionInputParameters ;
34
+ public get params ( ) : ActionInputParameters {
35
+ return this . _params ;
36
+ }
37
+ private constructor ( params : ActionInputParameters ) {
38
+ ActionInputs . validateInputs ( params ) ;
39
+ this . _params = params ;
57
40
}
58
- }
59
41
60
- export function validateInput ( opts : ActionInputs ) {
61
- if ( ! opts . standalone && ! opts . sysdigSecureToken ) {
62
- core . setFailed ( "Sysdig Secure Token is required for standard execution, please set your token or remove the standalone input." ) ;
63
- throw new Error ( "Sysdig Secure Token is required for standard execution, please set your token or remove the standalone input." ) ;
42
+ static from ( any : any ) : ActionInputs {
43
+ return new ActionInputs ( any as ActionInputParameters ) ;
64
44
}
65
45
66
- if ( opts . mode && opts . mode == vmMode && ! opts . imageTag ) {
67
- core . setFailed ( "image-tag is required for VM mode." ) ;
68
- throw new Error ( "image-tag is required for VM mode." ) ;
46
+ static fromJSON ( jsonContents : string ) : ActionInputs {
47
+ return ActionInputs . from ( JSON . parse ( jsonContents ) )
69
48
}
70
49
71
- if ( opts . mode && opts . mode == iacMode && opts . iacScanPath == "" ) {
72
- core . setFailed ( "iac-scan-path can't be empty, please specify the path you want to scan your manifest resources." ) ;
73
- throw new Error ( "iac-scan-path can't be empty, please specify the path you want to scan your manifest resources." ) ;
50
+ static parseActionInputs ( ) : ActionInputs {
51
+ return ActionInputs . overridingParsedActionInputs ( { } ) ;
74
52
}
75
- }
76
53
77
- export function printOptions ( opts : ActionInputs ) {
78
- if ( opts . standalone ) {
79
- core . info ( `[!] Running in Standalone Mode.` ) ;
54
+ static overridingParsedActionInputs ( overrides : { [ key : string ] : any } ) {
55
+
56
+ const params : ActionInputParameters = {
57
+ cliScannerURL : core . getInput ( 'cli-scanner-url' ) || cliScannerURL ,
58
+ cliScannerVersion : core . getInput ( 'cli-scanner-version' ) ,
59
+ registryUser : core . getInput ( 'registry-user' ) ,
60
+ registryPassword : core . getInput ( 'registry-password' ) ,
61
+ stopOnFailedPolicyEval : core . getInput ( 'stop-on-failed-policy-eval' ) == 'true' ,
62
+ stopOnProcessingError : core . getInput ( 'stop-on-processing-error' ) == 'true' ,
63
+ standalone : core . getInput ( 'standalone' ) == 'true' ,
64
+ dbPath : core . getInput ( 'db-path' ) ,
65
+ skipUpload : core . getInput ( 'skip-upload' ) == 'true' ,
66
+ skipSummary : core . getInput ( 'skip-summary' ) == 'true' ,
67
+ usePolicies : core . getInput ( 'use-policies' ) ,
68
+ overridePullString : core . getInput ( 'override-pullstring' ) ,
69
+ imageTag : core . getInput ( 'image-tag' ) ,
70
+ sysdigSecureToken : core . getInput ( 'sysdig-secure-token' ) ,
71
+ sysdigSecureURL : core . getInput ( 'sysdig-secure-url' ) || defaultSecureEndpoint ,
72
+ sysdigSkipTLS : core . getInput ( 'sysdig-skip-tls' ) == 'true' ,
73
+ severityAtLeast : core . getInput ( 'severity-at-least' ) || undefined ,
74
+ groupByPackage : core . getInput ( 'group-by-package' ) == 'true' ,
75
+ extraParameters : core . getInput ( 'extra-parameters' ) ,
76
+ mode : core . getInput ( 'mode' ) || vmMode ,
77
+ recursive : core . getInput ( 'recursive' ) == 'true' ,
78
+ minimumSeverity : core . getInput ( 'minimum-severity' ) ,
79
+ iacScanPath : core . getInput ( 'iac-scan-path' ) || './' ,
80
+ } ;
81
+
82
+ const overridenParams = {
83
+ ...params ,
84
+ ...overrides ,
85
+ } ;
86
+
87
+
88
+ return ActionInputs . from ( overridenParams ) ;
80
89
}
81
90
82
- if ( opts . sysdigSecureURL ) {
83
- core . info ( 'Sysdig Secure URL: ' + opts . sysdigSecureURL ) ;
91
+ get cliScannerURL ( ) : string {
92
+ return this . params . cliScannerURL
84
93
}
85
94
86
- if ( opts . registryUser && opts . registryPassword ) {
87
- core . info ( `Using specified Registry credentials.` ) ;
95
+ get mode ( ) {
96
+ return this . params . mode || vmMode ;
88
97
}
89
98
90
- core . info ( `Stop on Failed Policy Evaluation: ${ opts . stopOnFailedPolicyEval } ` ) ;
99
+ get stopOnProcessingError ( ) {
100
+ return this . params . stopOnProcessingError
101
+ }
91
102
92
- core . info ( `Stop on Processing Error: ${ opts . stopOnProcessingError } ` ) ;
103
+ get standalone ( ) {
104
+ return this . params . standalone
105
+ }
93
106
94
- if ( opts . skipUpload ) {
95
- core . info ( `Skipping scan results upload to Sysdig Secure...` ) ;
107
+ get stopOnFailedPolicyEval ( ) {
108
+ return this . params . stopOnFailedPolicyEval
96
109
}
97
110
98
- if ( opts . dbPath ) {
99
- core . info ( `DB Path: ${ opts . dbPath } ` ) ;
111
+ get skipSummary ( ) {
112
+ return this . params . skipSummary
100
113
}
101
114
102
- core . info ( `Sysdig skip TLS: ${ opts . sysdigSkipTLS } ` ) ;
115
+ get groupByPackage ( ) : boolean {
116
+ return this . params . groupByPackage
117
+ }
103
118
104
- if ( opts . severityAtLeast ) {
105
- core . info ( `Severity level: ${ opts . severityAtLeast } ` ) ;
119
+ get severityAtLeast ( ) {
120
+ return this . params . severityAtLeast
106
121
}
107
122
108
- core . info ( 'Analyzing image: ' + opts . imageTag ) ;
123
+ get imageTag ( ) {
124
+ return this . params . imageTag
125
+ }
109
126
110
- if ( opts . overridePullString ) {
111
- core . info ( ` * Image PullString will be overwritten as ${ opts . overridePullString } ` ) ;
127
+ get overridePullString ( ) {
128
+ return this . params . overridePullString
112
129
}
113
130
114
- if ( opts . skipSummary ) {
115
- core . info ( "This run will NOT generate a SUMMARY." ) ;
131
+ private static validateInputs ( params : ActionInputParameters ) {
132
+ if ( ! params . standalone && ! params . sysdigSecureToken ) {
133
+ core . setFailed ( "Sysdig Secure Token is required for standard execution, please set your token or remove the standalone input." ) ;
134
+ throw new Error ( "Sysdig Secure Token is required for standard execution, please set your token or remove the standalone input." ) ;
135
+ }
136
+
137
+ if ( params . mode && params . mode == vmMode && ! params . imageTag ) {
138
+ core . setFailed ( "image-tag is required for VM mode." ) ;
139
+ throw new Error ( "image-tag is required for VM mode." ) ;
140
+ }
141
+
142
+ if ( params . mode && params . mode == iacMode && params . iacScanPath == "" ) {
143
+ core . setFailed ( "iac-scan-path can't be empty, please specify the path you want to scan your manifest resources." ) ;
144
+ throw new Error ( "iac-scan-path can't be empty, please specify the path you want to scan your manifest resources." ) ;
145
+ }
146
+ }
147
+
148
+ // FIXME(fede) this also modifies the opts.cliScannerURL, which is something we don't want
149
+ public composeFlags ( ) : ComposeFlags {
150
+ if ( this . params . cliScannerVersion && this . params . cliScannerURL == cliScannerURL ) {
151
+ this . params . cliScannerURL = scannerURLForVersion ( this . params . cliScannerVersion )
152
+ }
153
+
154
+ let envvars : { [ key : string ] : string } = { }
155
+ envvars [ 'SECURE_API_TOKEN' ] = this . params . sysdigSecureToken || "" ;
156
+
157
+ let flags = ""
158
+
159
+ if ( this . params . registryUser ) {
160
+ envvars [ 'REGISTRY_USER' ] = this . params . registryUser ;
161
+ }
162
+
163
+ if ( this . params . registryPassword ) {
164
+ envvars [ 'REGISTRY_PASSWORD' ] = this . params . registryPassword ;
165
+ }
166
+
167
+ if ( this . params . standalone ) {
168
+ flags += " --standalone" ;
169
+ }
170
+
171
+ if ( this . params . sysdigSecureURL ) {
172
+ flags += ` --apiurl ${ this . params . sysdigSecureURL } ` ;
173
+ }
174
+
175
+ if ( this . params . dbPath ) {
176
+ flags += ` --dbpath=${ this . params . dbPath } ` ;
177
+ }
178
+
179
+ if ( this . params . skipUpload ) {
180
+ flags += ' --skipupload' ;
181
+ }
182
+
183
+ if ( this . params . usePolicies ) {
184
+ flags += ` --policy=${ this . params . usePolicies } ` ;
185
+ }
186
+
187
+ if ( this . params . sysdigSkipTLS ) {
188
+ flags += ` --skiptlsverify` ;
189
+ }
190
+
191
+ if ( this . params . overridePullString ) {
192
+ flags += ` --override-pullstring=${ this . params . overridePullString } ` ;
193
+ }
194
+
195
+ if ( this . params . extraParameters ) {
196
+ flags += ` ${ this . params . extraParameters } ` ;
197
+ }
198
+
199
+ if ( this . params . mode && this . params . mode == iacMode ) {
200
+ flags += ` --iac` ;
201
+ }
202
+
203
+ if ( this . params . recursive && this . params . mode == iacMode ) {
204
+ flags += ` -r` ;
205
+ }
206
+
207
+ if ( this . params . minimumSeverity && this . params . mode == iacMode ) {
208
+ flags += ` -f=${ this . params . minimumSeverity } ` ;
209
+ }
210
+
211
+ if ( this . params . mode && this . params . mode == vmMode ) {
212
+ flags += ` --json-scan-result=${ cliScannerResult } `
213
+ flags += ` ${ this . params . imageTag } ` ;
214
+ }
215
+
216
+ if ( this . params . mode && this . params . mode == iacMode ) {
217
+ flags += ` ${ this . params . iacScanPath } ` ;
218
+ }
219
+
220
+ return {
221
+ envvars : envvars ,
222
+ flags : flags
223
+ }
224
+ }
225
+
226
+ public printOptions ( ) {
227
+ if ( this . params . standalone ) {
228
+ core . info ( `[!] Running in Standalone Mode.` ) ;
229
+ }
230
+
231
+ if ( this . params . sysdigSecureURL ) {
232
+ core . info ( 'Sysdig Secure URL: ' + this . params . sysdigSecureURL ) ;
233
+ }
234
+
235
+ if ( this . params . registryUser && this . params . registryPassword ) {
236
+ core . info ( `Using specified Registry credentials.` ) ;
237
+ }
238
+
239
+ core . info ( `Stop on Failed Policy Evaluation: ${ this . params . stopOnFailedPolicyEval } ` ) ;
240
+
241
+ core . info ( `Stop on Processing Error: ${ this . params . stopOnProcessingError } ` ) ;
242
+
243
+ if ( this . params . skipUpload ) {
244
+ core . info ( `Skipping scan results upload to Sysdig Secure...` ) ;
245
+ }
246
+
247
+ if ( this . params . dbPath ) {
248
+ core . info ( `DB Path: ${ this . params . dbPath } ` ) ;
249
+ }
250
+
251
+ core . info ( `Sysdig skip TLS: ${ this . params . sysdigSkipTLS } ` ) ;
252
+
253
+ if ( this . params . severityAtLeast ) {
254
+ core . info ( `Severity level: ${ this . params . severityAtLeast } ` ) ;
255
+ }
256
+
257
+ core . info ( 'Analyzing image: ' + this . params . imageTag ) ;
258
+
259
+ if ( this . params . overridePullString ) {
260
+ core . info ( ` * Image PullString will be overwritten as ${ this . params . overridePullString } ` ) ;
261
+ }
262
+
263
+ if ( this . params . skipSummary ) {
264
+ core . info ( "This run will NOT generate a SUMMARY." ) ;
265
+ }
116
266
}
117
267
}
268
+
0 commit comments