From 0c106280c4a41acd77b013893041064428e0648e Mon Sep 17 00:00:00 2001 From: Jordan Jones Date: Sat, 7 Sep 2024 00:39:47 -0700 Subject: [PATCH] chore: move to external-dns's domain filter interface This had me confused for the last couple days. I don't understand why we don't give the actual DomainFilter here. --- internal/unifi/provider.go | 4 ++-- pkg/webhook/webhook.go | 10 ++-------- 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/internal/unifi/provider.go b/internal/unifi/provider.go index 729514e..33b1b65 100644 --- a/internal/unifi/provider.go +++ b/internal/unifi/provider.go @@ -17,7 +17,7 @@ type Provider struct { domainFilter endpoint.DomainFilter } -// newUnifiProvider initializes a new DNSProvider. +// NewUnifiProvider initializes a new DNSProvider. func NewUnifiProvider(domainFilter endpoint.DomainFilter, config *Config) (provider.Provider, error) { c, err := newUnifiClient(config) @@ -77,6 +77,6 @@ func (p *Provider) ApplyChanges(ctx context.Context, changes *plan.Changes) erro } // GetDomainFilter returns the domain filter for the provider. -func (p *Provider) GetDomainFilter() endpoint.DomainFilter { +func (p *Provider) GetDomainFilter() endpoint.DomainFilterInterface { return p.domainFilter } diff --git a/pkg/webhook/webhook.go b/pkg/webhook/webhook.go index 735ad4d..28d9c34 100644 --- a/pkg/webhook/webhook.go +++ b/pkg/webhook/webhook.go @@ -200,19 +200,13 @@ func (p *Webhook) Negotiate(w http.ResponseWriter, r *http.Request) { return } - b, err := p.provider.GetDomainFilter().MarshalJSON() + w.Header().Set(contentTypeHeader, string(mediaTypeVersion1)) + err := json.NewEncoder(w).Encode(p.provider.GetDomainFilter()) if err != nil { requestLog(r).Error("failed to marshal domain filter") w.WriteHeader(http.StatusInternalServerError) return } - - w.Header().Set(contentTypeHeader, string(mediaTypeVersion1)) - if _, writeError := w.Write(b); writeError != nil { - requestLog(r).With(zap.Error(writeError)).Error("error writing response") - w.WriteHeader(http.StatusInternalServerError) - return - } } func requestLog(r *http.Request) *zap.Logger {