Skip to content

Commit 1b4d37d

Browse files
committed
Merge pull request #165 from QuentinPerez/little_review
little review
2 parents 0b0f6d8 + 93d2f45 commit 1b4d37d

File tree

6 files changed

+23
-6
lines changed

6 files changed

+23
-6
lines changed

pkg/api/api.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -637,12 +637,14 @@ func (s *ScalewayAPI) GetResponse(resource string) (*http.Response, error) {
637637
req.Header.Set("Content-Type", "application/json")
638638

639639
curl, err := http2curl.GetCurlCommand(req)
640+
if err != nil {
641+
return nil, err
642+
}
640643
if os.Getenv("SCW_SENSITIVE") != "1" {
641644
log.Debug(s.HideAPICredentials(curl.String()))
642645
} else {
643646
log.Debug(curl.String())
644647
}
645-
646648
return s.client.Do(req)
647649
}
648650

@@ -663,6 +665,9 @@ func (s *ScalewayAPI) PostResponse(resource string, data interface{}) (*http.Res
663665
req.Header.Set("Content-Type", "application/json")
664666

665667
curl, err := http2curl.GetCurlCommand(req)
668+
if err != nil {
669+
return nil, err
670+
}
666671
if os.Getenv("SCW_SENSITIVE") != "1" {
667672
log.Debug(s.HideAPICredentials(curl.String()))
668673
} else {
@@ -689,6 +694,9 @@ func (s *ScalewayAPI) PatchResponse(resource string, data interface{}) (*http.Re
689694
req.Header.Set("Content-Type", "application/json")
690695

691696
curl, err := http2curl.GetCurlCommand(req)
697+
if err != nil {
698+
return nil, err
699+
}
692700
if os.Getenv("SCW_SENSITIVE") != "1" {
693701
log.Debug(s.HideAPICredentials(curl.String()))
694702
} else {
@@ -715,6 +723,9 @@ func (s *ScalewayAPI) PutResponse(resource string, data interface{}) (*http.Resp
715723
req.Header.Set("Content-Type", "application/json")
716724

717725
curl, err := http2curl.GetCurlCommand(req)
726+
if err != nil {
727+
return nil, err
728+
}
718729
if os.Getenv("SCW_SENSITIVE") != "1" {
719730
log.Debug(s.HideAPICredentials(curl.String()))
720731
} else {
@@ -736,6 +747,9 @@ func (s *ScalewayAPI) DeleteResponse(resource string) (*http.Response, error) {
736747
req.Header.Set("Content-Type", "application/json")
737748

738749
curl, err := http2curl.GetCurlCommand(req)
750+
if err != nil {
751+
return nil, err
752+
}
739753
if os.Getenv("SCW_SENSITIVE") != "1" {
740754
log.Debug(s.HideAPICredentials(curl.String()))
741755
} else {

pkg/commands/commit.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,6 @@ func RunCommit(ctx CommandContext, args CommitArgs) error {
3333
if err != nil {
3434
return fmt.Errorf("Cannot create snapshot: %v", err)
3535
}
36-
fmt.Println(snapshot)
36+
fmt.Fprintln(ctx.Stdout, snapshot)
3737
return nil
3838
}

pkg/commands/events.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ func RunEvents(ctx CommandContext, args EventsArgs) error {
3636
terminatedAt = units.HumanDuration(time.Now().UTC().Sub(terminatedAtTime))
3737
}
3838

39-
fmt.Printf("%s %s: %s (%s %d) %s\n", startedAt, event.HrefFrom, event.Description, event.Status, event.Progress, terminatedAt)
39+
fmt.Fprintf(ctx.Stdout, "%s %s: %s (%s %d) %s\n", startedAt, event.HrefFrom, event.Description, event.Status, event.Progress, terminatedAt)
4040
}
4141
return nil
4242
}

pkg/commands/info.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ func RunInfo(ctx CommandContext, args InfoArgs) error {
5555
if err != nil {
5656
return err
5757
} else {
58-
fmt.Fprintf(ctx.Stdout, " [%d] %s", id, fingerprint)
58+
fmt.Fprintf(ctx.Stdout, " [%d] %s\n", id, fingerprint)
5959
}
6060
}
6161
}

pkg/commands/login.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,13 +92,14 @@ func getToken(connect api.ScalewayConnect) (string, error) {
9292
if err != nil {
9393
return "", fmt.Errorf("unable to connect %v", err)
9494
}
95+
defer resp.Body.Close()
96+
9597
// Succeed POST code
9698
if resp.StatusCode != 201 {
9799
return "", fmt.Errorf("[%d] maybe your email or your password is not valid", resp.StatusCode)
98100
}
99101
var data api.ScalewayConnectResponse
100102

101-
defer resp.Body.Close()
102103
decoder := json.NewDecoder(resp.Body)
103104
err = decoder.Decode(&data)
104105
if err != nil {

pkg/commands/top.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ func RunTop(ctx CommandContext, args TopArgs) error {
4545
sshCommand := utils.NewSSHExecCmd(server.PublicAddress.IP, server.PrivateIP, true, []string{command}, gateway)
4646
logrus.Debugf("Executing: %s", sshCommand)
4747
out, err := exec.Command("ssh", sshCommand.Slice()[1:]...).CombinedOutput()
48-
fmt.Printf("%s", out)
48+
if err != nil {
49+
fmt.Fprintf(ctx.Stdout, "%s", out)
50+
}
4951
return err
5052
}

0 commit comments

Comments
 (0)