From 1ff229ca02df09c551a4d0ecc82471fa47168812 Mon Sep 17 00:00:00 2001 From: Jonni Liljamo Date: Mon, 28 Oct 2024 20:01:04 +0200 Subject: [PATCH] feat: add tsigkey field to domains --- internal/db/domains.go | 16 ++++++++++++++-- internal/db/migrations.go | 2 ++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/internal/db/domains.go b/internal/db/domains.go index 9aa0edf..481cd0c 100644 --- a/internal/db/domains.go +++ b/internal/db/domains.go @@ -27,13 +27,14 @@ type Domain struct { Domain string A string AcmeChallenge string + TsigKey string Owner DomainOwner } // FetchDomainsForUser fetches all domains for a specific user. func FetchDomainsForUser(userID string) ([]Domain, error) { - rows, err := DBConn.Query(`SELECT id, apikey, ddns_domain, a_record + rows, err := DBConn.Query(`SELECT id, apikey, ddns_domain, a_record, tsigkey FROM domains WHERE owner = $1`, userID) if err != nil { return nil, err @@ -43,7 +44,7 @@ func FetchDomainsForUser(userID string) ([]Domain, error) { var domains []Domain for rows.Next() { var domain Domain - err = rows.Scan(&domain.ID, &domain.APIKey, &domain.Domain, &domain.A) + err = rows.Scan(&domain.ID, &domain.APIKey, &domain.Domain, &domain.A, &domain.TsigKey) if err != nil { return nil, err } @@ -207,3 +208,14 @@ func DeleteDomainAcmeChallenge(ddnsDomain string) error { return nil } + +// FetchDomainTsigKey fetches the tsig key of a domain. +func FetchDomainTsigKey(ddnsDomain string) (string, error) { + var tsig string + err := DBConn.QueryRow(`SELECT tsigkey FROM domains WHERE ddns_domain = $1`, + ddnsDomain).Scan(&tsig) + if err != nil { + return "", err + } + return tsig, nil +} diff --git a/internal/db/migrations.go b/internal/db/migrations.go index 2970cb5..ccca67e 100644 --- a/internal/db/migrations.go +++ b/internal/db/migrations.go @@ -84,5 +84,7 @@ func migrations() []string { )`), fmt.Sprintf(`ALTER TABLE domains ADD acme_challenge TEXT DEFAULT ''`), + fmt.Sprintf(`ALTER TABLE domains + ADD tsigkey TEXT DEFAULT ''`), } } -- 2.44.1