Skip to content

Commit

Permalink
chore: add more debug logging to the keycloak groups request
Browse files Browse the repository at this point in the history
  • Loading branch information
smlx committed Aug 23, 2024
1 parent 4fba651 commit 32055b0
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions internal/keycloak/groups.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"io"
"log/slog"
"net/http"
"net/http/httputil"
"path"

"golang.org/x/oauth2/clientcredentials"
Expand Down Expand Up @@ -40,11 +41,26 @@ func (c *Client) rawGroups(ctx context.Context) ([]byte, error) {
q := req.URL.Query()
q.Add("briefRepresentation", "true")
req.URL.RawQuery = q.Encode()
// debug groups request
dump, err := httputil.DumpRequestOut(req, true)
if err != nil {
c.log.Debug("couldn't dump request", slog.Any("error", err))
} else {
c.log.Debug("rawGroups", slog.String("request", string(dump)))
}
// perform request
res, err := c.httpClient(ctx).Do(req)
if err != nil {
return nil, fmt.Errorf("couldn't get groups: %v", err)
}
defer res.Body.Close()
// debug groups response
dump, err = httputil.DumpResponse(res, true)
if err != nil {
c.log.Debug("couldn't dump response", slog.Any("error", err))
} else {
c.log.Debug("rawGroups", slog.String("response", string(dump)))
}
if res.StatusCode > 299 {
body, _ := io.ReadAll(res.Body)
return nil, fmt.Errorf("bad groups response: %d\n%s", res.StatusCode, body)
Expand Down

0 comments on commit 32055b0

Please sign in to comment.