-
-
Notifications
You must be signed in to change notification settings - Fork 111
Expand file tree
/
Copy pathCheck.php
More file actions
103 lines (91 loc) · 2.48 KB
/
Check.php
File metadata and controls
103 lines (91 loc) · 2.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
<?php
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2020-2024 LibreCode coop and contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\Libresign\Command\Configure;
use OC\Core\Command\Base;
use OCA\Libresign\Service\SetupCheckResultService;
use Symfony\Component\Console\Helper\Table;
use Symfony\Component\Console\Helper\TableCell;
use Symfony\Component\Console\Helper\TableCellStyle;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
class Check extends Base {
public function __construct(
private SetupCheckResultService $setupCheckResultService,
) {
parent::__construct();
}
protected function configure(): void {
$this
->setName('libresign:configure:check')
->setDescription('Check configure')
->addOption(
name: 'sign',
shortcut: 's',
mode: InputOption::VALUE_NONE,
description: 'Check requirements to sign document'
)
->addOption(
name: 'certificate',
shortcut: 'c',
mode: InputOption::VALUE_NONE,
description: 'Check requirements to use root certificate'
);
}
protected function execute(InputInterface $input, OutputInterface $output): int {
$sign = $input->getOption('sign');
$certificate = $input->getOption('certificate');
$all = (!$sign && !$certificate);
$allChecks = $this->setupCheckResultService->getFormattedChecks();
$filteredRows = array_filter($allChecks, function ($check) use ($all, $sign, $certificate) {
if ($all) {
return true;
}
if ($sign && $check['category'] === 'system') {
return true;
}
if ($certificate && $check['category'] === 'security') {
return true;
}
return false;
});
if (!empty($filteredRows)) {
$table = new Table($output);
$table->setColumnMaxWidth(3, 40);
foreach ($filteredRows as $row) {
$table->addRow([
new TableCell($row['status'], ['style' => new TableCellStyle([
'bg' => $this->getStatusColor($row['status']),
'fg' => 'black',
'align' => 'center',
])]),
$row['resource'],
$row['message'],
$row['tip'],
]);
}
$table
->setHeaders([
'Status',
'Resource',
'Message',
'Tip',
])
->setStyle('symfony-style-guide')
->render();
}
return 0;
}
private function getStatusColor(string $status): string {
return match ($status) {
'success' => 'green',
'error' => 'red',
'info' => 'bright-yellow',
default => 'red',
};
}
}