Skip to content

Commit a9816ff

Browse files
authored
Merge pull request #135 from Icinga/adjust-some-db-columns
Change DB `yes,no` enum types
2 parents cfc5f78 + 4bdd79a commit a9816ff

File tree

11 files changed

+51
-26
lines changed

11 files changed

+51
-26
lines changed

application/clicommands/CheckCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ public function hostAction()
113113

114114
$state = 3;
115115
foreach ($this->getDb()->select($targets) as $target) {
116-
if ($target['valid'] === 'no' && ($target['self_signed'] === 'no' || ! $allowSelfSigned)) {
116+
if ($target['valid'] === 'n' && ($target['self_signed'] === 'n' || ! $allowSelfSigned)) {
117117
$invalidMessage = $target['subject'] . ': ' . $target['invalid_reason'];
118118
$output[$invalidMessage] = $invalidMessage;
119119
$state = 2;

application/clicommands/ImportCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public function indexAction()
4545

4646
$db->update(
4747
'x509_certificate',
48-
['trusted' => 'yes'],
48+
['trusted' => 'y'],
4949
['id = ?' => $id]
5050
);
5151

application/controllers/ChainController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public function indexAction()
5858

5959
$valid = Html::tag('div', ['class' => 'cert-chain']);
6060

61-
if ($chain['valid'] === 'yes') {
61+
if ($chain['valid'] === 'y') {
6262
$valid->getAttributes()->add('class', '-valid');
6363
$valid->add(Html::tag('p', $this->translate('Certificate chain is valid.')));
6464
} else {

application/controllers/DashboardController.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public function indexAction()
2929
(new Select())
3030
->from('x509_certificate i')
3131
->columns(['i.subject', 'cnt' => 'COUNT(*)'])
32-
->join('x509_certificate c', ['c.issuer_hash = i.subject_hash', 'i.ca = ?' => 'yes'])
32+
->join('x509_certificate c', ['c.issuer_hash = i.subject_hash', 'i.ca = ?' => 'y'])
3333
->groupBy(['i.id'])
3434
->orderBy('cnt', SORT_DESC)
3535
->limit(5)
@@ -55,7 +55,7 @@ public function indexAction()
5555
'duration' => 'valid_to - valid_from',
5656
'cnt' => 'COUNT(*)'
5757
])
58-
->where(['ca = ?' => 'no'])
58+
->where(['ca = ?' => 'n'])
5959
->groupBy(['duration'])
6060
->orderBy('cnt', SORT_DESC)
6161
->limit(5)
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
ALTER TABLE x509_certificate
2+
CHANGE self_signed self_signed enum('n', 'y', 'yes', 'no') NOT NULL DEFAULT 'n',
3+
CHANGE ca ca enum('n', 'y', 'yes', 'no') NOT NULL,
4+
CHANGE trusted trusted enum('n', 'y', 'yes', 'no') NOT NULL DEFAULT 'n';
5+
6+
UPDATE x509_certificate SET self_signed = 'y' WHERE self_signed = 'yes';
7+
UPDATE x509_certificate SET self_signed = 'n' WHERE self_signed = 'no';
8+
9+
UPDATE x509_certificate SET ca = 'y' WHERE ca = 'yes';
10+
UPDATE x509_certificate SET ca = 'n' WHERE ca = 'no';
11+
12+
UPDATE x509_certificate SET trusted = 'y' WHERE trusted = 'yes';
13+
UPDATE x509_certificate SET trusted = 'n' WHERE trusted = 'no';
14+
15+
ALTER TABLE x509_certificate
16+
CHANGE self_signed self_signed enum('n', 'y') NOT NULL DEFAULT 'n',
17+
CHANGE ca ca enum('n', 'y') NOT NULL,
18+
CHANGE trusted trusted enum('n', 'y') NOT NULL DEFAULT 'n';
19+
20+
ALTER TABLE x509_certificate_chain CHANGE valid valid enum('n', 'y', 'yes', 'no') NOT NULL DEFAULT 'n';
21+
22+
UPDATE x509_certificate_chain SET valid = 'y' WHERE valid = 'yes';
23+
UPDATE x509_certificate_chain SET valid = 'n' WHERE valid = 'no';
24+
25+
ALTER TABLE x509_certificate_chain CHANGE valid valid enum('n', 'y') NOT NULL DEFAULT 'n';

etc/schema/mysql.schema.sql

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ CREATE TABLE x509_certificate (
66
issuer_hash binary(32) NOT NULL COMMENT 'sha256 hash of the full issuer DN',
77
issuer_certificate_id int(10) unsigned DEFAULT NULL,
88
version enum('1','2','3') NOT NULL,
9-
self_signed enum('yes','no') NOT NULL DEFAULT 'no',
10-
ca enum('yes','no') NOT NULL,
11-
trusted enum('yes','no') NOT NULL DEFAULT 'no',
9+
self_signed enum('n', 'y') NOT NULL DEFAULT 'n',
10+
ca enum('n', 'y') NOT NULL,
11+
trusted enum('n', 'y') NOT NULL DEFAULT 'n',
1212
pubkey_algo enum('unknown','RSA','DSA','DH','EC') NOT NULL,
1313
pubkey_bits smallint(6) unsigned NOT NULL,
1414
signature_algo varchar(255) NOT NULL,
@@ -30,7 +30,7 @@ CREATE TABLE x509_certificate_chain (
3030
id int(10) unsigned NOT NULL AUTO_INCREMENT,
3131
target_id int(10) unsigned NOT NULL,
3232
length smallint(6) NOT NULL,
33-
valid enum('yes','no') NOT NULL DEFAULT 'no',
33+
valid enum('n', 'y') NOT NULL DEFAULT 'n',
3434
invalid_reason varchar(255) NULL DEFAULT NULL,
3535
ctime timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
3636
PRIMARY KEY (id)

etc/schema/postgresql.schema.sql

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
CREATE DOMAIN uint2 AS int4
22
CHECK(VALUE >= 0 AND VALUE < 65536);
3-
CREATE TYPE yesno AS ENUM ('yes','no');
3+
CREATE TYPE boolenum AS ENUM ('n', 'y');
44
CREATE TYPE certificate_version AS ENUM('1','2','3');
55
CREATE TYPE dn_type AS ENUM('issuer','subject');
66
CREATE TYPE pubkey_algo AS ENUM('unknown','RSA','DSA','DH','EC');
@@ -24,9 +24,9 @@ CREATE TABLE x509_certificate (
2424
issuer_hash bytea NOT NULL,
2525
issuer_certificate_id int DEFAULT NULL,
2626
version certificate_version NOT NULL,
27-
self_signed yesno NOT NULL DEFAULT 'no',
28-
ca yesno NOT NULL,
29-
trusted yesno NOT NULL DEFAULT 'no',
27+
self_signed boolenum NOT NULL DEFAULT 'n',
28+
ca boolenum NOT NULL,
29+
trusted boolenum NOT NULL DEFAULT 'n',
3030
pubkey_algo pubkey_algo NOT NULL,
3131
pubkey_bits uint2 NOT NULL,
3232
signature_algo varchar(255) NOT NULL,
@@ -46,7 +46,7 @@ CREATE TABLE x509_certificate_chain (
4646
id serial PRIMARY KEY,
4747
target_id int NOT NULL,
4848
length uint2 NOT NULL,
49-
valid yesno NOT NULL DEFAULT 'no',
49+
valid boolenum NOT NULL DEFAULT 'n',
5050
invalid_reason varchar(255) NULL DEFAULT NULL,
5151
ctime timestamptz NOT NULL DEFAULT CURRENT_TIMESTAMP
5252
);

library/X509/CertificateUtils.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -234,8 +234,8 @@ public static function findOrInsertCert(Connection $db, $cert)
234234
'issuer' => CertificateUtils::shortNameFromDN($certInfo['issuer']),
235235
'issuer_hash' => $dbTool->marshalBinary($issuerHash),
236236
'version' => $certInfo['version'] + 1,
237-
'self_signed' => $subjectHash === $issuerHash ? 'yes' : 'no',
238-
'ca' => $ca ? 'yes' : 'no',
237+
'self_signed' => $subjectHash === $issuerHash ? 'y' : 'n',
238+
'ca' => $ca ? 'y' : 'n',
239239
'pubkey_algo' => CertificateUtils::$pubkeyTypes[$pubkey['type']],
240240
'pubkey_bits' => $pubkey['bits'],
241241
'signature_algo' => array_shift($signature), // Support formats like RSA-SHA1 and
@@ -372,7 +372,7 @@ public static function verifyCertificates(Connection $db)
372372
(new Select())
373373
->from('x509_certificate')
374374
->columns(['certificate'])
375-
->where(['ca = ?' => 'yes', 'trusted = ?' => 'yes'])
375+
->where(['ca = ?' => 'y', 'trusted = ?' => 'y'])
376376
);
377377

378378
$contents = [];
@@ -395,7 +395,7 @@ public static function verifyCertificates(Connection $db)
395395
$chains = $db->select(
396396
(new Select())
397397
->from('x509_certificate_chain c')
398-
->join('x509_target t', ['t.latest_certificate_chain_id = c.id', 'c.valid = ?' => 'no'])
398+
->join('x509_target t', ['t.latest_certificate_chain_id = c.id', 'c.valid = ?' => 'n'])
399399
->columns('c.id')
400400
);
401401

@@ -455,7 +455,7 @@ public static function verifyCertificates(Connection $db)
455455
if (!empty($match)) {
456456
$set = ['invalid_reason' => trim($match[1])];
457457
} else {
458-
$set = ['valid' => 'yes', 'invalid_reason' => null];
458+
$set = ['valid' => 'y', 'invalid_reason' => null];
459459
}
460460

461461
$db->update(

library/X509/CertificatesTable.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ protected function createColumns()
3232
'ca' => [
3333
'attributes' => ['class' => 'icon-col'],
3434
'renderer' => function ($ca) {
35-
if ($ca === 'no') {
35+
if ($ca === 'n') {
3636
return null;
3737
}
3838

@@ -46,7 +46,7 @@ protected function createColumns()
4646
'self_signed' => [
4747
'attributes' => ['class' => 'icon-col'],
4848
'renderer' => function ($selfSigned) {
49-
if ($selfSigned === 'no') {
49+
if ($selfSigned === 'n') {
5050
return null;
5151
}
5252

@@ -60,7 +60,7 @@ protected function createColumns()
6060
'trusted' => [
6161
'attributes' => ['class' => 'icon-col'],
6262
'renderer' => function ($trusted) {
63-
if ($trusted === 'no') {
63+
if ($trusted === 'n') {
6464
return null;
6565
}
6666

library/X509/ChainDetails.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public function createColumns()
4141
'ca' => [
4242
'attributes' => ['class' => 'icon-col'],
4343
'renderer' => function ($ca) {
44-
if ($ca === 'no') {
44+
if ($ca === 'n') {
4545
return null;
4646
}
4747

@@ -55,7 +55,7 @@ public function createColumns()
5555
'self_signed' => [
5656
'attributes' => ['class' => 'icon-col'],
5757
'renderer' => function ($selfSigned) {
58-
if ($selfSigned === 'no') {
58+
if ($selfSigned === 'n') {
5959
return null;
6060
}
6161

@@ -69,7 +69,7 @@ public function createColumns()
6969
'trusted' => [
7070
'attributes' => ['class' => 'icon-col'],
7171
'renderer' => function ($trusted) {
72-
if ($trusted === 'no') {
72+
if ($trusted === 'n') {
7373
return null;
7474
}
7575

0 commit comments

Comments
 (0)