Skip to content
Closed
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
35 changes: 32 additions & 3 deletions builtin/providers/azurerm/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
mainStorage "github.com/Azure/azure-sdk-for-go/storage"
"github.com/hashicorp/terraform/terraform"
riviera "github.com/jen20/riviera/azure"
"io"
)

// ArmClient contains the handles to all the specific Azure Resource Manager
Expand Down Expand Up @@ -62,15 +63,43 @@ type ArmClient struct {
deploymentsClient resources.DeploymentsClient
}

type DebugBodyLogger struct {
Body io.ReadCloser
HeaderMessage string
}

func (r DebugBodyLogger) Close() error {
return r.Body.Close()
}

func (r DebugBodyLogger) Read(p []byte) (int, error) {
n, err := r.Body.Read(p)
if n > 0 {
log.Printf("[TRACE] %s: %s\n", r.HeaderMessage, string(p[0:n]))
}
return n, err
}

func NewDebugBodyLogger(body io.ReadCloser, headerMsg string) DebugBodyLogger {
logger := DebugBodyLogger{Body: body, HeaderMessage: headerMsg}
return logger
}

func withRequestLogging() autorest.SendDecorator {
return func(s autorest.Sender) autorest.Sender {
return autorest.SenderFunc(func(r *http.Request) (*http.Response, error) {
log.Printf("[DEBUG] Sending Azure RM Request %q to %q\n", r.Method, r.URL)
log.Printf("[DEBUG] Sending Azure RM Request %q to %q with content length %d\n", r.Method, r.URL, r.ContentLength)
if r.ContentLength > 0 {
r.Body = NewDebugBodyLogger(r.Body, fmt.Sprintf("Message body for %q %q", r.Method, r.URL))
}
resp, err := s.Do(r)
if resp != nil {
log.Printf("[DEBUG] Received Azure RM Request status code %s for %s\n", resp.Status, r.URL)
log.Printf("[DEBUG] Received Azure RM Request status code %s for %s with content length %d\n", resp.Status, r.URL, resp.ContentLength)
if resp.ContentLength > 0 {
r.Body = NewDebugBodyLogger(resp.Body, fmt.Sprintf("Response body from call to %q %q", r.Method, r.URL))
}
} else {
log.Printf("[DEBUG] Request to %s completed with no response", r.URL)
log.Printf("[DEBUG] Request to %s completed with no response\n", r.URL)
}
return resp, err
})
Expand Down