Skip to content
Snippets Groups Projects
Commit c0654e29 authored by jurgenhaas's avatar jurgenhaas
Browse files

#18 Implement lakedrops:auditignorereport

parent d7b73514
No related branches found
No related tags found
1 merge request!251Merging develop into main
Pipeline #1278946 failed
<?php
namespace LakeDrops\DrupalEnvironment;
use LakeDrops\Component\Composer\BaseCommand;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
/**
* Composer Audit Ignore Report Command for LakeDrops Drupal environments.
*
* @package LakeDrops\DrupalEnvironment
*/
class AuditIgnoreReportCommand extends BaseCommand {
/**
* {@inheritdoc}
*/
protected function configure(): void {
parent::configure();
$this
->setName('lakedrops:auditignorereport')
->setDescription('Report about status of all ignored CVEs during audit.');
}
/**
* {@inheritdoc}
*/
public function getHandlerClass(): string {
return Handler::class;
}
/**
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output): int {
parent::execute($input, $output);
/** @var Handler $handler */
$handler = $this->handler;
$handler->auditIgnoreReport();
return 0;
}
}
......@@ -20,6 +20,7 @@ class CommandProvider implements CommandProviderCapability {
public function getCommands(): array {
return [
new ConfigCommand(),
new AuditIgnoreReportCommand(),
];
}
......
......@@ -2,6 +2,7 @@
namespace LakeDrops\DrupalEnvironment;
use GuzzleHttp\Client;
use LakeDrops\Component\Composer\BaseHandler;
use Symfony\Component\Filesystem\Filesystem;
......@@ -187,4 +188,47 @@ class Handler extends BaseHandler {
}
}
public function auditIgnoreReport(): void {
$audit = $this->composer->getConfig()->get('audit');
if (empty($audit['ignore'])) {
$this->io->info('There are no ignored CVEs in the configuration.');
return;
}
/** @var \GuzzleHttp\Client $client */
$client = new Client();
$ignore = $audit['ignore'];
$report = [];
foreach ($ignore as $item) {
print('.');
$parts = explode('-', $item);
if (count($parts) < 5 || $parts[0] !== 'DDQG' || $parts[2] !== 'drupal') {
$report[] = $item . ': Not Drupal related';
continue;
}
$project = json_decode($client->get('https://www.drupal.org/api-d7/node.json?type=project_module&field_project_machine_name=' . $parts[3])->getBody(), TRUE);
if (empty($project['list'])) {
$project = json_decode($client->get('https://www.drupal.org/api-d7/node.json?type=project_theme&field_project_machine_name=' . $parts[3])->getBody(), TRUE);
}
if (empty($project['list'])) {
$report[] = $parts[3] . ': Drupal project not found';
}
$nid = $project['list'][0]['nid'];
$releases = json_decode($client->get('https://www.drupal.org/api-d7/node.json?type=project_release&field_release_update_status=0&field_release_category=current&field_release_project=' . $nid)->getBody(), TRUE);
if (empty($releases['list'])) {
$report[] = $parts[3] . ': No releases available for Drupal project';
continue;
}
$used = $parts[4] . (isset($parts[5]) ? '-' . $parts[5] : '');
$used_version_major = (int) $parts[4][0];
$available = [];
foreach ($releases['list'] as $release) {
if ((int) $release['field_release_version_major'] >= $used_version_major) {
$available[] = $release['field_release_version'];
}
}
$report[] = $parts[3] . ': ' . $used . ' - ' . implode(' ', $available);
}
print_r($report);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment