mirror of
https://github.com/mjl-/mox.git
synced 2025-07-12 20:54:39 +03:00
use new sherpadoc rename mechanism to remove some typename stuttering
the stuttering was introduced to make the same type name declared in multiple packages, and used in the admin sherpa api, unique. with sherpadoc's new rename, we can make them unique when generating the api definition/docs, and the Go code can use nicer names.
This commit is contained in:
@ -10,12 +10,12 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
ReportDBTypes = []any{TLSReportRecord{}}
|
||||
ReportDBTypes = []any{Record{}}
|
||||
ReportDB *bstore.DB
|
||||
mutex sync.Mutex
|
||||
|
||||
// Accessed directly by tlsrptsend.
|
||||
ResultDBTypes = []any{TLSResult{}, TLSRPTSuppressAddress{}}
|
||||
ResultDBTypes = []any{TLSResult{}, SuppressAddress{}}
|
||||
ResultDB *bstore.DB
|
||||
)
|
||||
|
||||
|
@ -44,12 +44,10 @@ var (
|
||||
}
|
||||
)
|
||||
|
||||
// TLSReportRecord is a TLS report as a database record, including information
|
||||
// Record is a TLS report as a database record, including information
|
||||
// about the sender.
|
||||
//
|
||||
// todo: should be named just Record, but it would cause a sherpa type name conflict.
|
||||
type TLSReportRecord struct {
|
||||
ID int64 `bstore:"typename Record"`
|
||||
type Record struct {
|
||||
ID int64
|
||||
Domain string `bstore:"index"` // Policy domain to which the TLS report applies. Unicode.
|
||||
FromDomain string
|
||||
MailFrom string
|
||||
@ -119,7 +117,7 @@ func AddReport(ctx context.Context, log mlog.Log, verifiedFromDomain dns.Domain,
|
||||
metricSession.WithLabelValues(result).Add(float64(f.FailedSessionCount))
|
||||
}
|
||||
|
||||
record := TLSReportRecord{0, d.Name(), verifiedFromDomain.Name(), mailFrom, d == mox.Conf.Static.HostnameDomain, *r}
|
||||
record := Record{0, d.Name(), verifiedFromDomain.Name(), mailFrom, d == mox.Conf.Static.HostnameDomain, *r}
|
||||
if err := tx.Insert(&record); err != nil {
|
||||
return fmt.Errorf("inserting report for domain: %w", err)
|
||||
}
|
||||
@ -133,22 +131,22 @@ func AddReport(ctx context.Context, log mlog.Log, verifiedFromDomain dns.Domain,
|
||||
}
|
||||
|
||||
// Records returns all TLS reports in the database.
|
||||
func Records(ctx context.Context) ([]TLSReportRecord, error) {
|
||||
func Records(ctx context.Context) ([]Record, error) {
|
||||
db, err := reportDB(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return bstore.QueryDB[TLSReportRecord](ctx, db).List()
|
||||
return bstore.QueryDB[Record](ctx, db).List()
|
||||
}
|
||||
|
||||
// RecordID returns the report for the ID.
|
||||
func RecordID(ctx context.Context, id int64) (TLSReportRecord, error) {
|
||||
func RecordID(ctx context.Context, id int64) (Record, error) {
|
||||
db, err := reportDB(ctx)
|
||||
if err != nil {
|
||||
return TLSReportRecord{}, err
|
||||
return Record{}, err
|
||||
}
|
||||
|
||||
e := TLSReportRecord{ID: id}
|
||||
e := Record{ID: id}
|
||||
err = db.Get(ctx, &e)
|
||||
return e, err
|
||||
}
|
||||
@ -156,18 +154,18 @@ func RecordID(ctx context.Context, id int64) (TLSReportRecord, error) {
|
||||
// RecordsPeriodPolicyDomain returns the reports overlapping start and end, for the
|
||||
// given policy domain. If policy domain is empty, records for all domains are
|
||||
// returned.
|
||||
func RecordsPeriodDomain(ctx context.Context, start, end time.Time, policyDomain dns.Domain) ([]TLSReportRecord, error) {
|
||||
func RecordsPeriodDomain(ctx context.Context, start, end time.Time, policyDomain dns.Domain) ([]Record, error) {
|
||||
db, err := reportDB(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
q := bstore.QueryDB[TLSReportRecord](ctx, db)
|
||||
q := bstore.QueryDB[Record](ctx, db)
|
||||
var zerodom dns.Domain
|
||||
if policyDomain != zerodom {
|
||||
q.FilterNonzero(TLSReportRecord{Domain: policyDomain.Name()})
|
||||
q.FilterNonzero(Record{Domain: policyDomain.Name()})
|
||||
}
|
||||
q.FilterFn(func(r TLSReportRecord) bool {
|
||||
q.FilterFn(func(r Record) bool {
|
||||
dr := r.Report.DateRange
|
||||
return !dr.Start.Before(start) && dr.Start.Before(end) || dr.End.After(start) && !dr.End.After(end)
|
||||
})
|
||||
|
@ -60,12 +60,10 @@ type TLSResult struct {
|
||||
Results []tlsrpt.Result
|
||||
}
|
||||
|
||||
// todo: TLSRPTSuppressAddress should be named just SuppressAddress, but would clash with dmarcdb.SuppressAddress in sherpa api.
|
||||
|
||||
// TLSRPTSuppressAddress is a reporting address for which outgoing TLS reports
|
||||
// SuppressAddress is a reporting address for which outgoing TLS reports
|
||||
// will be suppressed for a period.
|
||||
type TLSRPTSuppressAddress struct {
|
||||
ID int64
|
||||
type SuppressAddress struct {
|
||||
ID int64 `bstore:"typename TLSRPTSuppressAddress"`
|
||||
Inserted time.Time `bstore:"default now"`
|
||||
ReportingAddress string `bstore:"unique"`
|
||||
Until time.Time `bstore:"nonzero"`
|
||||
@ -205,7 +203,7 @@ func RemoveResultsRecipientDomain(ctx context.Context, recipientDomain dns.Domai
|
||||
}
|
||||
|
||||
// SuppressAdd adds an address to the suppress list.
|
||||
func SuppressAdd(ctx context.Context, ba *TLSRPTSuppressAddress) error {
|
||||
func SuppressAdd(ctx context.Context, ba *SuppressAddress) error {
|
||||
db, err := resultDB(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
@ -215,13 +213,13 @@ func SuppressAdd(ctx context.Context, ba *TLSRPTSuppressAddress) error {
|
||||
}
|
||||
|
||||
// SuppressList returns all reporting addresses on the suppress list.
|
||||
func SuppressList(ctx context.Context) ([]TLSRPTSuppressAddress, error) {
|
||||
func SuppressList(ctx context.Context) ([]SuppressAddress, error) {
|
||||
db, err := resultDB(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return bstore.QueryDB[TLSRPTSuppressAddress](ctx, db).SortDesc("ID").List()
|
||||
return bstore.QueryDB[SuppressAddress](ctx, db).SortDesc("ID").List()
|
||||
}
|
||||
|
||||
// SuppressRemove removes a reporting address record from the suppress list.
|
||||
@ -231,7 +229,7 @@ func SuppressRemove(ctx context.Context, id int64) error {
|
||||
return err
|
||||
}
|
||||
|
||||
return db.Delete(ctx, &TLSRPTSuppressAddress{ID: id})
|
||||
return db.Delete(ctx, &SuppressAddress{ID: id})
|
||||
}
|
||||
|
||||
// SuppressUpdate updates the until field of a reporting address record.
|
||||
@ -241,7 +239,7 @@ func SuppressUpdate(ctx context.Context, id int64, until time.Time) error {
|
||||
return err
|
||||
}
|
||||
|
||||
ba := TLSRPTSuppressAddress{ID: id}
|
||||
ba := SuppressAddress{ID: id}
|
||||
err = db.Get(ctx, &ba)
|
||||
if err != nil {
|
||||
return err
|
||||
|
Reference in New Issue
Block a user