aboutsummaryrefslogtreecommitdiff
path: root/backend/internal/store/postgres.go
diff options
context:
space:
mode:
Diffstat (limited to 'backend/internal/store/postgres.go')
-rw-r--r--backend/internal/store/postgres.go28
1 files changed, 28 insertions, 0 deletions
diff --git a/backend/internal/store/postgres.go b/backend/internal/store/postgres.go
index 57fa258..fb07bdc 100644
--- a/backend/internal/store/postgres.go
+++ b/backend/internal/store/postgres.go
@@ -393,3 +393,31 @@ func (s *PostgresStore) DeleteMaintenance(id int) error {
}
return nil
}
+
+func (s *PostgresStore) GetSSLInfo(serviceID int) (*model.SSLInfo, error) {
+ var info model.SSLInfo
+ err := s.pool.QueryRow(context.Background(),
+ `SELECT service_id, issuer, expires_at, days_remaining, checked_at FROM ssl_info WHERE service_id = $1`,
+ serviceID,
+ ).Scan(&info.ServiceID, &info.Issuer, &info.ExpiresAt, &info.DaysRemaining, &info.CheckedAt)
+ if err != nil {
+ if err == pgx.ErrNoRows {
+ return nil, nil
+ }
+ return nil, fmt.Errorf("get ssl info: %w", err)
+ }
+ return &info, nil
+}
+
+func (s *PostgresStore) SaveSSLInfo(info model.SSLInfo) error {
+ _, err := s.pool.Exec(context.Background(),
+ `INSERT INTO ssl_info (service_id, issuer, expires_at, days_remaining, checked_at)
+ VALUES ($1, $2, $3, $4, $5)
+ ON CONFLICT (service_id) DO UPDATE SET issuer=$2, expires_at=$3, days_remaining=$4, checked_at=$5`,
+ info.ServiceID, info.Issuer, info.ExpiresAt, info.DaysRemaining, info.CheckedAt,
+ )
+ if err != nil {
+ return fmt.Errorf("save ssl info: %w", err)
+ }
+ return nil
+}