Skip to content

Commit

Permalink
[chore] - ioutil.ReadFile is deprecated (#753)
Browse files Browse the repository at this point in the history
* Use os.ReadFile.

* Update imports.

* remove unused import.
  • Loading branch information
ahrav committed Aug 30, 2022
1 parent fa2d6b9 commit 37c4eea
Show file tree
Hide file tree
Showing 92 changed files with 208 additions and 213 deletions.
3 changes: 1 addition & 2 deletions hack/generate/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package main

import (
"fmt"
"io/ioutil"
"log"
"os"
"path/filepath"
Expand Down Expand Up @@ -77,7 +76,7 @@ func mustWriteTemplates(jobs []templateJob) {

// Write the files from templates.
for _, job := range jobs {
tmplBytes, err := ioutil.ReadFile(job.TemplatePath)
tmplBytes, err := os.ReadFile(job.TemplatePath)
if err != nil {
log.Fatal(err)
}
Expand Down
10 changes: 4 additions & 6 deletions pkg/detectors/abuseipdb/abuseipdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@ package abuseipdb

import (
"context"
"io/ioutil"

"io"
"net/http"
// "log"
"regexp"
"strings"

"net/http"

"github.com/trufflesecurity/trufflehog/v3/pkg/common"
"github.com/trufflesecurity/trufflehog/v3/pkg/detectors"
"github.com/trufflesecurity/trufflehog/v3/pkg/pb/detectorspb"
Expand Down Expand Up @@ -58,11 +56,11 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result
req.Header.Add("Key", resMatch)
res, err := client.Do(req)
if err == nil {
bodyBytes, err := ioutil.ReadAll(res.Body)
bodyBytes, err := io.ReadAll(res.Body)
if err == nil {
bodyString := string(bodyBytes)
validResponse := strings.Contains(bodyString, `ipAddress`)
//errCode := strings.Contains(bodyString, `AbuseIPDB APIv2 Server.`)
// errCode := strings.Contains(bodyString, `AbuseIPDB APIv2 Server.`)

defer res.Body.Close()
if res.StatusCode >= 200 && res.StatusCode < 300 {
Expand Down
8 changes: 3 additions & 5 deletions pkg/detectors/allsports/allsports.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@ package allsports

import (
"context"
"io/ioutil"

"io"
"net/http"
// "log"
"regexp"
"strings"

"net/http"

"github.com/trufflesecurity/trufflehog/v3/pkg/common"
"github.com/trufflesecurity/trufflehog/v3/pkg/detectors"
"github.com/trufflesecurity/trufflehog/v3/pkg/pb/detectorspb"
Expand Down Expand Up @@ -58,7 +56,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result
res, err := client.Do(req)
if err == nil {
defer res.Body.Close()
bodyBytes, err := ioutil.ReadAll(res.Body)
bodyBytes, err := io.ReadAll(res.Body)
if err != nil {
continue
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/detectors/amadeus/amadeus.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package amadeus

import (
"context"
"io/ioutil"
"io"
"net/http"
"regexp"
"strings"
Expand Down Expand Up @@ -66,7 +66,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result
res, err := client.Do(req)
if err == nil {
defer res.Body.Close()
bodyBytes, err := ioutil.ReadAll(res.Body)
bodyBytes, err := io.ReadAll(res.Body)
if err != nil {
continue
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/detectors/api2cart/api2cart.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"context"
"encoding/json"
"fmt"
"io/ioutil"
"io"
"net/http"
"regexp"
"strings"
Expand Down Expand Up @@ -57,7 +57,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result
res, err := client.Do(req)
if err == nil {
defer res.Body.Close()
body, errBody := ioutil.ReadAll(res.Body)
body, errBody := io.ReadAll(res.Body)

var result Response
if errBody == nil {
Expand Down
8 changes: 4 additions & 4 deletions pkg/detectors/appointedd/appointedd.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ package appointedd

import (
"context"
"io"
"net/http"
"regexp"
"strings"
"io/ioutil"


"github.com/trufflesecurity/trufflehog/v3/pkg/common"
"github.com/trufflesecurity/trufflehog/v3/pkg/detectors"
"github.com/trufflesecurity/trufflehog/v3/pkg/pb/detectorspb"
Expand All @@ -20,7 +20,7 @@ var _ detectors.Detector = (*Scanner)(nil)
var (
client = common.SaneHttpClient()

//Make sure that your group is surrounded in boundry characters such as below to reduce false positives
// Make sure that your group is surrounded in boundry characters such as below to reduce false positives
keyPat = regexp.MustCompile(detectors.PrefixRegex([]string{"appointedd"}) + `\b([a-zA-Z0-9=+]{88})`)
)

Expand Down Expand Up @@ -55,7 +55,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result
res, err := client.Do(req)
if err == nil {
defer res.Body.Close()
bodyBytes, err := ioutil.ReadAll(res.Body)
bodyBytes, err := io.ReadAll(res.Body)
if err != nil {
continue
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/detectors/apptivo/apptivo.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package apptivo
import (
"context"
"fmt"
"io/ioutil"
"io"
"net/http"
"regexp"
"strings"
Expand Down Expand Up @@ -63,7 +63,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result
}
res, err := client.Do(req)
if err == nil {
bodyBytes, err := ioutil.ReadAll(res.Body)
bodyBytes, err := io.ReadAll(res.Body)
if err != nil {
continue
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/detectors/audd/audd.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package audd
import (
"context"
"fmt"
"io/ioutil"
"io"
"net/http"
"regexp"
"strings"
Expand Down Expand Up @@ -55,7 +55,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result
}
res, err := client.Do(req)
if err == nil {
bodyBytes, err := ioutil.ReadAll(res.Body)
bodyBytes, err := io.ReadAll(res.Body)
if err == nil {
bodyString := string(bodyBytes)
validResponse := strings.Contains(bodyString, `"status":"success"`)
Expand Down
4 changes: 2 additions & 2 deletions pkg/detectors/auth0oauth/auth0oauth.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package auth0oauth

import (
"context"
"io/ioutil"
"io"
"net/http"
"net/url"
"regexp"
Expand Down Expand Up @@ -88,7 +88,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result
res, err := client.Do(req)
if err == nil {
defer res.Body.Close()
bodyBytes, err := ioutil.ReadAll(res.Body)
bodyBytes, err := io.ReadAll(res.Body)
if err != nil {
continue
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/detectors/autoklose/autoklose.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"context"
"encoding/json"
"fmt"
"io/ioutil"
"io"
"net/http"
"regexp"
"strings"
Expand Down Expand Up @@ -56,7 +56,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result
}
res, err := client.Do(req)
if err == nil {
bodyBytes, err := ioutil.ReadAll(res.Body)
bodyBytes, err := io.ReadAll(res.Body)
if err != nil {
continue
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/detectors/baseapiio/baseapiio.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package baseapiio
import (
"context"
"fmt"
"io/ioutil"
"io"
"net/http"
"regexp"
"strings"
Expand Down Expand Up @@ -57,7 +57,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result
res, err := client.Do(req)
if err == nil {
defer res.Body.Close()
bodyBytes, err := ioutil.ReadAll(res.Body)
bodyBytes, err := io.ReadAll(res.Body)
if err != nil {
continue
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/detectors/besttime/besttime.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package besttime

import (
"context"
"io/ioutil"
"io"
"net/http"
"regexp"
"strings"
Expand Down Expand Up @@ -55,7 +55,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result
res, err := client.Do(req)
if err == nil {
defer res.Body.Close()
bodyBytes, err := ioutil.ReadAll(res.Body)
bodyBytes, err := io.ReadAll(res.Body)
if err != nil {
continue
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/detectors/borgbase/borgbase.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package borgbase
import (
"context"
"fmt"
"io/ioutil"
"io"
"net/http"
"regexp"
"strings"
Expand Down Expand Up @@ -61,7 +61,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result
req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", resMatch))
res, err := client.Do(req)
if err == nil {
bodyBytes, err := ioutil.ReadAll(res.Body)
bodyBytes, err := io.ReadAll(res.Body)
if err == nil {
bodyString := string(bodyBytes)
validResponse := strings.Contains(bodyString, `"sshList":[]`)
Expand Down
8 changes: 4 additions & 4 deletions pkg/detectors/braintreepayments/braintreepayments.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package braintreepayments

import (
"context"
"io/ioutil"
"io"
"net/http"
"regexp"
"strings"
Expand All @@ -20,7 +20,7 @@ var _ detectors.Detector = (*Scanner)(nil)
var (
client = common.SaneHttpClient()

//Make sure that your group is surrounded in boundry characters such as below to reduce false positives
// Make sure that your group is surrounded in boundry characters such as below to reduce false positives
keyPat = regexp.MustCompile(detectors.PrefixRegex([]string{"braintree"}) + `\b([0-9a-f]{32})\b`)
idPat = regexp.MustCompile(detectors.PrefixRegex([]string{"braintree"}) + `\b([0-9a-z]{16})\b`)
)
Expand Down Expand Up @@ -67,7 +67,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result
req.SetBasicAuth(resIdMatch, resMatch)
res, err := client.Do(req)
if err == nil {
bodyBytes, err := ioutil.ReadAll(res.Body)
bodyBytes, err := io.ReadAll(res.Body)
if err != nil {
continue
}
Expand All @@ -79,7 +79,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result
if res.StatusCode >= 200 && res.StatusCode < 300 && validResponse {
s1.Verified = true
} else {
//This function will check false positives for common test words, but also it will make sure the key appears 'random' enough to be a real key
// This function will check false positives for common test words, but also it will make sure the key appears 'random' enough to be a real key
if detectors.IsKnownFalsePositive(resMatch, detectors.DefaultFalsePositives, true) {
continue
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/detectors/bulbul/bulbul.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package bulbul
import (
"context"
"fmt"
"io/ioutil"
"io"
"net/http"
"regexp"
"strings"
Expand Down Expand Up @@ -55,7 +55,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result
}
res, err := client.Do(req)
if err == nil {
bodyBytes, err := ioutil.ReadAll(res.Body)
bodyBytes, err := io.ReadAll(res.Body)

if err != nil {
continue
Expand Down
4 changes: 2 additions & 2 deletions pkg/detectors/cexio/cexio.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"encoding/hex"
"encoding/json"
"fmt"
"io/ioutil"
"io"
"net/http"
"net/url"
"regexp"
Expand Down Expand Up @@ -92,7 +92,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result
if err == nil {
defer res.Body.Close()

body, err := ioutil.ReadAll(res.Body)
body, err := io.ReadAll(res.Body)
if err != nil {
continue
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/detectors/coinlayer/coinlayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package coinlayer
import (
"context"
"fmt"
"io/ioutil"
"io"
"net/http"
"regexp"
"strings"
Expand Down Expand Up @@ -55,7 +55,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result
}
res, err := client.Do(req)
if err == nil {
bodyBytes, err := ioutil.ReadAll(res.Body)
bodyBytes, err := io.ReadAll(res.Body)
if err == nil {
bodyString := string(bodyBytes)
validResponse := strings.Contains(bodyString, `"success": true`) || strings.Contains(bodyString, `"info":"Access Restricted - Your current Subscription Plan does not support HTTPS Encryption."`)
Expand Down
4 changes: 2 additions & 2 deletions pkg/detectors/commodities/commodities.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package commodities

import (
"context"
"io/ioutil"
"io"
"net/http"
"regexp"
"strings"
Expand Down Expand Up @@ -56,7 +56,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result
}
res, err := client.Do(req)
if err == nil {
bodyBytes, err := ioutil.ReadAll(res.Body)
bodyBytes, err := io.ReadAll(res.Body)
if err != nil {
continue
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/detectors/convier/convier.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package convier
import (
"context"
"fmt"
"io/ioutil"
"io"
"net/http"
"regexp"
"strings"
Expand Down Expand Up @@ -59,7 +59,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result
req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", resMatch))
res, err := client.Do(req)
if err == nil {
bodyBytes, err := ioutil.ReadAll(res.Body)
bodyBytes, err := io.ReadAll(res.Body)
if err != nil {
continue
}
Expand Down
Loading

0 comments on commit 37c4eea

Please sign in to comment.