Skip to content

Commit dc1903d

Browse files
committed
small fixes
1 parent 7e6a846 commit dc1903d

File tree

6 files changed

+57
-40
lines changed

6 files changed

+57
-40
lines changed

application/clicommands/CheckCommand.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Icinga\Application\Logger;
88
use Icinga\Module\X509\Command;
99
use Icinga\Module\X509\Model\X509Certificate;
10+
use Icinga\Module\X509\Model\X509CertificateChain;
1011
use Icinga\Module\X509\Model\X509Target;
1112
use ipl\Sql\Expression;
1213
use ipl\Stdlib\Filter;
@@ -88,13 +89,11 @@ public function hostAction()
8889
]);
8990

9091
// Sub queries for (valid_from, valid_to) columns
91-
$validFrom = X509Certificate::on($conn)
92-
->with(['chain', 'issuer_certificate'])
93-
->columns([new Expression('MAX(GREATEST(%s, %s))', ['valid_from', 'issuer_certificate.valid_from'])]);
94-
95-
$validFrom->getResolver()->setAliasPrefix('sub_');
92+
$validFrom = $targets->createSubQuery(new X509Certificate(), 'chain.certificate');
9693
$validFrom
94+
->columns([new Expression('MAX(GREATEST(%s, %s))', ['valid_from', 'issuer_certificate.valid_from'])])
9795
->getSelectBase()
96+
->resetWhere()
9897
->where(new Expression('sub_certificate_link.certificate_chain_id = target_chain.id'));
9998

10099
$validTo = clone $validFrom;

application/controllers/CertificatesController.php

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -77,14 +77,7 @@ public function indexAction()
7777
$this->addControl($limitControl);
7878
$this->addControl($searchBar);
7979

