Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Log HTTP request before sending towards NSX #963

Merged
merged 1 commit into from
Sep 7, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions nsxt/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import (
"log"
"math/rand"
"net/http"
"net/http/httputil"
"os"
"regexp"
"strings"
"time"
Expand Down Expand Up @@ -763,6 +765,22 @@ func (processor remoteAuthHeaderProcessor) Process(req *http.Request) error {
return nil
}

type logRequestProcessor struct {
}

func newLogRequestProcessor() *logRequestProcessor {
return &logRequestProcessor{}
}

func (processor logRequestProcessor) Process(req *http.Request) error {
reqDump, err := httputil.DumpRequestOut(req, true)
if err != nil {
log.Fatal(err)
}
log.Printf("Issuing request towards NSX:\n%s", reqDump)
return nil
}

type bearerAuthHeaderProcessor struct {
Token string
}
Expand Down Expand Up @@ -979,6 +997,10 @@ func getPolicyConnectorWithHeaders(clients interface{}, customHeaders *map[strin
log.Printf("[INFO]: Session headers configured for policy objects")
}

if os.Getenv("TF_LOG_PROVIDER") != "" {
requestProcessors = append(requestProcessors, newLogRequestProcessor().Process)
}

if len(requestProcessors) > 0 {
connectorOptions = append(connectorOptions, client.WithRequestProcessors(requestProcessors...))
}
Expand Down