diff --git a/core/configuration.go b/core/configuration.go index 5237948..f834ffc 100644 --- a/core/configuration.go +++ b/core/configuration.go @@ -2,7 +2,7 @@ package core import ( "fmt" - "io/ioutil" + "io" "os" "reflect" "sync" @@ -29,7 +29,7 @@ func LoadConfiguration(path string) (*Configuration, error) { return configuration, fmt.Errorf("loading configuration: file opening: %s", err) } - bytes, _ := ioutil.ReadAll(file) + bytes, _ := io.ReadAll(file) var cc map[interface{}]interface{} diff --git a/core/rule_parser.go b/core/rule_parser.go index e6e4eb2..7038b3b 100644 --- a/core/rule_parser.go +++ b/core/rule_parser.go @@ -2,11 +2,12 @@ package core import ( "fmt" - "github.com/evilsocket/islazy/log" - "io/ioutil" + "os" "path/filepath" "regexp" + "github.com/evilsocket/islazy/log" + "github.com/alecthomas/participle" "github.com/alecthomas/participle/lexer" ) @@ -126,7 +127,7 @@ func (p *Parser) parseFile(filename string, deps []string) (*AST, error) { ast := &AST{} log.Debug("parsing %s", filename) - content, err := ioutil.ReadFile(filename) + content, err := os.ReadFile(filename) if err != nil { return nil, fmt.Errorf("parsing '%s': %s", filename, err) } diff --git a/feeders/web.go b/feeders/web.go index 85f758a..67fdf4f 100644 --- a/feeders/web.go +++ b/feeders/web.go @@ -5,7 +5,6 @@ import ( "encoding/json" "fmt" "io" - "io/ioutil" "net/http" "net/url" "strconv" @@ -136,7 +135,7 @@ func (f *Web) prepareRequest() (*http.Request, error) { } func (f *Web) getBodyAsString(r *http.Response) string { - body, err := ioutil.ReadAll(r.Body) + body, err := io.ReadAll(r.Body) if err != nil { return "" } diff --git a/filters/base_test.go b/filters/base_test.go index b4d64f4..d812f0f 100644 --- a/filters/base_test.go +++ b/filters/base_test.go @@ -2,7 +2,6 @@ package filters import ( "fmt" - "io/ioutil" "os" "path" "testing" @@ -84,7 +83,7 @@ func TestBase_Log(t *testing.T) { expected := fmt.Sprintf("[%s::%s] this is %s\n", b.rule, b.name, b.name) b.Log(msg) - dat, _ := ioutil.ReadFile(logfile) + dat, _ := os.ReadFile(logfile) if string(dat) != expected { t.Errorf("wrong error: expected=%#v had=%#v", expected, string(dat)) } @@ -155,7 +154,7 @@ func TestBase_Pipe(t *testing.T) { cbFilter: v.Callback, } b.Pipe(v.ExpectedMessage) - dat, _ := ioutil.ReadFile(logfile) + dat, _ := os.ReadFile(logfile) if string(dat) != v.ExpectedLog { t.Errorf("%s : wrong error: expected=%#v had=%#v", v.Name, v.ExpectedLog, string(dat)) } diff --git a/filters/file.go b/filters/file.go index e2c2aea..33e2548 100644 --- a/filters/file.go +++ b/filters/file.go @@ -1,7 +1,6 @@ package filters import ( - "io/ioutil" "os" "github.com/Matrix86/driplane/data" @@ -36,7 +35,7 @@ func (f *File) DoFilter(msg *data.Message) (bool, error) { // if the path exists and it's a file if stat, err := os.Stat(path); err == nil && !stat.IsDir() { log.Debug("path='%s' size=%d extra=%v", path, stat.Size(), msg.GetExtra()) - readData, err := ioutil.ReadFile(path) + readData, err := os.ReadFile(path) if err != nil { return true, err } diff --git a/filters/format.go b/filters/format.go index 144b3a2..48016f0 100644 --- a/filters/format.go +++ b/filters/format.go @@ -3,7 +3,7 @@ package filters import ( "fmt" html "html/template" - "io/ioutil" + "os" "path/filepath" text "text/template" @@ -66,7 +66,7 @@ func NewFormatFilter(p map[string]string) (Filter, error) { } else { fpath = filepath.Join(v, fpath) } - content, err := ioutil.ReadFile(fpath) + content, err := os.ReadFile(fpath) if err != nil { return nil, err } diff --git a/filters/http.go b/filters/http.go index e224935..13e3d82 100644 --- a/filters/http.go +++ b/filters/http.go @@ -6,9 +6,9 @@ import ( "encoding/json" "fmt" "io" - "io/ioutil" "net/http" "os" + //"net/http/httputil" "net/url" "strconv" @@ -222,7 +222,7 @@ func (f *HTTP) DoFilter(msg *data.Message) (bool, error) { } func (f *HTTP) readBody(r *http.Response) interface{} { - body, err := ioutil.ReadAll(r.Body) + body, err := io.ReadAll(r.Body) if err != nil { return "" } @@ -230,7 +230,7 @@ func (f *HTTP) readBody(r *http.Response) interface{} { } // OnEvent is called when an event occurs -func (f *HTTP) OnEvent(event *data.Event){} +func (f *HTTP) OnEvent(event *data.Event) {} // Set the name of the filter func init() { diff --git a/plugins/file.go b/plugins/file.go index f490547..67a934b 100644 --- a/plugins/file.go +++ b/plugins/file.go @@ -3,7 +3,6 @@ package plugins import ( "fmt" "io" - "io/ioutil" "os" ) @@ -26,7 +25,7 @@ type FileResponse struct { func (c *FilePackage) Read(fileName string) FileResponse { resp := FileResponse{} - resp.Binary, resp.Error = ioutil.ReadFile(fileName) + resp.Binary, resp.Error = os.ReadFile(fileName) resp.Status = resp.Error == nil resp.String = string(resp.Binary) @@ -36,7 +35,7 @@ func (c *FilePackage) Read(fileName string) FileResponse { func (c *FilePackage) Write(fileName string, data []byte) FileResponse { resp := FileResponse{} - resp.Error = ioutil.WriteFile(fileName, data, os.ModePerm) + resp.Error = os.WriteFile(fileName, data, os.ModePerm) resp.Status = resp.Error == nil return resp diff --git a/plugins/file_test.go b/plugins/file_test.go index e22882f..4eeb84b 100644 --- a/plugins/file_test.go +++ b/plugins/file_test.go @@ -1,7 +1,6 @@ package plugins import ( - "io/ioutil" "os" "path" "testing" @@ -274,7 +273,7 @@ func TestFilePackage_AppendString(t *testing.T) { t.Errorf("%s: wrong result: expected=%#v had=%#v", v.Name, v.ExpectedError, had.Error.Error()) } if v.ExpectedStatus { - content, err := ioutil.ReadFile(v.Filename) + content, err := os.ReadFile(v.Filename) if err != nil { t.Errorf("%s: cannot read the file '%s'", v.Name, v.Filename) } diff --git a/plugins/http.go b/plugins/http.go index 196e293..4e283e1 100644 --- a/plugins/http.go +++ b/plugins/http.go @@ -4,7 +4,6 @@ import ( "bytes" "fmt" "io" - "io/ioutil" "mime/multipart" "net/http" "net/url" @@ -88,7 +87,7 @@ func (c *HTTPPackage) Request(method string, uri string, headers interface{}, da } defer resp.Body.Close() - raw, err := ioutil.ReadAll(resp.Body) + raw, err := io.ReadAll(resp.Body) if err != nil { return HTTPResponse{Error: err, Status: false} } @@ -202,7 +201,7 @@ func (c *HTTPPackage) UploadFile(filename string, fieldname string, method strin } defer resp.Body.Close() - raw, err := ioutil.ReadAll(resp.Body) + raw, err := io.ReadAll(resp.Body) if err != nil { return HTTPResponse{Error: err, Status: false} } diff --git a/plugins/http_test.go b/plugins/http_test.go index 8187dfd..0acbe6d 100644 --- a/plugins/http_test.go +++ b/plugins/http_test.go @@ -4,7 +4,6 @@ import ( "bytes" "errors" "fmt" - "io/ioutil" "net/http" "net/http/httptest" "net/url" @@ -124,7 +123,7 @@ func TestHTTPPackage_DownloadFile(t *testing.T) { t.Errorf("%s: wrong error: expected=%#v had=%#v", v.Name, res.Error, v.ExpectedResponse.Error) } if v.ExpectedResponse.Status { - dat, _ := ioutil.ReadFile(v.Filepath) + dat, _ := os.ReadFile(v.Filepath) if string(dat) != msg { t.Errorf("%s : wrong file content: expected=%#v had=%#v", v.Name, msg, string(dat)) } @@ -184,7 +183,7 @@ func TestHTTPPackage_UploadFile(t *testing.T) { t.Errorf("%s: wrong error: expected=%#v had=%#v", v.Name, v.ExpectedResponse.Error, res.Error) } if v.ExpectedResponse.Status { - dat, _ := ioutil.ReadFile(v.Filepath) + dat, _ := os.ReadFile(v.Filepath) if string(dat) != msg { t.Errorf("%s : wrong file content: expected=%#v had=%#v", v.Name, msg, string(dat)) } diff --git a/plugins/log_test.go b/plugins/log_test.go index 7a99260..37bbcf1 100644 --- a/plugins/log_test.go +++ b/plugins/log_test.go @@ -2,7 +2,6 @@ package plugins import ( "fmt" - "io/ioutil" "os" "path" "testing" @@ -25,7 +24,7 @@ func TestLogPackage_Debug(t *testing.T) { expected := fmt.Sprintf("%s\n", message) l.Debug("%s", message) - dat, _ := ioutil.ReadFile(logfile) + dat, _ := os.ReadFile(logfile) if string(dat) != expected { t.Errorf("wrong string: expected=%#v had=%#v", expected, string(dat)) } @@ -45,13 +44,12 @@ func TestLogPackage_Info(t *testing.T) { expected := fmt.Sprintf("%s\n", message) l.Info("%s", message) - dat, _ := ioutil.ReadFile(logfile) + dat, _ := os.ReadFile(logfile) if string(dat) != expected { t.Errorf("wrong string: expected=%#v had=%#v", expected, string(dat)) } } - func TestLogPackage_Error(t *testing.T) { l := GetLog() @@ -67,8 +65,8 @@ func TestLogPackage_Error(t *testing.T) { expected := fmt.Sprintf("%s\n", message) l.Error("%s", message) - dat, _ := ioutil.ReadFile(logfile) + dat, _ := os.ReadFile(logfile) if string(dat) != expected { t.Errorf("wrong string: expected=%#v had=%#v", expected, string(dat)) } -} \ No newline at end of file +} diff --git a/utils/cookie.go b/utils/cookie.go index e2b26cb..c305168 100644 --- a/utils/cookie.go +++ b/utils/cookie.go @@ -2,7 +2,7 @@ package utils import ( "encoding/json" - "io/ioutil" + "io" "net/http" "os" "time" @@ -33,7 +33,7 @@ func ParseCookieFile(filename string) ([]*http.Cookie, error) { } defer jsonFile.Close() - byteValue, _ := ioutil.ReadAll(jsonFile) + byteValue, _ := io.ReadAll(jsonFile) err = json.Unmarshal(byteValue, &cookies) if err != nil { return nil, err @@ -45,15 +45,15 @@ func ParseCookieFile(filename string) ([]*http.Cookie, error) { nsecs := int64((c.ExpirationDate - float64(secs)) * 1e9) httpCookies[i] = &http.Cookie{ - Name: c.Name, - Value: c.Value, - Path: c.Path, - Domain: c.Domain, - Expires: time.Unix(secs, nsecs), - Secure: c.Secure, - HttpOnly: c.HTTPOnly, + Name: c.Name, + Value: c.Value, + Path: c.Path, + Domain: c.Domain, + Expires: time.Unix(secs, nsecs), + Secure: c.Secure, + HttpOnly: c.HTTPOnly, } } return httpCookies, nil -} \ No newline at end of file +} diff --git a/utils/misc_test.go b/utils/misc_test.go index c469efb..8be93c7 100644 --- a/utils/misc_test.go +++ b/utils/misc_test.go @@ -1,7 +1,6 @@ package utils import ( - "io/ioutil" "os" "path" "testing" @@ -18,7 +17,7 @@ func TestIsFlagPassed(t *testing.T) { } func TestFileExists(t *testing.T) { - file, err := ioutil.TempFile(os.TempDir(), "prefix") + file, err := os.CreateTemp(os.TempDir(), "prefix") if err != nil { t.Errorf("cannot create a temporary file") }