-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
API refactor module to be more independent
As part of a greater piece of work with site summaries (cf. bringyourownideas/silverstripe-maintenance). This commit tidies class definitions and makes the import slightly more efficient. Abstractions are added to relate to the Package object from the aforementioned module. Unit tests have been added to ensure tidy standards in future maintenance.
- Loading branch information
Dylan Wagstaff
committed
May 28, 2018
1 parent
36d92eb
commit 5701642
Showing
16 changed files
with
395 additions
and
210 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
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.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,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> |
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,8 @@ | ||
<?php | ||
|
||
class CVEExtension extends DataExtension | ||
{ | ||
private static $has_one = [ | ||
'PackageRecord' => 'Package' | ||
]; | ||
} |
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,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); | ||
} | ||
} |
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,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)); | ||
} | ||
} |
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,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() | ||
{ | ||
return $this->checkTask; | ||
} | ||
|
||
/** | ||
* @param CVECheckTask | ||
* @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; | ||
} | ||
} |
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,20 @@ | ||
<?php | ||
/** | ||
* Describes a known security issue of an installed Composer package | ||
*/ | ||
class CVE extends DataObject | ||
{ | ||
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', | ||
); | ||
} |
Oops, something went wrong.