Skip to content

Commit

Permalink
Merge pull request #25 from heww/prepare-vuls
Browse files Browse the repository at this point in the history
feat: support preparing vulnerabilities for the artifacts
  • Loading branch information
heww authored Aug 31, 2021
2 parents 128e9da + 0177e77 commit 3b85095
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
1 change: 1 addition & 0 deletions scripts/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export function Settings() {

settings['ProjectPrefix'] = getEnv('PROJECT_PREFIX', 'project')
settings['UserPrefix'] = getEnv('USER_PREFIX', 'user')
settings['ScannerURL'] = getEnv('SCANNER_URL', '')

return settings
}
Expand Down
50 changes: 50 additions & 0 deletions scripts/data/07-vulnerability.js
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 })
}

0 comments on commit 3b85095

Please sign in to comment.