2022-03-31 18:31:39 +02:00
|
|
|
import * as z from 'zod'
|
2022-06-01 12:09:11 +02:00
|
|
|
|
|
|
|
|
export const SEVERITIES = ['critical', 'high', 'moderate', 'low'] as const
|
2022-09-15 17:53:34 +00:00
|
|
|
export const SCOPES = ['unknown', 'runtime', 'development'] as const
|
2022-03-31 18:31:39 +02:00
|
|
|
|
2022-09-21 16:30:05 +02:00
|
|
|
export const SeveritySchema = z.enum(SEVERITIES).default('low')
|
2022-03-31 18:31:39 +02:00
|
|
|
|
2022-05-31 06:06:19 +02:00
|
|
|
export const ChangeSchema = z.object({
|
2022-03-31 18:31:39 +02:00
|
|
|
change_type: z.enum(['added', 'removed']),
|
|
|
|
|
manifest: z.string(),
|
|
|
|
|
ecosystem: z.string(),
|
|
|
|
|
name: z.string(),
|
|
|
|
|
version: z.string(),
|
|
|
|
|
package_url: z.string(),
|
|
|
|
|
license: z.string().nullable(),
|
|
|
|
|
source_repository_url: z.string().nullable(),
|
2022-09-16 19:13:58 +00:00
|
|
|
scope: z.enum(SCOPES).optional(),
|
2022-03-31 18:31:39 +02:00
|
|
|
vulnerabilities: z
|
|
|
|
|
.array(
|
|
|
|
|
z.object({
|
2022-09-21 16:30:05 +02:00
|
|
|
severity: SeveritySchema,
|
2022-03-31 18:31:39 +02:00
|
|
|
advisory_ghsa_id: z.string(),
|
|
|
|
|
advisory_summary: z.string(),
|
|
|
|
|
advisory_url: z.string()
|
|
|
|
|
})
|
|
|
|
|
)
|
|
|
|
|
.optional()
|
2022-06-01 05:36:46 +02:00
|
|
|
.default([])
|
2022-03-31 18:31:39 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
|
|
export const PullRequestSchema = z.object({
|
|
|
|
|
number: z.number(),
|
2022-06-01 12:09:11 +02:00
|
|
|
base: z.object({sha: z.string()}),
|
|
|
|
|
head: z.object({sha: z.string()})
|
2022-03-31 18:31:39 +02:00
|
|
|
})
|
|
|
|
|
|
2022-06-01 12:09:11 +02:00
|
|
|
export const ConfigurationOptionsSchema = z
|
|
|
|
|
.object({
|
2022-09-21 16:30:05 +02:00
|
|
|
fail_on_severity: SeveritySchema,
|
2022-09-15 18:48:58 +00:00
|
|
|
fail_on_scopes: z.array(z.enum(SCOPES)).default(['runtime']),
|
2022-11-07 17:08:00 +00:00
|
|
|
allow_licenses: z.array(z.string()).optional(),
|
|
|
|
|
deny_licenses: z.array(z.string()).optional(),
|
2023-04-06 09:37:42 +02:00
|
|
|
allow_dependencies_licenses: z.array(z.string()).optional(),
|
2022-09-22 21:34:18 +00:00
|
|
|
allow_ghsas: z.array(z.string()).default([]),
|
2023-08-07 14:04:41 +02:00
|
|
|
deny_packages: z.array(z.string()).default([]),
|
|
|
|
|
deny_groups: z.array(z.string()).default([]),
|
2022-10-28 21:59:30 +02:00
|
|
|
license_check: z.boolean().default(true),
|
|
|
|
|
vulnerability_check: z.boolean().default(true),
|
2022-11-07 17:08:00 +00:00
|
|
|
config_file: z.string().optional(),
|
|
|
|
|
base_ref: z.string().optional(),
|
2023-02-03 10:35:46 +00:00
|
|
|
head_ref: z.string().optional(),
|
2023-09-06 18:04:10 +00:00
|
|
|
retry_on_snapshot_warnings: z.boolean().default(false),
|
2023-08-31 16:23:39 +00:00
|
|
|
retry_on_snapshot_warnings_timeout: z.number().default(120),
|
2023-08-09 15:57:03 -04:00
|
|
|
comment_summary_in_pr: z
|
2023-08-09 21:10:48 -04:00
|
|
|
.union([
|
|
|
|
|
z.preprocess(
|
|
|
|
|
val => (val === 'true' ? true : val === 'false' ? false : val),
|
|
|
|
|
z.boolean()
|
|
|
|
|
),
|
|
|
|
|
z.enum(['always', 'never', 'on-failure'])
|
|
|
|
|
])
|
2024-01-28 10:16:07 +01:00
|
|
|
.default('never'),
|
2023-06-12 11:26:44 +02:00
|
|
|
warn_only: z.boolean().default(false)
|
2022-11-07 17:08:00 +00:00
|
|
|
})
|
2023-08-09 15:57:03 -04:00
|
|
|
.transform(config => {
|
|
|
|
|
if (config.comment_summary_in_pr === true) {
|
|
|
|
|
config.comment_summary_in_pr = 'always'
|
|
|
|
|
} else if (config.comment_summary_in_pr === false) {
|
|
|
|
|
config.comment_summary_in_pr = 'never'
|
|
|
|
|
}
|
|
|
|
|
return config
|
2022-11-07 17:08:00 +00:00
|
|
|
})
|
|
|
|
|
.superRefine((config, context) => {
|
|
|
|
|
if (config.allow_licenses && config.deny_licenses) {
|
|
|
|
|
context.addIssue({
|
|
|
|
|
code: z.ZodIssueCode.custom,
|
|
|
|
|
message: 'You cannot specify both allow-licenses and deny-licenses'
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
if (config.allow_licenses && config.allow_licenses.length < 1) {
|
|
|
|
|
context.addIssue({
|
|
|
|
|
code: z.ZodIssueCode.custom,
|
|
|
|
|
message: 'You should provide at least one license in allow-licenses'
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
if (
|
|
|
|
|
config.license_check === false &&
|
|
|
|
|
config.vulnerability_check === false
|
|
|
|
|
) {
|
|
|
|
|
context.addIssue({
|
|
|
|
|
code: z.ZodIssueCode.custom,
|
|
|
|
|
message: "Can't disable both license-check and vulnerability-check"
|
|
|
|
|
})
|
|
|
|
|
}
|
2022-06-01 12:09:11 +02:00
|
|
|
})
|
2022-06-01 06:36:02 +02:00
|
|
|
|
2022-03-31 18:31:39 +02:00
|
|
|
export const ChangesSchema = z.array(ChangeSchema)
|
2023-03-22 21:13:20 +00:00
|
|
|
export const ComparisonResponseSchema = z.object({
|
|
|
|
|
changes: z.array(ChangeSchema),
|
|
|
|
|
snapshot_warnings: z.string()
|
|
|
|
|
})
|
2022-06-01 06:36:02 +02:00
|
|
|
|
2022-05-31 06:06:19 +02:00
|
|
|
export type Change = z.infer<typeof ChangeSchema>
|
2022-03-31 18:31:39 +02:00
|
|
|
export type Changes = z.infer<typeof ChangesSchema>
|
2023-03-22 21:13:20 +00:00
|
|
|
export type ComparisonResponse = z.infer<typeof ComparisonResponseSchema>
|
2022-06-01 06:36:02 +02:00
|
|
|
export type ConfigurationOptions = z.infer<typeof ConfigurationOptionsSchema>
|
2022-09-21 16:50:02 +02:00
|
|
|
export type Severity = z.infer<typeof SeveritySchema>
|
2023-01-09 07:59:55 +01:00
|
|
|
export type Scope = (typeof SCOPES)[number]
|