DEVELOPMENT ENVIRONMENT

~liljamo/felu

1ff229ca02df09c551a4d0ecc82471fa47168812 — Jonni Liljamo 24 days ago cb7bd83
feat: add tsigkey field to domains
2 files changed, 16 insertions(+), 2 deletions(-)

M internal/db/domains.go
M internal/db/migrations.go
M internal/db/domains.go => internal/db/domains.go +14 -2
@@ 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
}

M internal/db/migrations.go => internal/db/migrations.go +2 -0
@@ 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 ''`),
	}
}