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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

add UUID at INFO #2139

Merged
merged 7 commits into from
Feb 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ BUGS:

FEATURES:
* Add support for `skip_import_rotation` and `skip_static_role_import_rotation` in `ldap_secret_backend_static_role` and `ldap_secret_backend` respectively. Requires Vault 1.16+ ([#2128](https://github.com/hashicorp/terraform-provider-vault/pull/2128)).
* Improve logging to track full API exchanges between the provider and Vault ([#2139](https://github.com/hashicorp/terraform-provider-vault/pull/2139))

## 3.25.0 (Feb 14, 2024)

Expand Down
11 changes: 7 additions & 4 deletions helper/transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"crypto/tls"
"encoding/json"
"fmt"
"github.com/google/uuid"
"log"
"net/http"
"net/http/httputil"
Expand Down Expand Up @@ -56,6 +57,7 @@ func DefaultTransportOptions() *TransportOptions {
if logBody, err := strconv.ParseBool(os.Getenv(EnvLogBody)); err == nil {
opts.LogRequestBody = logBody
opts.LogResponseBody = logBody

} else {
if logRequestBody, err := strconv.ParseBool(os.Getenv(EnvLogRequestBody)); err == nil {
opts.LogRequestBody = logRequestBody
Expand Down Expand Up @@ -89,6 +91,7 @@ func (t *TransportWrapper) SetTLSConfig(c *tls.Config) error {
}

func (t *TransportWrapper) RoundTrip(req *http.Request) (*http.Response, error) {
transportID := uuid.New().String()
if logging.IsDebugOrHigher() {
var origHeaders http.Header
if len(t.options.HMACRequestHeaders) > 0 && len(req.Header) > 0 {
Expand All @@ -108,7 +111,7 @@ func (t *TransportWrapper) RoundTrip(req *http.Request) (*http.Response, error)

reqData, err := httputil.DumpRequestOut(req, t.options.LogRequestBody)
if err == nil {
log.Printf("[DEBUG] "+logReqMsg, t.name, prettyPrintJsonLines(reqData))
log.Printf("[DEBUG] "+logReqMsg, transportID, t.name, prettyPrintJsonLines(reqData))
} else {
log.Printf("[ERROR] %s API Request error: %#v", t.name, err)
}
Expand All @@ -126,7 +129,7 @@ func (t *TransportWrapper) RoundTrip(req *http.Request) (*http.Response, error)
if logging.IsDebugOrHigher() {
respData, err := httputil.DumpResponse(resp, t.options.LogResponseBody)
if err == nil {
log.Printf("[DEBUG] "+logRespMsg, t.name, prettyPrintJsonLines(respData))
log.Printf("[DEBUG] "+logRespMsg, transportID, t.name, prettyPrintJsonLines(respData))
} else {
log.Printf("[ERROR] %s API Response error: %#v", t.name, err)
}
Expand Down Expand Up @@ -157,12 +160,12 @@ func prettyPrintJsonLines(b []byte) string {
return strings.Join(parts, "\n")
}

const logReqMsg = `%s API Request Details:
const logReqMsg = `[%s] %s API Request Details:
---[ REQUEST ]---------------------------------------
%s
-----------------------------------------------------`

const logRespMsg = `%s API Response Details:
const logRespMsg = `[%s] %s API Response Details:
---[ RESPONSE ]--------------------------------------
%s
-----------------------------------------------------`