Skip to main content
Version: 0.1.0

The SslCertificateCheck model

The entity of SslCertificateCheck is represented as a model in MoonGuard, and it has the following definition:

Casts

NameDescription
statusThe status of the SSL certificate check, casted to the SslCertificateStatus enum
expiration_dateThe expiration date of the SSL certificate, casted to an immutable datetime object

Methods

Method NameReturn TypeDescription
site()BelongsToReturns a BelongsTo relationship between the SslCertificateCheck model and the Site model. This method allows you to retrieve the site associated with the SSL certificate check.
saveCertificate(SslCertificate $certificate, Url $url)voidSaves the result of a successful SSL certificate check. This method sets the status of the SSL certificate check to "VALID" if the certificate is valid, or "INVALID" if the certificate is invalid. It also saves the expiration date and issuer of the certificate.
saveError(Exception $exception)voidSaves the result of a failed SSL certificate check. This method sets the status of the SSL certificate check to "INVALID", and saves the failure reason.
certificateIsValid()boolReturns a boolean indicating whether the SSL certificate is valid.
certificateIsInvalid()boolReturns a boolean indicating whether the SSL certificate is invalid.
certificateIsAboutToExpire(int $maxDaysToExpire)boolReturns a boolean indicating whether the SSL certificate is about to expire within the specified number of days.
isEnabled()AttributeReturns an Attribute instance that indicates whether the SSL certificate check is enabled.

Using a custom SslCertificateCheck Model

In case you want to create a custom SslCertificateCheck model or extends it capabilities we recommend you the following steps:

  1. Create a new SslCertificateCheck class that extends from Illuminate\Database\Eloquent\Model and implements the Taecontrol\MoonGuard\Contracts\MoonGuardSslCertificateCheck interface.
<?php

use Illuminate\Database\Eloquent\Model;
use Taecontrol\MoonGuard\Contracts\MoonGuardSslCertificateCheck;

class SslCertificateCheck extends Model implements MoonGuardSslCertificateCheck
{
//Contract implementation
}
  1. Implement all the properties and methods required, you can guide yourself with the original SslCertificateCheck.php model from Moonguard here a resume.

  2. Replace the SslCertificateCheck class in the configuration file.

[
'ssl_certificate_check' => [
'enabled' => true,
'model' => \Taecontrol\MoonGuard\Models\SslCertificateCheck::class, //-> replace model
'notify_expiring_soon_if_certificate_expires_within_days' => 7,
'cron_schedule' => '* * * * *',
],
]