Support configurable TLS probes in the API and dashboard

This commit is contained in:
ayurishchev committed 2026-11-20 21:15:22 +03:00
1 parent 0bde5627f0
commit c7fdd2c430
38 files changed
+495 -203

No files matched your search

+24 -12
View File
@@ -4,6 +4,8 @@ import (
"context"
"encoding/json"
"fmt"
"cloudipvalidator/internal/inbound"
)
// GetInboundChecks returns the singleton inbound-checks settings row.
@@ -12,10 +14,10 @@ import (
// normal condition.
func (d *DB) GetInboundChecks(ctx context.Context) (InboundChecksSettings, error) {
var s InboundChecksSettings
var portsJSON, createdAt, updatedAt string
var portsJSON, tlsJSON, createdAt, updatedAt string
err := d.QueryRowContext(ctx, `
SELECT ports, icmp, created_at, updated_at FROM inbound_checks_settings WHERE id=1
`).Scan(&portsJSON, &s.ICMP, &createdAt, &updatedAt)
SELECT ports, icmp, tls_checks, created_at, updated_at FROM inbound_checks_settings WHERE id=1
`).Scan(&portsJSON, &s.ICMP, &tlsJSON, &createdAt, &updatedAt)
if err != nil {
return InboundChecksSettings{}, err
}
@@ -25,6 +27,9 @@ func (d *DB) GetInboundChecks(ctx context.Context) (InboundChecksSettings, error
if s.Ports == nil {
s.Ports = []int{}
}
if err := json.Unmarshal([]byte(tlsJSON), &s.TLSChecks); err != nil {
return InboundChecksSettings{}, fmt.Errorf("decode inbound TLS checks: %w", err)
}
if s.CreatedAt, err = dbToTime(createdAt); err != nil {
return InboundChecksSettings{}, err
}
@@ -34,12 +39,9 @@ func (d *DB) GetInboundChecks(ctx context.Context) (InboundChecksSettings, error
return s, nil
}
// SetInboundChecks persists a new prober check configuration. Validation is
// purely local (port range, no duplicates) — unlike fip_settle_seconds,
// there's no cross-field dependency on other orchestrator config, so this
// is called directly by the HTTP handler without going through
// orchestrator.Orchestrator.
func (d *DB) SetInboundChecks(ctx context.Context, ports []int, icmp bool) error {
// SetInboundChecks preserves the TLS configuration when tlsChecks is nil.
// A pointer to a nil slice selects automatic mode.
func (d *DB) SetInboundChecks(ctx context.Context, ports []int, icmp bool, tlsChecks *[]inbound.TLSCheck) error {
seen := make(map[int]bool, len(ports))
for _, p := range ports {
if p < 1 || p > 65535 {
@@ -57,9 +59,19 @@ func (d *DB) SetInboundChecks(ctx context.Context, ports []int, icmp bool) error
if err != nil {
return err
}
now := timeToDB(Now())
var tlsJSON any
if tlsChecks != nil {
if err := inbound.ValidateTLSChecks(*tlsChecks); err != nil {
return fmt.Errorf("%v: %w", err, ErrValidation)
}
encoded, err := json.Marshal(*tlsChecks)
if err != nil {
return err
}
tlsJSON = string(encoded)
}
_, err = d.ExecContext(ctx, `
UPDATE inbound_checks_settings SET ports=?, icmp=?, updated_at=? WHERE id=1
`, string(payload), icmp, now)
UPDATE inbound_checks_settings SET ports=?, icmp=?, tls_checks=COALESCE(?, tls_checks), updated_at=? WHERE id=1
`, string(payload), icmp, tlsJSON, timeToDB(Now()))
return err
}