@@ -22,6 +22,7 @@ import (
22
22
23
23
log "github.com/scaleway/scaleway-cli/vendor/github.com/Sirupsen/logrus"
24
24
"github.com/scaleway/scaleway-cli/vendor/github.com/moul/anonuuid"
25
+ "github.com/scaleway/scaleway-cli/vendor/github.com/moul/http2curl"
25
26
)
26
27
27
28
// Default values
@@ -626,13 +627,21 @@ func (s *ScalewayAPI) Sync() {
626
627
// GetResponse returns an http.Response object for the requested resource
627
628
func (s * ScalewayAPI ) GetResponse (resource string ) (* http.Response , error ) {
628
629
uri := fmt .Sprintf ("%s/%s" , strings .TrimRight (s .APIUrl , "/" ), resource )
629
- log . Debugf ( "GET %s" , uri )
630
+
630
631
req , err := http .NewRequest ("GET" , uri , nil )
631
632
if err != nil {
632
633
return nil , err
633
634
}
634
635
req .Header .Set ("X-Auth-Token" , s .Token )
635
636
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
+
636
645
return s .client .Do (req )
637
646
}
638
647
@@ -645,18 +654,20 @@ func (s *ScalewayAPI) PostResponse(resource string, data interface{}) (*http.Res
645
654
return nil , err
646
655
}
647
656
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
-
654
657
req , err := http .NewRequest ("POST" , uri , payload )
655
658
if err != nil {
656
659
return nil , err
657
660
}
658
661
req .Header .Set ("X-Auth-Token" , s .Token )
659
662
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
+
660
671
return s .client .Do (req )
661
672
}
662
673
@@ -669,18 +680,20 @@ func (s *ScalewayAPI) PatchResponse(resource string, data interface{}) (*http.Re
669
680
return nil , err
670
681
}
671
682
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
-
678
683
req , err := http .NewRequest ("PATCH" , uri , payload )
679
684
if err != nil {
680
685
return nil , err
681
686
}
682
687
req .Header .Set ("X-Auth-Token" , s .Token )
683
688
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
+
684
697
return s .client .Do (req )
685
698
}
686
699
@@ -693,31 +706,41 @@ func (s *ScalewayAPI) PutResponse(resource string, data interface{}) (*http.Resp
693
706
return nil , err
694
707
}
695
708
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
-
702
709
req , err := http .NewRequest ("PUT" , uri , payload )
703
710
if err != nil {
704
711
return nil , err
705
712
}
706
713
req .Header .Set ("X-Auth-Token" , s .Token )
707
714
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
+
708
723
return s .client .Do (req )
709
724
}
710
725
711
726
// DeleteResponse returns an http.Response object for the deleted resource
712
727
func (s * ScalewayAPI ) DeleteResponse (resource string ) (* http.Response , error ) {
713
728
uri := fmt .Sprintf ("%s/%s" , strings .TrimRight (s .APIUrl , "/" ), resource )
714
- log . Debugf ( "DELETE %s" , uri )
729
+
715
730
req , err := http .NewRequest ("DELETE" , uri , nil )
716
731
if err != nil {
717
732
return nil , err
718
733
}
719
734
req .Header .Set ("X-Auth-Token" , s .Token )
720
735
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
+
721
744
return s .client .Do (req )
722
745
}
723
746
0 commit comments