1package dto
2
3import (
4 "time"
5
6 "github.com/bnema/gordon/internal/domain"
7)
8
9// TLSStatusResponse represents the public TLS/ACME status for the admin API.
10type TLSStatusResponse struct {
11 ACMEEnabled bool `json:"acme_enabled"`
12 ConfiguredMode string `json:"configured_mode"`
13 EffectiveMode string `json:"effective_mode"`
14 SelectionReason string `json:"selection_reason"`
15 TokenSource string `json:"token_source"`
16 Certificates []TLSCertificateEntry `json:"certificates"`
17 Routes []TLSRouteCoverage `json:"routes"`
18 Errors []string `json:"errors,omitempty"`
19}
20
21// TLSCertificateEntry represents a managed certificate entry in the TLS status.
22type TLSCertificateEntry struct {
23 ID string `json:"id"`
24 Names []string `json:"names"`
25 Challenge string `json:"challenge"`
26 Status string `json:"status"`
27 NotAfter time.Time `json:"not_after"`
28 LastError string `json:"last_error,omitempty"`
29 RenewalPending bool `json:"renewal_pending"`
30}
31
32// TLSRouteCoverage represents a route's TLS coverage status.
33type TLSRouteCoverage struct {
34 Domain string `json:"domain"`
35 Covered bool `json:"covered"`
36 CoveredBy string `json:"covered_by,omitempty"`
37 RequiredACME bool `json:"required_acme"`
38 Error string `json:"error,omitempty"`
39}
40
41// TLSStatusFromDomain converts a public TLS domain status to its transport DTO.
42func TLSStatusFromDomain(s domain.PublicTLSStatus) TLSStatusResponse {
43 certs := make([]TLSCertificateEntry, 0, len(s.Certificates))
44 for _, c := range s.Certificates {
45 certs = append(certs, TLSCertificateEntry{
46 ID: c.ID,
47 Names: c.Names,
48 Challenge: string(c.Challenge),
49 Status: string(c.Status),
50 NotAfter: c.NotAfter,
51 LastError: c.LastError,
52 RenewalPending: c.RenewalPending,
53 })
54 }
55
56 routes := make([]TLSRouteCoverage, 0, len(s.Routes))
57 for _, r := range s.Routes {
58 routes = append(routes, TLSRouteCoverage{
59 Domain: r.Domain,
60 Covered: r.Covered,
61 CoveredBy: r.CoveredBy,
62 RequiredACME: r.RequiredACME,
63 Error: r.Error,
64 })
65 }
66
67 return TLSStatusResponse{
68 ACMEEnabled: s.ACMEEnabled,
69 ConfiguredMode: string(s.ConfiguredMode),
70 EffectiveMode: string(s.EffectiveMode),
71 SelectionReason: s.SelectionReason,
72 TokenSource: string(s.TokenSource),
73 Certificates: certs,
74 Routes: routes,
75 Errors: s.Errors,
76 }
77}