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 ;
use Utopia\CLI\Console ;
use Utopia\Database\Document ;
2024-03-08 12:57:20 +00:00
use Utopia\Platform\Action ;
2024-04-01 11:08:46 +00:00
use Utopia\System\System ;
2024-10-08 07:54:40 +00:00
use Utopia\Validator\Boolean ;
use Utopia\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-04-01 11:02:47 +00:00
-> param ( 'domain' , System :: 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
}