Skip to content

Commit

Permalink
chore: remove excessive logging
Browse files Browse the repository at this point in the history
  • Loading branch information
kashalls committed Oct 16, 2024
1 parent 09b0910 commit 85227d8
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 33 deletions.
31 changes: 0 additions & 31 deletions internal/unifi/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,51 +109,22 @@ func (c *httpClient) login() error {
}

func (c *httpClient) doRequest(method, path string, body io.Reader) (*http.Response, error) {
log.Debug("Do request", zap.String("method", method), zap.String("path", path))

// Convert body to bytes for logging and reuse
var bodyBytes []byte
if body != nil {
bodyBytes, _ = io.ReadAll(body)
body = bytes.NewReader(bodyBytes)
log.Debug("Request body", zap.String("body", string(bodyBytes)))
}

req, err := http.NewRequest(method, path, body)
if err != nil {
return nil, err
}
// Set the required headers
if body != nil {
req.Header.Set("Content-Length", fmt.Sprintf("%d", len(bodyBytes)))
}
// Dynamically set the Host header
parsedURL, err := url.Parse(path)
if err != nil {
return nil, err
}
req.Host = parsedURL.Host

c.setHeaders(req)

resp, err := c.Client.Do(req)
if err != nil {
log.Error("Request failed", zap.Error(err))
return nil, err
}

// Log response body
respBody, _ := io.ReadAll(resp.Body)
log.Debug("response body", zap.String("body", string(respBody)))
resp.Body = io.NopCloser(bytes.NewBuffer(respBody)) // Restore the response body for further use

if csrf := resp.Header.Get("X-CSRF-Token"); csrf != "" {
c.csrf = csrf
log.Debug("Updated CSRF token", zap.String("token", c.csrf))
}

log.Debug("recieved response", zap.String("method", method), zap.String("path", path), zap.Int("statusCode", resp.StatusCode))

// If the status code is 401, re-login and retry the request
if resp.StatusCode == http.StatusUnauthorized {
log.Debug("received 401 unauthorized, attempting to re-login")
Expand Down Expand Up @@ -183,8 +154,6 @@ func (c *httpClient) doRequest(method, path string, body io.Reader) (*http.Respo

// GetEndpoints retrieves the list of DNS records from the UniFi controller.
func (c *httpClient) GetEndpoints() ([]DNSRecord, error) {
log.Debug("Getting endpoints")

resp, err := c.doRequest(
http.MethodGet,
FormatUrl(c.ClientURLs.Records, c.Config.Host, c.Config.Site),
Expand Down
2 changes: 0 additions & 2 deletions pkg/webhook/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ func (p *Webhook) Records(w http.ResponseWriter, r *http.Request) {
return
}

requestLog(r).Debug("requesting records")
ctx := r.Context()
records, err := p.provider.Records(ctx)
if err != nil {
Expand All @@ -106,7 +105,6 @@ func (p *Webhook) Records(w http.ResponseWriter, r *http.Request) {
return
}

requestLog(r).With(zap.Int("count", len(records))).Debug("returning records")
w.Header().Set(contentTypeHeader, string(mediaTypeVersion1))
w.Header().Set(varyHeader, contentTypeHeader)
err = json.NewEncoder(w).Encode(records)
Expand Down

0 comments on commit 85227d8

Please sign in to comment.