@@ -22,6 +22,7 @@ import (
2222
2323 log "github.com/scaleway/scaleway-cli/vendor/github.com/Sirupsen/logrus"
2424 "github.com/scaleway/scaleway-cli/vendor/github.com/moul/anonuuid"
25+ "github.com/scaleway/scaleway-cli/vendor/github.com/moul/http2curl"
2526)
2627
2728// Default values
@@ -626,13 +627,21 @@ func (s *ScalewayAPI) Sync() {
626627// GetResponse returns an http.Response object for the requested resource
627628func (s * ScalewayAPI ) GetResponse (resource string ) (* http.Response , error ) {
628629 uri := fmt .Sprintf ("%s/%s" , strings .TrimRight (s .APIUrl , "/" ), resource )
629- log . Debugf ( "GET %s" , uri )
630+
630631 req , err := http .NewRequest ("GET" , uri , nil )
631632 if err != nil {
632633 return nil , err
633634 }
634635 req .Header .Set ("X-Auth-Token" , s .Token )
635636 req .Header .Set ("Content-Type" , "application/json" )
637+
638+ curl , err := http2curl .GetCurlCommand (req )
639+ if os .Getenv ("SCW_SENSITIVE" ) != "1" {
640+ log .Debug (s .HideAPICredentials (curl .String ()))
641+ } else {
642+ log .Debug (curl .String ())
643+ }
644+
636645 return s .client .Do (req )
637646}
638647
@@ -645,18 +654,20 @@ func (s *ScalewayAPI) PostResponse(resource string, data interface{}) (*http.Res
645654 return nil , err
646655 }
647656
648- payloadString := strings .TrimSpace (fmt .Sprintf ("%s" , payload ))
649- if os .Getenv ("SCW_SENSITIVE" ) != "1" {
650- payloadString = s .HideAPICredentials (payloadString )
651- }
652- log .Debugf ("POST %s payload=%s" , uri , payloadString )
653-
654657 req , err := http .NewRequest ("POST" , uri , payload )
655658 if err != nil {
656659 return nil , err
657660 }
658661 req .Header .Set ("X-Auth-Token" , s .Token )
659662 req .Header .Set ("Content-Type" , "application/json" )
663+
664+ curl , err := http2curl .GetCurlCommand (req )
665+ if os .Getenv ("SCW_SENSITIVE" ) != "1" {
666+ log .Debug (s .HideAPICredentials (curl .String ()))
667+ } else {
668+ log .Debug (curl .String ())
669+ }
670+
660671 return s .client .Do (req )
661672}
662673
@@ -669,18 +680,20 @@ func (s *ScalewayAPI) PatchResponse(resource string, data interface{}) (*http.Re
669680 return nil , err
670681 }
671682
672- payloadString := strings .TrimSpace (fmt .Sprintf ("%s" , payload ))
673- if os .Getenv ("SCW_SENSITIVE" ) != "1" {
674- payloadString = s .HideAPICredentials (payloadString )
675- }
676- log .Debugf ("PATCH %s payload=%s" , uri , payloadString )
677-
678683 req , err := http .NewRequest ("PATCH" , uri , payload )
679684 if err != nil {
680685 return nil , err
681686 }
682687 req .Header .Set ("X-Auth-Token" , s .Token )
683688 req .Header .Set ("Content-Type" , "application/json" )
689+
690+ curl , err := http2curl .GetCurlCommand (req )
691+ if os .Getenv ("SCW_SENSITIVE" ) != "1" {
692+ log .Debug (s .HideAPICredentials (curl .String ()))
693+ } else {
694+ log .Debug (curl .String ())
695+ }
696+
684697 return s .client .Do (req )
685698}
686699
@@ -693,31 +706,41 @@ func (s *ScalewayAPI) PutResponse(resource string, data interface{}) (*http.Resp
693706 return nil , err
694707 }
695708
696- payloadString := strings .TrimSpace (fmt .Sprintf ("%s" , payload ))
697- if os .Getenv ("SCW_SENSITIVE" ) != "1" {
698- payloadString = s .HideAPICredentials (payloadString )
699- }
700- log .Debugf ("PUT %s payload=%s" , uri , payloadString )
701-
702709 req , err := http .NewRequest ("PUT" , uri , payload )
703710 if err != nil {
704711 return nil , err
705712 }
706713 req .Header .Set ("X-Auth-Token" , s .Token )
707714 req .Header .Set ("Content-Type" , "application/json" )
715+
716+ curl , err := http2curl .GetCurlCommand (req )
717+ if os .Getenv ("SCW_SENSITIVE" ) != "1" {
718+ log .Debug (s .HideAPICredentials (curl .String ()))
719+ } else {
720+ log .Debug (curl .String ())
721+ }
722+
708723 return s .client .Do (req )
709724}
710725
711726// DeleteResponse returns an http.Response object for the deleted resource
712727func (s * ScalewayAPI ) DeleteResponse (resource string ) (* http.Response , error ) {
713728 uri := fmt .Sprintf ("%s/%s" , strings .TrimRight (s .APIUrl , "/" ), resource )
714- log . Debugf ( "DELETE %s" , uri )
729+
715730 req , err := http .NewRequest ("DELETE" , uri , nil )
716731 if err != nil {
717732 return nil , err
718733 }
719734 req .Header .Set ("X-Auth-Token" , s .Token )
720735 req .Header .Set ("Content-Type" , "application/json" )
736+
737+ curl , err := http2curl .GetCurlCommand (req )
738+ if os .Getenv ("SCW_SENSITIVE" ) != "1" {
739+ log .Debug (s .HideAPICredentials (curl .String ()))
740+ } else {
741+ log .Debug (curl .String ())
742+ }
743+
721744 return s .client .Do (req )
722745}
723746
0 commit comments