-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #25 from heww/prepare-vuls
feat: support preparing vulnerabilities for the artifacts
- Loading branch information
Showing
2 changed files
with
51 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// prepare vulnerabiliies for the artifact | ||
import { Rate } from 'k6/metrics' | ||
import harbor from 'k6/x/harbor' | ||
|
||
import { Settings } from '../config.js' | ||
import { retry } from '../helpers.js' | ||
|
||
const settings = Settings() | ||
|
||
export let successRate = new Rate('success') | ||
|
||
export let options = { | ||
setupTimeout: '6h', | ||
duration: '24h', | ||
vus: 1, | ||
iterations: 1, | ||
thresholds: { | ||
'success': ['rate>=1'], | ||
'iteration_duration{scenario:default}': [ | ||
`max>=0`, | ||
], | ||
'iteration_duration{group:::setup}': [`max>=0`], | ||
} | ||
}; | ||
|
||
export function setup() { | ||
harbor.initialize(settings.Harbor) | ||
} | ||
|
||
export default function () { | ||
if (settings.ScannerURL === '') { | ||
console.log('SCANNER_URL is not found, skip to prepare vulnerabilities for the artifacts') | ||
successRate.add(true) | ||
|
||
return | ||
} | ||
|
||
harbor.setScannerAsDefault(harbor.createScanner({ name: `scanner-${Date.now()}`, url: settings.ScannerURL })) | ||
|
||
harbor.startScanAll() | ||
|
||
retry(() => { | ||
const metrics = harbor.getScanAllMetrics() | ||
if (metrics.ongoing) { | ||
throw new Error('scan all is ongoing') | ||
} | ||
|
||
successRate.add(true) | ||
}, { times: 1440, interval: 60 }) | ||
} |