Skip to content
Snippets Groups Projects
Commit f6aa6da0 authored by GitLab CI's avatar GitLab CI
Browse files

Merge branch 'develop' into 'main'

Merging develop into main

See merge request !251
parents fecd3925 7c083271
No related branches found
No related tags found
1 merge request!251Merging develop into main
Pipeline #1278954 passed
<?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:audit-ignore-report')
->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,51 @@ class Handler extends BaseHandler {
}
}
/**
* Generates a report for ignored projects during audit.
*
* @throws \GuzzleHttp\Exception\GuzzleException
*/
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;
}
$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.
Please register or to comment