appwrite/src/Appwrite/Platform/Tasks/SSL.php

44 lines
1.5 KiB
PHP
Raw Normal View History

2022-07-13 07:02:55 +00:00
<?php
2022-07-14 02:04:31 +00:00
2022-11-14 10:01:41 +00:00
namespace Appwrite\Platform\Tasks;
2022-07-13 07:02:55 +00:00
use Appwrite\Event\Certificate;
2024-03-07 14:29:42 +00:00
use Utopia\Http\Http;
2022-07-13 07:02:55 +00:00
use Utopia\CLI\Console;
use Utopia\Database\Document;
2024-03-06 17:34:21 +00:00
use Utopia\Platform\Action;
2024-03-07 14:29:42 +00:00
use Utopia\Http\Validator\Boolean;
use Utopia\Http\Validator\Hostname;
2022-07-13 07:02:55 +00:00
2022-07-14 02:04:31 +00:00
class SSL extends Action
{
2022-08-02 01:58:36 +00:00
public static function getName(): string
{
return 'ssl';
}
2022-07-14 02:04:31 +00:00
2022-07-13 07:02:55 +00:00
public function __construct()
{
$this
->desc('Validate server certificates')
2024-03-07 14:29:42 +00:00
->param('domain', Http::getEnv('_APP_DOMAIN', ''), new Hostname(), 'Domain to generate certificate for. If empty, main domain will be used.', true)
2024-02-12 01:18:19 +00:00
->param('skip-check', true, new Boolean(true), 'If DNS and renew check should be skipped. Defaults to true, and when true, all jobs will result in certificate generation attempt.', true)
2023-07-18 07:54:11 +00:00
->inject('queueForCertificates')
2024-02-12 01:18:19 +00:00
->callback(fn (string $domain, bool|string $skipCheck, Certificate $queueForCertificates) => $this->action($domain, $skipCheck, $queueForCertificates));
2022-07-13 07:02:55 +00:00
}
2024-02-12 01:18:19 +00:00
public function action(string $domain, bool|string $skipCheck, Certificate $queueForCertificates): void
2022-07-13 07:02:55 +00:00
{
2024-02-12 01:18:19 +00:00
$skipCheck = \strval($skipCheck) === 'true';
2022-07-13 07:02:55 +00:00
Console::success('Scheduling a job to issue a TLS certificate for domain: ' . $domain);
2023-07-18 07:54:11 +00:00
$queueForCertificates
2022-07-13 07:02:55 +00:00
->setDomain(new Document([
'domain' => $domain
]))
2024-02-12 01:18:19 +00:00
->setSkipRenewCheck($skipCheck)
2022-07-13 07:02:55 +00:00
->trigger();
}
2022-07-14 02:04:31 +00:00
}