Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[OSSFScorecard] Create scorecard badge service #7687

Merged
merged 55 commits into from
Apr 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
6d97a9f
security scorecards badge
rohankh532 Mar 6, 2022
769a2f0
Merge branch 'badges:master' into master
rohankh532 Mar 6, 2022
e2d69b8
Create scorecards.yml
rohankh532 Mar 22, 2022
476449b
Delete scorecards.yml
rohankh532 Mar 22, 2022
305aba2
Merge branch 'badges:master' into master
rohankh532 Mar 23, 2022
2f7040b
api functional + color changing
rohankh532 Mar 23, 2022
68c6f1f
fixed test
rohankh532 Mar 23, 2022
cd70fe3
security scorecards badge
rohankh532 Mar 6, 2022
ebc8706
Create scorecards.yml
rohankh532 Mar 22, 2022
3b29534
Delete scorecards.yml
rohankh532 Mar 22, 2022
58b4ace
api functional + color changing
rohankh532 Mar 23, 2022
501c280
fixed test
rohankh532 Mar 23, 2022
9a62460
Merge branch 'master' of https://github.com/rohankh532/shields
rohankh532 Mar 25, 2022
8944818
Create scorecards.yml
rohankh532 Mar 22, 2022
63973e5
Delete scorecards.yml
rohankh532 Mar 22, 2022
9814e44
Merge branch 'master' of https://github.com/rohankh532/shields
rohankh532 Mar 25, 2022
d322942
reverted package-lock
rohankh532 Mar 25, 2022
9b7eb62
Merge branch 'master' into master
rohankh532 Mar 30, 2022
cb67713
renamed to ossf-scorecard + fixups
rohankh532 Apr 1, 2022
af9b0c4
fix packages
rohankh532 Apr 1, 2022
848808f
renamed to OSSFScorecard
rohankh532 Apr 1, 2022
25b09d2
reverted package-lock
rohankh532 Apr 1, 2022
7ef0e04
fixed dependencies
rohankh532 Apr 1, 2022
300f472
force peer deps
rohankh532 Apr 1, 2022
664d946
install force
rohankh532 Apr 1, 2022
61d8c25
force install
rohankh532 Apr 1, 2022
033f429
reset package lock
rohankh532 Apr 1, 2022
3855551
pkg
rohankh532 Apr 1, 2022
10b0dfb
original package lock
rohankh532 Apr 1, 2022
6685c6f
security scorecards badge
rohankh532 Mar 6, 2022
3c26af8
Create scorecards.yml
rohankh532 Mar 22, 2022
fd35c9a
Delete scorecards.yml
rohankh532 Mar 22, 2022
74cdb88
api functional + color changing
rohankh532 Mar 23, 2022
1d72c79
fixed test
rohankh532 Mar 23, 2022
7e5e150
Create scorecards.yml
rohankh532 Mar 22, 2022
e404ba0
Delete scorecards.yml
rohankh532 Mar 22, 2022
7dfaa69
Create scorecards.yml
rohankh532 Mar 22, 2022
d895f56
Delete scorecards.yml
rohankh532 Mar 22, 2022
f313ebd
renamed to ossf-scorecard + fixups
rohankh532 Apr 1, 2022
fd47bc0
renamed to OSSFScorecard
rohankh532 Apr 1, 2022
c21cfa8
pkg
rohankh532 Apr 1, 2022
8c2f6ef
original package lock
rohankh532 Apr 1, 2022
4c8a846
Merge branch 'master' of https://github.com/rohankh532/shields
rohankh532 Apr 6, 2022
c8b3aeb
reset other files
rohankh532 Apr 6, 2022
da83848
Merge branch 'master' of https://github.com/rohankh532/shields
rohankh532 Apr 6, 2022
aaa69fc
rerun tests
rohankh532 Apr 6, 2022
9cb0e45
fixed pkg err
rohankh532 Apr 6, 2022
d6ec129
handle response errors
rohankh532 Apr 7, 2022
21fe648
Merge branch 'master' into master
rohankh532 Apr 14, 2022
fb7678c
Merge branch 'master' into master
rohankh532 Apr 18, 2022
d356f74
404 test, removed 500 err
rohankh532 Apr 18, 2022
7c724c6
Merge branch 'master' of https://github.com/rohankh532/shields
rohankh532 Apr 18, 2022
0890410
Merge branch 'master' into master
rohankh532 Apr 19, 2022
457aade
Merge branch 'master' into master
repo-ranger[bot] Apr 23, 2022
05d6e8f
Merge branch 'master' into master
repo-ranger[bot] Apr 23, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions services/ossf-scorecard/ossf-scorecard.service.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import Joi from 'joi'
import { BaseJsonService } from '../index.js'
import { colorScale } from '../color-formatters.js'

const schema = Joi.object({
score: Joi.number().min(0).required(),
}).required()

const ossfScorecardColorScale = colorScale(
[2, 5, 8, 10],
['red', 'yellow', 'yellowgreen', 'green', 'brightgreen']
)

export default class OSSFScorecard extends BaseJsonService {
static category = 'analysis'

static route = { base: 'ossf-scorecard', pattern: ':host/:orgName/:repoName' }

static examples = [
{
title: 'OSSF-Scorecard Score',
namedParams: {
host: 'github.com',
calebcartwright marked this conversation as resolved.
Show resolved Hide resolved
orgName: 'rohankh532',
repoName: 'org-workflow-add',
},
staticPreview: this.render({ score: '7.5' }),
},
]

static defaultBadgeData = { label: 'score' }

static render({ score }) {
return {
message: score,
color: ossfScorecardColorScale(score),
}
}

async fetch({ host, orgName, repoName }) {
return this._requestJson({
schema,
url: `https://api.securityscorecards.dev/projects/${host}/${orgName}/${repoName}`,
errorMessages: {
404: 'invalid repo path',
},
})
}

async handle({ host, orgName, repoName }) {
const { score } = await this.fetch({ host, orgName, repoName })

return this.constructor.render({ score })
}
}
25 changes: 25 additions & 0 deletions services/ossf-scorecard/ossf-scorecard.tester.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import Joi from 'joi'
import { createServiceTester } from '../tester.js'
export const t = await createServiceTester()

t.create('score valid')
.get('/github.com/rohankh532/org-workflow-add.json')
.expectBadge({
label: 'score',
message: Joi.number().min(0),
color: Joi.string().allow(
'red',
'yellow',
'yellowgreen',
'green',
'brightgreen'
),
})
rohankh532 marked this conversation as resolved.
Show resolved Hide resolved

t.create('score ivalid')
.get('/github.com/invalid-user/invalid-repo.json')
.expectBadge({
label: 'score',
message: 'invalid repo path',
color: 'red',
})