1
0
Fork 0
mirror of synced 2024-06-29 11:40:45 +12:00

PR review changes

This commit is contained in:
Matej Bačo 2022-05-11 14:09:30 +00:00
parent 6d94c1d6e8
commit 9a3b226781

View file

@ -23,7 +23,7 @@ class CertificatesV1 extends Worker
* *
* @var Database * @var Database
*/ */
private $dbForConsole; private Database $dbForConsole;
public function getName(): string { public function getName(): string {
return "certificates"; return "certificates";
@ -103,7 +103,7 @@ class CertificatesV1 extends Worker
} }
// Generate certificate files using Let's Encrypt // Generate certificate files using Let's Encrypt
$letsEncryptData = $this->letsEncryptAction($domain->get(), $email); $letsEncryptData = $this->issueCertificate($domain->get(), $email);
// Command succeeded, store all data into document // Command succeeded, store all data into document
// We store stderr too, because it may include warnings // We store stderr too, because it may include warnings
@ -135,7 +135,7 @@ class CertificatesV1 extends Worker
// Save all changes we made to certificate document into database // Save all changes we made to certificate document into database
$this->saveCertificateDocument($domain->get(), $certificate); $this->saveCertificateDocument($domain->get(), $certificate);
Authorization::reset(); Authorization::reset();
} }
} }
@ -152,7 +152,7 @@ class CertificatesV1 extends Worker
* *
* @return void * @return void
*/ */
private function saveCertificateDocument(string $domain, Document $certificate) { private function saveCertificateDocument(string $domain, Document $certificate): void {
// Check if update or insert required // Check if update or insert required
$certificateDocument = $this->dbForConsole->findOne('certificates', [ new Query('domain', Query::TYPE_EQUAL, [$domain]) ]); $certificateDocument = $this->dbForConsole->findOne('certificates', [ new Query('domain', Query::TYPE_EQUAL, [$domain]) ]);
if (!empty($certificateDocument) && !$certificateDocument->isEmpty()) { if (!empty($certificateDocument) && !$certificateDocument->isEmpty()) {
@ -175,15 +175,15 @@ class CertificatesV1 extends Worker
*/ */
private function getMainDomain(): ?string { private function getMainDomain(): ?string {
if (!empty(App::getEnv('_APP_DOMAIN', ''))) { if (!empty(App::getEnv('_APP_DOMAIN', ''))) {
$mainDomain = App::getEnv('_APP_DOMAIN', ''); return App::getEnv('_APP_DOMAIN', '');
} else { } else {
$domainDocument = $this->dbForConsole->findOne('domains', [], 0, ['_id'], ['ASC']); $domainDocument = $this->dbForConsole->findOne('domains', [], 0, ['_id'], ['ASC']);
if($domainDocument) { if($domainDocument) {
$mainDomain = $domainDocument->getAttribute('domain'); return $domainDocument->getAttribute('domain');
} }
} }
return $mainDomain; return null;
} }
/** /**
@ -262,7 +262,7 @@ class CertificatesV1 extends Worker
* *
* @return array Named array with keys 'stdout' and 'stderr', both string * @return array Named array with keys 'stdout' and 'stderr', both string
*/ */
private function letsEncryptAction(string $domain, string $email): array { private function issueCertificate(string $domain, string $email): array {
$staging = (App::isProduction()) ? '' : ' --dry-run'; $staging = (App::isProduction()) ? '' : ' --dry-run';
$stdout = ''; $stdout = '';