-
Notifications
You must be signed in to change notification settings - Fork 6
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
API refactor module to be more independent #34
Changes from 1 commit
5701642
079a9d5
7efa85c
a8e9238
fd37c29
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
--- | ||
Name: packagerelations | ||
after: '#updatecheckerextensions' | ||
Only: | ||
moduleexists: silverstripe-maintenance | ||
--- | ||
Package: | ||
extensions: | ||
- PackageSecurityExtension | ||
CVE: | ||
extensions: | ||
- CVEExtension | ||
SiteSummary: | ||
extensions: | ||
- SiteSummaryExtension |
This file was deleted.
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,15 +19,15 @@ | |
], | ||
"require": { | ||
"php": ">=5.6.0", | ||
"silverstripe/framework": "^3.0", | ||
"sensiolabs/security-checker": "^3.0", | ||
"symbiote/silverstripe-queuedjobs": "^2.8", | ||
"friendsofsilverstripe/silverstripe-maintenance": "^0.3" | ||
"silverstripe/framework": "^3", | ||
"sensiolabs/security-checker": "^4", | ||
"symbiote/silverstripe-queuedjobs": "^2" | ||
}, | ||
"replace": { | ||
"spekulatius/silverstripe-composer-security-checker": "self.version" | ||
}, | ||
"suggest": { | ||
"friendsofsilverstripe/silverstripe-maintenance": "Display advisory information via Site Summary Report", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The package name has changed =) |
||
"roave/security-advisories": "Raises a conflict on attempt to install a vulnerable module" | ||
}, | ||
"support": { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<ruleset name="SilverStripe"> | ||
<description>CodeSniffer ruleset for SilverStripe coding conventions.</description> | ||
|
||
<!-- base rules are PSR-2 --> | ||
<rule ref="PSR2" > | ||
<!-- Current exclusions --> | ||
<exclude name="PSR1.Classes.ClassDeclaration.MissingNamespace" /> | ||
</rule> | ||
</ruleset> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?php | ||
|
||
class CVEExtension extends DataExtension | ||
{ | ||
private static $has_one = [ | ||
'PackageRecord' => 'Package' | ||
]; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
class PackageSecurityExtension extends DataExtension | ||
{ | ||
private static $has_many = [ | ||
'SecurityAlerts' => 'CVE' | ||
]; | ||
|
||
private static $summary_fields = [ | ||
'listCVEs' => 'Security alerts', | ||
]; | ||
|
||
public function listCVEs() | ||
{ | ||
$alerts = $this->owner->SecurityAlerts()->Column('CVE'); | ||
return $alerts ? implode(', ', $alerts) : null; | ||
} | ||
|
||
public function listAlerts() | ||
{ | ||
$templates = ['PackageSecurityAlerts']; | ||
$this->owner->extend('updateListAlerts', $templates); | ||
return $this->owner->renderWith($templates); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php | ||
|
||
class SiteSummaryExtension extends Extension | ||
{ | ||
public function updateColumns(&$columns) | ||
{ | ||
unset($columns['listCVEs']); | ||
} | ||
|
||
public function updateCMSFields(&$fields) | ||
{ | ||
$summaryInfo = $this->owner->sourceRecords()->renderWith('PackageSecurityAlerts'); | ||
$fields->unshift(LiteralField::create('AlertSummary', $summaryInfo)); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<?php | ||
/** | ||
* Composer security checker job. Runs the task which does the check as a queuedjob. | ||
* | ||
* @author Peter Thaleikis | ||
* @license BSD-3-Clause | ||
*/ | ||
class CVECheckJob extends AbstractQueuedJob implements QueuedJob | ||
{ | ||
private static $dependencies = [ | ||
'CVECheckTask' => '%$' . CVECheckTask::class, | ||
]; | ||
|
||
/** | ||
* @var CVECheckTask | ||
*/ | ||
protected $checkTask; | ||
|
||
/** | ||
* @return CVECheckTask | ||
*/ | ||
public function getCVECheckTask() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you please name the getters/setters the same as the property? I.e. |
||
{ | ||
return $this->checkTask; | ||
} | ||
|
||
/** | ||
* @param CVECheckTask | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing variable name - can you please type hint the class in the argument too? |
||
* @return CVECheckJob | ||
*/ | ||
public function setCVECheckTask($checkTask) | ||
{ | ||
$this->checkTask = $checkTask; | ||
return $this; | ||
} | ||
|
||
public function getTitle() | ||
{ | ||
return _t( | ||
__CLASS__ . '.Title', | ||
'Check if any composer managed modules have known security vulnerabilities.' | ||
); | ||
} | ||
|
||
public function getJobType() | ||
{ | ||
$this->totalSteps = 1; | ||
|
||
return QueuedJob::QUEUED; | ||
} | ||
|
||
public function process() | ||
{ | ||
// run the task | ||
$task = $this->getCVECheckTask(); | ||
$task->run(null); | ||
|
||
// mark job as completed | ||
$this->isComplete = true; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
/** | ||
* Describes a known security issue of an installed Composer package | ||
*/ | ||
class CVE extends DataObject | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Last thing- the vulnerabilities are not always assigned CVEs (ours aren’t for example), so maybe the original name or something like PackageVulnerability would be better- what do you think? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Question: Should the SS security ID then be put in place of the CVE ID? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, because this module can work for any PHP packages not just SilverStripe packages. Maybe choose something generic like "Identifier" |
||
{ | ||
private static $db = array( | ||
'PackageName' => 'Varchar(255)', | ||
'Version' => 'Varchar(255)', | ||
'Title' => 'Varchar(255)', | ||
'ExternalLink' => 'Varchar(255)', | ||
'CVE' => 'Varchar(255)', | ||
); | ||
|
||
private static $summary_fields = array( | ||
'PackageName', | ||
'Version', | ||
'Title', | ||
); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's introduce
^3.2
which matches bringyourownideas/silverstripe-maintenance