Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changing ioutil.ReadAll to io.ReadAll #394

Merged
merged 1 commit into from
Jan 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions admin/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"crypto/rand"
"encoding/json"
"fmt"
"io/ioutil"
"io"
"log"
"os"
"strings"
Expand Down Expand Up @@ -106,7 +106,7 @@ func loadOsqueryTables(file string) ([]types.OsqueryTable, error) {
log.Fatalf("Failed to close tables file %v", err)
}
}()
byteValue, _ := ioutil.ReadAll(jsonFile)
byteValue, _ := io.ReadAll(jsonFile)
if err := json.Unmarshal(byteValue, &tables); err != nil {
return tables, err
}
Expand Down
2 changes: 1 addition & 1 deletion cli/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ func (api *OsctrlAPI) ReqGeneric(reqType string, url string, body io.Reader) ([]
}
}()
// Read body
bodyBytes, err := ioutil.ReadAll(resp.Body)
bodyBytes, err := io.ReadAll(resp.Body)
if err != nil {
return []byte{}, fmt.Errorf("can not read response - %v", err)
}
Expand Down
27 changes: 14 additions & 13 deletions tls/handlers/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package handlers
import (
"compress/gzip"
"encoding/json"
"io/ioutil"
"io"
"log"
"net/http"
"strings"
Expand Down Expand Up @@ -246,7 +246,7 @@ func (h *HandlersTLS) EnrollHandler(w http.ResponseWriter, r *http.Request) {
utils.DebugHTTPDump(r, (*h.EnvsMap)[env.Name].DebugHTTP, true)
// Decode read POST body
var t types.EnrollRequest
body, err := ioutil.ReadAll(r.Body)
body, err := io.ReadAll(r.Body)
if err != nil {
h.Inc(metricEnrollErr)
log.Printf("error reading POST body %v", err)
Expand Down Expand Up @@ -327,7 +327,7 @@ func (h *HandlersTLS) ConfigHandler(w http.ResponseWriter, r *http.Request) {
utils.DebugHTTPDump(r, (*h.EnvsMap)[env.Name].DebugHTTP, true)
// Decode read POST body
var t types.ConfigRequest
body, err := ioutil.ReadAll(r.Body)
body, err := io.ReadAll(r.Body)
if err != nil {
h.Inc(metricConfigErr)
log.Printf("error reading POST body %v", err)
Expand Down Expand Up @@ -408,7 +408,7 @@ func (h *HandlersTLS) LogHandler(w http.ResponseWriter, r *http.Request) {
utils.DebugHTTPDump(r, (*h.EnvsMap)[env.Name].DebugHTTP, true)
// Extract POST body and decode JSON
var t types.LogRequest
body, err := ioutil.ReadAll(r.Body)
body, err := io.ReadAll(r.Body)
if err != nil {
h.Inc(metricLogErr)
log.Printf("error reading POST body %v", err)
Expand All @@ -427,7 +427,8 @@ func (h *HandlersTLS) LogHandler(w http.ResponseWriter, r *http.Request) {
}()
var nodeInvalid bool
// Check if provided node_key is valid and if so, update node
node, err := h.Nodes.GetByKey(t.NodeKey); if err == nil {
node, err := h.Nodes.GetByKey(t.NodeKey)
if err == nil {
nodeInvalid = false
// Record ingested data
if err := h.Ingested.IngestLog(env.ID, node.ID, len(body), t.LogType); err != nil {
Expand Down Expand Up @@ -472,7 +473,7 @@ func (h *HandlersTLS) QueryReadHandler(w http.ResponseWriter, r *http.Request) {
utils.DebugHTTPDump(r, (*h.EnvsMap)[env.Name].DebugHTTP, true)
// Decode read POST body
var t types.QueryReadRequest
body, err := ioutil.ReadAll(r.Body)
body, err := io.ReadAll(r.Body)
if err != nil {
h.Inc(metricReadErr)
log.Printf("error reading POST body %v", err)
Expand Down Expand Up @@ -552,7 +553,7 @@ func (h *HandlersTLS) QueryWriteHandler(w http.ResponseWriter, r *http.Request)
utils.DebugHTTPDump(r, (*h.EnvsMap)[env.Name].DebugHTTP, true)
// Decode read POST body
var t types.QueryWriteRequest
body, err := ioutil.ReadAll(r.Body)
body, err := io.ReadAll(r.Body)
if err != nil {
h.Inc(metricWriteErr)
log.Printf("error reading POST body %v", err)
Expand Down Expand Up @@ -790,7 +791,7 @@ func (h *HandlersTLS) CarveInitHandler(w http.ResponseWriter, r *http.Request) {
utils.DebugHTTPDump(r, (*h.EnvsMap)[env.Name].DebugHTTP, true)
// Decode read POST body
var t types.CarveInitRequest
body, err := ioutil.ReadAll(r.Body)
body, err := io.ReadAll(r.Body)
if err != nil {
h.Inc(metricInitErr)
log.Printf("error reading POST body %v", err)
Expand Down Expand Up @@ -862,7 +863,7 @@ func (h *HandlersTLS) CarveBlockHandler(w http.ResponseWriter, r *http.Request)
utils.DebugHTTPDump(r, (*h.EnvsMap)[env.Name].DebugHTTP, true)
// Decode read POST body
var t types.CarveBlockRequest
body, err := ioutil.ReadAll(r.Body)
body, err := io.ReadAll(r.Body)
if err != nil {
h.Inc(metricBlockErr)
log.Printf("error reading POST body %v", err)
Expand Down Expand Up @@ -923,7 +924,7 @@ func (h *HandlersTLS) FlagsHandler(w http.ResponseWriter, r *http.Request) {
utils.DebugHTTPDump(r, (*h.EnvsMap)[env.Name].DebugHTTP, true)
// Decode read POST body
var t types.FlagsRequest
body, err := ioutil.ReadAll(r.Body)
body, err := io.ReadAll(r.Body)
if err != nil {
h.Inc(metricFlagsErr)
log.Printf("error reading POST body %v", err)
Expand Down Expand Up @@ -979,7 +980,7 @@ func (h *HandlersTLS) CertHandler(w http.ResponseWriter, r *http.Request) {
utils.DebugHTTPDump(r, (*h.EnvsMap)[env.Name].DebugHTTP, true)
// Decode read POST body
var t types.CertRequest
body, err := ioutil.ReadAll(r.Body)
body, err := io.ReadAll(r.Body)
if err != nil {
h.Inc(metricCertErr)
log.Printf("error reading POST body %v", err)
Expand Down Expand Up @@ -1029,7 +1030,7 @@ func (h *HandlersTLS) VerifyHandler(w http.ResponseWriter, r *http.Request) {
utils.DebugHTTPDump(r, (*h.EnvsMap)[env.Name].DebugHTTP, true)
// Decode read POST body
var t types.VerifyRequest
body, err := ioutil.ReadAll(r.Body)
body, err := io.ReadAll(r.Body)
if err != nil {
h.Inc(metricVerifyErr)
log.Printf("error reading POST body %v", err)
Expand Down Expand Up @@ -1118,7 +1119,7 @@ func (h *HandlersTLS) ScriptHandler(w http.ResponseWriter, r *http.Request) {
utils.DebugHTTPDump(r, (*h.EnvsMap)[env.Name].DebugHTTP, true)
// Decode read POST body
var t types.ScriptRequest
body, err := ioutil.ReadAll(r.Body)
body, err := io.ReadAll(r.Body)
if err != nil {
h.Inc(metricScriptErr)
log.Printf("error reading POST body %v", err)
Expand Down
3 changes: 1 addition & 2 deletions utils/http-utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"encoding/json"
"fmt"
"io"
"io/ioutil"
"log"
"net/http"
"net/http/httputil"
Expand Down Expand Up @@ -79,7 +78,7 @@ func SendRequest(reqType, reqURL string, params io.Reader, headers map[string]st
}
}()

bodyBytes, err := ioutil.ReadAll(resp.Body)
bodyBytes, err := io.ReadAll(resp.Body)
if err != nil {
return 0, []byte("Can not read response"), err
}
Expand Down
Loading