Skip to content

Commit 7e6a846

Browse files
committed
Optimize imports & cleanup some codes
1 parent d2b5622 commit 7e6a846

File tree

6 files changed

+21
-31
lines changed

6 files changed

+21
-31
lines changed

application/clicommands/CheckCommand.php

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
use Icinga\Application\Logger;
88
use Icinga\Module\X509\Command;
9-
use Icinga\Module\X509\Job;
109
use Icinga\Module\X509\Model\X509Certificate;
1110
use Icinga\Module\X509\Model\X509Target;
1211
use ipl\Sql\Expression;
@@ -91,34 +90,28 @@ public function hostAction()
9190
// Sub queries for (valid_from, valid_to) columns
9291
$validFrom = X509Certificate::on($conn)
9392
->with(['chain', 'issuer_certificate'])
94-
->columns([
95-
new Expression('MAX(GREATEST(%s, %s))', ['valid_from', 'issuer_certificate.valid_from'])
96-
]);
93+
->columns([new Expression('MAX(GREATEST(%s, %s))', ['valid_from', 'issuer_certificate.valid_from'])]);
9794

9895
$validFrom->getResolver()->setAliasPrefix('sub_');
9996
$validFrom
10097
->getSelectBase()
101-
->where(new Expression(
102-
'sub_certificate_link.certificate_chain_id = target_chain.id'
103-
));
98+
->where(new Expression('sub_certificate_link.certificate_chain_id = target_chain.id'));
10499

105100
$validTo = clone $validFrom;
106-
$validTo->columns([
107-
new Expression('MIN(LEAST(%s, %s))', ['valid_to', 'issuer_certificate.valid_to'])
108-
]);
101+
$validTo->columns([new Expression('MIN(LEAST(%s, %s))', ['valid_to', 'issuer_certificate.valid_to'])]);
109102

110-
list($validFromSelect, $validFromValues) = $validFrom->dump();
111-
list($validToSelect, $validToValues) = $validTo->dump();
103+
list($validFromSelect, $_) = $validFrom->dump();
104+
list($validToSelect, $_) = $validTo->dump();
112105
$targets
113106
->withColumns([
114-
'valid_from' => new Expression("$validFromSelect", null, ...$validFromValues),
115-
'valid_to' => new Expression("$validToSelect", null, ...$validToValues)
107+
'valid_from' => new Expression($validFromSelect),
108+
'valid_to' => new Expression($validToSelect)
116109
])
117110
->getSelectBase()
118111
->where(new Expression('target_chain_link.order = 0'));
119112

120113
if ($ip !== null) {
121-
$targets->filter(Filter::equal('ip', Job::binary($ip)));
114+
$targets->filter(Filter::equal('ip', $ip));
122115
}
123116
if ($hostname !== null) {
124117
$targets->filter(Filter::equal('hostname', $hostname));

application/controllers/CertificateController.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
use Icinga\Module\X509\CertificateDetails;
99
use Icinga\Module\X509\Controller;
1010
use Icinga\Module\X509\Model\X509Certificate;
11-
use ipl\Sql;
1211
use ipl\Stdlib\Filter;
1312

1413
class CertificateController extends Controller

library/X509/CertificateDetails.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
namespace Icinga\Module\X509;
66

77
use DateTime;
8+
use Icinga\Module\X509\Model\X509Certificate;
89
use ipl\Html\BaseHtmlElement;
910
use ipl\Html\Html;
10-
use ipl\Orm\Model;
1111

1212
/**
1313
* Widget to display X.509 certificate details
@@ -23,7 +23,7 @@ class CertificateDetails extends BaseHtmlElement
2323
*/
2424
protected $cert;
2525

26-
public function setCert(Model $cert)
26+
public function setCert(X509Certificate $cert)
2727
{
2828
$this->cert = $cert;
2929

library/X509/Job.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@ protected function processChain($target, $chain)
439439
$row = X509Target::on($this->db)->columns(['id']);
440440

441441
$filter = Filter::all();
442-
$filter->add(Filter::equal('ip', static::binary($target->ip)));
442+
$filter->add(Filter::equal('ip', $target->ip));
443443
$filter->add(Filter::equal('port', $target->port));
444444
$filter->add(Filter::equal('hostname', $target->hostname));
445445

library/X509/ProvidedHook/HostsImportSource.php

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,9 @@
44

55
namespace Icinga\Module\X509\ProvidedHook;
66

7-
use Icinga\Module\X509\DbTool;
87
use Icinga\Module\X509\Job;
98
use Icinga\Module\X509\Model\X509Target;
109
use ipl\Sql;
11-
use ipl\Stdlib\Filter;
1210

1311
class HostsImportSource extends X509ImportSource
1412
{
@@ -60,12 +58,12 @@ public function fetchData()
6058
$target->host_name_or_ip = $target->host_ip;
6159
}
6260

63-
unset($target->ip); // Isn't needed any more!!
64-
unset($target->chain); // We don't need any relation properties anymore
61+
// Target ip is now obsolete and must not be included in the results.
62+
// The relation is only used to utilize the query and must not be in the result set as well.
63+
unset($target->ip);
64+
unset($target->chain);
6565

66-
$properties = iterator_to_array($target);
67-
68-
$results[$target->host_name_or_ip] = (object) $properties;
66+
$results[$target->host_name_or_ip] = (object) iterator_to_array($target);
6967
}
7068

7169
return $results;

library/X509/ProvidedHook/ServicesImportSource.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -101,12 +101,12 @@ public function fetchData()
101101
$target->host_port
102102
);
103103

104-
unset($target->ip); // Isn't needed any more!!
105-
unset($target->chain); // We don't need any relation properties anymore
104+
// Target ip is now obsolete and must not be included in the results.
105+
// The relation is only used to utilize the query and must not be in the result set as well.
106+
unset($target->ip);
107+
unset($target->chain);
106108

107-
$properties = iterator_to_array($target);
108-
109-
$results[$target->host_name_ip_and_port] = (object) $properties;
109+
$results[$target->host_name_ip_and_port] = (object) iterator_to_array($target);
110110
}
111111

112112
return $results;

0 commit comments

Comments
 (0)