80-
// List of allowed columns to be exported
81-
$exportable = array_flip([
82-
'id', 'subject', 'issuer', 'version', 'self_signed', 'ca', 'trusted',
83-
'pubkey_algo', 'pubkey_bits', 'signature_algo', 'signature_hash_algo',
84-
'valid_from', 'valid_to'
85-
]);
86-
87-
$this->handleFormatRequest($certificates, function (Query $certificates) use ($exportable) {
80+
$this->handleFormatRequest($certificates, function (Query $certificates) {
8881
/** @var X509Certificate $cert */
8982
foreach ($certificates as $cert) {
9083
$cert['valid_from'] = (new \DateTime())
@@ -94,7 +87,7 @@ public function indexAction()
9487
->setTimestamp($cert['valid_to'])
9588
->format('l F jS, Y H:i:s e');
9689

97-
yield array_intersect_key(iterator_to_array($cert), $exportable);
90+
yield array_intersect_key(iterator_to_array($cert), array_flip($cert->getExportableColumns()));
9891
}
9992
});
10093

@@ -107,10 +100,11 @@ public function indexAction()
107100

108101
public function completeAction()
109102
{
110-
$suggestions = new ObjectSuggestions();
111-
$suggestions->setModel(X509Certificate::class);
112-
$suggestions->forRequest($this->getServerRequest());
113-
$this->getDocument()->add($suggestions);
103+
$this->getDocument()->add(
104+
(new ObjectSuggestions())
105+
->setModel(X509Certificate::class)
106+
->forRequest($this->getServerRequest())
107+
);
114108
}
115109

116110
public function searchEditorAction()

application/controllers/UsageController.php

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ public function indexAction()
7878
} else {
7979
$this->addControl($searchBar);
8080
$this->sendMultipartUpdate();
81+
8182
return;
8283
}
8384
} else {
@@ -93,13 +94,7 @@ public function indexAction()
9394
$this->addControl($limitControl);
9495
$this->addControl($searchBar);
9596

96-
$exportable = array_flip([
97-
'valid', 'hostname', 'ip', 'port', 'subject', 'issuer', 'version',
98-
'self_signed', 'ca', 'trusted', 'pubkey_algo', 'pubkey_bits',
99-
'signature_algo', 'signature_hash_algo', 'valid_from', 'valid_to'
100-
]);
101-
102-
$this->handleFormatRequest($targets, function (Query $targets) use ($conn, $exportable) {
97+
$this->handleFormatRequest($targets, function (Query $targets) {
10398
foreach ($targets as $usage) {
10499
$usage['valid_from'] = (new \DateTime())
105100
->setTimestamp($usage['valid_from'])
@@ -113,7 +108,10 @@ public function indexAction()
113108
$usage->port = $usage->chain->target->port;
114109
$usage->valid = $usage->chain->valid;
115110

116-
yield array_intersect_key(iterator_to_array($usage), $exportable);
111+
yield array_intersect_key(
112+
iterator_to_array($usage),
113+
array_flip(array_merge(['valid', 'hostname', 'ip', 'port'], $usage->getExportableColumns()))
114+
);
117115
}
118116
});
119117

@@ -126,10 +124,11 @@ public function indexAction()
126124

127125
public function completeAction()
128126
{
129-
$suggestions = new ObjectSuggestions();
130-
$suggestions->setModel(X509Certificate::class);
131-
$suggestions->forRequest($this->getServerRequest());
132-
$this->getDocument()->add($suggestions);
127+
$this->getDocument()->add(
128+
(new ObjectSuggestions())
129+
->setModel(X509Certificate::class)
130+
->forRequest($this->getServerRequest())
131+
);
133132
}
134133

135134
public function searchEditorAction()

library/X509/DataTable.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ protected function renderRow($row)
8484
$cells = [];
8585

8686
foreach ($this->columns as $key => $column) {
87-
if (! is_int($key) && isset($row->$key)) {
87+
if (! is_int($key) && property_exists($row, $key)) {
8888
$data = $row[$key];
8989
} else {
9090
$data = null;

library/X509/Job.php

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -438,10 +438,10 @@ protected function processChain($target, $chain)
438438
$this->db->transaction(function () use ($target, $chain) {
439439
$row = X509Target::on($this->db)->columns(['id']);
440440

441-
$filter = Filter::all();
442-
$filter->add(Filter::equal('ip', $target->ip));
443-
$filter->add(Filter::equal('port', $target->port));
444-
$filter->add(Filter::equal('hostname', $target->hostname));
441+
$filter = Filter::all()
442+
->add(Filter::equal('ip', $target->ip))
443+
->add(Filter::equal('port', $target->port))
444+
->add(Filter::equal('hostname', $target->hostname));
445445

446446
$row->filter($filter);
447447

@@ -463,13 +463,14 @@ protected function processChain($target, $chain)
463463

464464
$chainUptodate = false;
465465

466-
$lastChain = X509CertificateChain::on($this->db)->columns(['id']);
467-
$lastChain
466+
$lastChain = X509CertificateChain::on($this->db)
467+
->columns(['id'])
468468
->filter(Filter::equal('target_id', $targetId))
469469
->orderBy('id', SORT_DESC)
470-
->limit(1);
470+
->limit(1)
471+
->first();
471472

472-
if (($lastChain = $lastChain->first())) {
473+
if ($lastChain) {
473474
$lastFingerprints = X509Certificate::on($this->db)->utilize('chain');
474475
$lastFingerprints
475476
->columns(['fingerprint'])
@@ -495,7 +496,7 @@ protected function processChain($target, $chain)
495496
}
496497

497498
if ($chainUptodate) {
498-
$chainId = (int) $lastChain->id;
499+
$chainId = $lastChain->id;
499500
} else {
500501
// TODO: https://github.com/Icinga/ipl-orm/pull/78
501502
$this->db->insert(

library/X509/Model/X509Certificate.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,30 @@ public function getSearchColumns()
8686
return ['subject', 'issuer'];
8787
}
8888

89+
/**
90+
* Get list of allowed columns to be exported
91+
*
92+
* @return string[]
93+
*/
94+
public function getExportableColumns(): array
95+
{
96+
return [
97+
'id',
98+
'subject',
99+
'issuer',
100+
'version',
101+
'self_signed',
102+
'ca',
103+
'trusted',
104+
'pubkey_algo',
105+
'pubkey_bits',
106+
'signature_algo',
107+
'signature_hash_algo',
108+
'valid_from',
109+
'valid_to'
110+
];
111+
}
112+
89113
public function createBehaviors(Behaviors $behaviors)
90114
{
91115
$behaviors->add(new Binary([

0 commit comments

Comments
 (0)