Skip to content

Commit

Permalink
Fix hoverctl code issue
Browse files Browse the repository at this point in the history
  • Loading branch information
tommysitu committed Feb 2, 2025
1 parent 8606ca2 commit a56f8c6
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 24 deletions.
2 changes: 1 addition & 1 deletion hoverctl/cmd/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func askForInput(value string, sensitive bool) string {
for {
fmt.Printf(value + ": ")
if sensitive {
responseBytes, err := terminal.ReadPassword(int(syscall.Stdin))
responseBytes, err := terminal.ReadPassword(syscall.Stdin)
handleIfError(err)
fmt.Println("")

Expand Down
4 changes: 2 additions & 2 deletions hoverctl/configuration/config.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package configuration

import (
"io/ioutil"
"os"
"path/filepath"

log "github.com/sirupsen/logrus"
Expand Down Expand Up @@ -113,7 +113,7 @@ func (c *Config) WriteToFile(hoverflyDirectory HoverflyDirectory) error {

configPath := filepath.Join(hoverflyDirectory.Path, "config.yaml")

err = ioutil.WriteFile(configPath, data, 0644)
err = os.WriteFile(configPath, data, 0644)

if err != nil {
log.Debug(err.Error())
Expand Down
3 changes: 1 addition & 2 deletions hoverctl/configuration/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package configuration
import (
"bytes"
"github.com/spf13/viper"
"io/ioutil"
"os"
"testing"

Expand Down Expand Up @@ -152,7 +151,7 @@ func Test_Config_WriteToFile_WritesTheConfigObjectToAFileInAYamlFormat(t *testin

Expect(err).To(BeNil())

data, _ := ioutil.ReadFile(hoverflyDirectory.Path + "/config.yaml")
data, _ := os.ReadFile(hoverflyDirectory.Path + "/config.yaml")
_ = os.Remove(hoverflyDirectory.Path + "/config.yaml")

Expect(string(data)).To(ContainSubstring(`targets:`))
Expand Down
8 changes: 4 additions & 4 deletions hoverctl/configuration/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package configuration

import (
"errors"
"io/ioutil"
"io"
"os"
"path/filepath"

Expand All @@ -23,14 +23,14 @@ func WriteFile(filePath string, data []byte) error {
return err
}

return ioutil.WriteFile(basePath+"/"+fileName, data, 0644)
return os.WriteFile(basePath+"/"+fileName, data, 0644)
}

func ReadFile(filePath string) ([]byte, error) {
if strings.HasPrefix(filePath, "http://") || strings.HasPrefix(filePath, "https://") {
return DownloadFile(filePath)
}
data, err := ioutil.ReadFile(filePath)
data, err := os.ReadFile(filePath)
if err != nil {
return nil, errors.New("File not found: " + filePath)
}
Expand All @@ -47,7 +47,7 @@ func DownloadFile(filePath string) ([]byte, error) {

defer response.Body.Close()

body, err := ioutil.ReadAll(response.Body)
body, err := io.ReadAll(response.Body)
if err != nil {
log.Info(err.Error())
return nil, errors.New("Could not download simulation")
Expand Down
5 changes: 2 additions & 3 deletions hoverctl/wrapper/current_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@ package wrapper

import (
"encoding/json"
"io/ioutil"

"github.com/SpectoLabs/hoverfly/core/handlers/v2"
"github.com/SpectoLabs/hoverfly/hoverctl/configuration"
"io"
)

func GetCurrentState(target configuration.Target) (map[string]string, error) {
Expand All @@ -18,7 +17,7 @@ func GetCurrentState(target configuration.Target) (map[string]string, error) {

defer res.Body.Close()

responseBody, err := ioutil.ReadAll(res.Body)
responseBody, err := io.ReadAll(res.Body)

if err != nil {
return nil, err
Expand Down
4 changes: 2 additions & 2 deletions hoverctl/wrapper/diffs.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package wrapper

import (
"encoding/json"
"io/ioutil"
"io"

"github.com/SpectoLabs/hoverfly/core/handlers/v2"
"github.com/SpectoLabs/hoverfly/hoverctl/configuration"
Expand All @@ -18,7 +18,7 @@ func GetAllDiffs(target configuration.Target) ([]v2.ResponseDiffForRequestView,

defer res.Body.Close()

responseBody, err := ioutil.ReadAll(res.Body)
responseBody, err := io.ReadAll(res.Body)

if err != nil {
return nil, err
Expand Down
8 changes: 4 additions & 4 deletions hoverctl/wrapper/hoverfly.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"io"
"net"
"net/http"
"os/exec"
Expand Down Expand Up @@ -72,7 +72,7 @@ type ErrorSchema struct {
}

func UnmarshalToInterface(response *http.Response, v interface{}) error {
body, err := ioutil.ReadAll(response.Body)
body, err := io.ReadAll(response.Body)
if err != nil {
return err
}
Expand Down Expand Up @@ -117,7 +117,7 @@ func Login(target configuration.Target, username, password string) (string, erro
return "", fmt.Errorf("Incorrect username or password")
}

body, err := ioutil.ReadAll(response.Body)
body, err := io.ReadAll(response.Body)
if err != nil {
return "", fmt.Errorf("There was an error when logging in")
}
Expand Down Expand Up @@ -308,7 +308,7 @@ func checkPorts(ports ...int) error {
func handleResponseError(response *http.Response, errorMessage string) error {
if response.StatusCode != 200 {
defer response.Body.Close()
responseError, _ := ioutil.ReadAll(response.Body)
responseError, _ := io.ReadAll(response.Body)

errSchema := &ErrorSchema{}

Expand Down
4 changes: 2 additions & 2 deletions hoverctl/wrapper/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package wrapper
import (
"encoding/json"
"fmt"
"io/ioutil"
"io"
"strings"
"time"

Expand Down Expand Up @@ -37,7 +37,7 @@ func GetLogs(target configuration.Target, format string, filterTime *time.Time)
return nil, err
}

responseBody, _ := ioutil.ReadAll(response.Body)
responseBody, _ := io.ReadAll(response.Body)
if format == "json" {
var logsView v2.LogsView

Expand Down
7 changes: 3 additions & 4 deletions hoverctl/wrapper/simulation.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ package wrapper

import (
"encoding/json"
"io/ioutil"

"fmt"
"io"
"net/url"

"github.com/SpectoLabs/hoverfly/core/handlers/v2"
Expand Down Expand Up @@ -44,7 +43,7 @@ func ImportSimulation(target configuration.Target, simulationData string) error
return err
}

responseBytes, _ := ioutil.ReadAll(response.Body)
responseBytes, _ := io.ReadAll(response.Body)

result := &v2.SimulationImportResult{}
json.Unmarshal(responseBytes, result)
Expand All @@ -68,7 +67,7 @@ func AddSimulation(target configuration.Target, simulationData string) error {
return err
}

responseBytes, _ := ioutil.ReadAll(response.Body)
responseBytes, _ := io.ReadAll(response.Body)

result := &v2.SimulationImportResult{}
json.Unmarshal(responseBytes, result)
Expand Down

0 comments on commit a56f8c6

Please sign in to comment.