github.com/hugorut/terraform@v1.1.3/src/backend/remote-state/azure/sender.go (about) 1 package azure 2 3 import ( 4 "log" 5 "net/http" 6 "net/http/httputil" 7 8 "github.com/Azure/go-autorest/autorest" 9 "github.com/hugorut/terraform/src/logging" 10 ) 11 12 func buildSender() autorest.Sender { 13 return autorest.DecorateSender(&http.Client{ 14 Transport: &http.Transport{ 15 Proxy: http.ProxyFromEnvironment, 16 }, 17 }, withRequestLogging()) 18 } 19 20 func withRequestLogging() autorest.SendDecorator { 21 return func(s autorest.Sender) autorest.Sender { 22 return autorest.SenderFunc(func(r *http.Request) (*http.Response, error) { 23 // only log if logging's enabled 24 logLevel := logging.CurrentLogLevel() 25 if logLevel == "" { 26 return s.Do(r) 27 } 28 29 // strip the authorization header prior to printing 30 authHeaderName := "Authorization" 31 auth := r.Header.Get(authHeaderName) 32 if auth != "" { 33 r.Header.Del(authHeaderName) 34 } 35 36 // dump request to wire format 37 if dump, err := httputil.DumpRequestOut(r, true); err == nil { 38 log.Printf("[DEBUG] Azure Backend Request: \n%s\n", dump) 39 } else { 40 // fallback to basic message 41 log.Printf("[DEBUG] Azure Backend Request: %s to %s\n", r.Method, r.URL) 42 } 43 44 // add the auth header back 45 if auth != "" { 46 r.Header.Add(authHeaderName, auth) 47 } 48 49 resp, err := s.Do(r) 50 if resp != nil { 51 // dump response to wire format 52 if dump, err2 := httputil.DumpResponse(resp, true); err2 == nil { 53 log.Printf("[DEBUG] Azure Backend Response for %s: \n%s\n", r.URL, dump) 54 } else { 55 // fallback to basic message 56 log.Printf("[DEBUG] Azure Backend Response: %s for %s\n", resp.Status, r.URL) 57 } 58 } else { 59 log.Printf("[DEBUG] Request to %s completed with no response", r.URL) 60 } 61 return resp, err 62 }) 63 } 64 }