Skip to content

minor fixes and linting #180

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion checks_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ func (c cond) RegistryKey() (bool, error) {
registryArgs := regexp.MustCompile(`\\+`).Split(c.Key, -1)
if len(registryArgs) < 2 {
fail("Invalid key for RegistryKey. Did you supply 'key'?")
return false, errors.New("invalid registry key path: " + c.Key)
return false, errors.New("Invalid registry key path: " + c.Key)
}
registryHiveText := registryArgs[0]
keyPath := fmt.Sprintf(strings.Join(registryArgs[1:len(registryArgs)-1], `\`))
Expand Down
3 changes: 1 addition & 2 deletions checks_windows_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package main

import (
"io/ioutil"
"os"
"testing"

Expand All @@ -12,7 +11,7 @@ import (

func TestPermissionIs(t *testing.T) {
filePath := "misc/tests/permTest.txt"
ioutil.WriteFile(filePath, []byte("testContent"), os.ModePerm)
os.WriteFile(filePath, []byte("testContent"), os.ModePerm)
defer os.Remove(filePath)

c := cond{
Expand Down
5 changes: 1 addition & 4 deletions output.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,7 @@ func ask(p ...interface{}) bool {
fmt.Print(toPrint + " [Y/n]: ")
var resp string
fmt.Scanln(&resp)
if strings.ToLower(strings.TrimSpace(resp)) == "n" {
return false
}
return true
return !(strings.ToLower(strings.TrimSpace(resp)) == "n")
}

func pass(p ...interface{}) {
Expand Down
4 changes: 2 additions & 2 deletions release_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ func installService() {
Add-MpPreference -ExclusionPath "C:\aeacus\"
`
shellCommand(addExclusions)

}

// cleanUp clears out sensitive files left behind by image developers or the
Expand All @@ -152,7 +152,7 @@ func cleanUp() {
info("Emptying recycle bin...")
shellCommand("Clear-RecycleBin -Force")
info("Clearing recently used...")
shellCommand("Remove-Item -Force '${env:USERPROFILE}\\AppData\\Roaming\\Microsoft\\Windows\\Recent‌​*.lnk'")
shellCommand("Remove-Item -Force \"${env:USERPROFILE}\\AppData\\Roaming\\Microsoft\\Windows\\Recent\\*.lnk\"")
info("Clearing run.exe command history...")
clearRunScript := `$path = "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\RunMRU"
$arr = (Get-Item -Path $path).Property
Expand Down
4 changes: 2 additions & 2 deletions remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"io"
"math"
"net/http"
"net/url"
Expand Down Expand Up @@ -177,7 +177,7 @@ func checkServer() {
conn.ServerStatus = FAIL
} else {
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
body, err := io.ReadAll(resp.Body)
if err != nil {
fail("Error reading Status body.")
conn.ServerColor = RED
Expand Down
3 changes: 1 addition & 2 deletions shell_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,7 @@ func shellSocket() {
continue
}
} else {
select {
case <-ticker.C:
for range ticker.C {
if disconnected {
readTeamID()
curTeamID := string(teamID)
Expand Down
5 changes: 2 additions & 3 deletions utility.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package main

import (
"errors"
"io/ioutil"
"os"
"runtime"
"strings"
Expand Down Expand Up @@ -66,10 +65,10 @@ func timeCheck() bool {
return false
}

// writeFile wraps ioutil's WriteFile function, and prints
// writeFile wraps os's WriteFile function, and prints
// the error the screen if one occurs.
func writeFile(fileName, fileContent string) {
err := ioutil.WriteFile(fileName, []byte(fileContent), 0o644)
err := os.WriteFile(fileName, []byte(fileContent), 0o644)
if err != nil {
fail("Error writing file: " + err.Error())
}
Expand Down
5 changes: 2 additions & 3 deletions utility_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package main
import (
"crypto/md5"
"io"
"io/ioutil"
"os"
"os/exec"
"os/user"
Expand All @@ -12,7 +11,7 @@ import (

// readFile (Linux) wraps ioutil's ReadFile function.
func readFile(fileName string) (string, error) {
fileContent, err := ioutil.ReadFile(fileName)
fileContent, err := os.ReadFile(fileName)
return string(fileContent), err
}

Expand Down Expand Up @@ -108,6 +107,6 @@ func adminCheck() bool {
return true
}

func getInfo(infoType string) {
func getInfo(_ string) {
warn("Info gathering is not supported for Linux-- there's always a better, easier command-line tool.")
}
5 changes: 3 additions & 2 deletions utility_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ package main

import (
"bytes"
"github.com/DataDog/datadog-agent/pkg/util/winutil"
"io/ioutil"
"os"
"os/exec"
"strings"
"unsafe"

"github.com/DataDog/datadog-agent/pkg/util/winutil"

"github.com/gen2brain/beeep"
wapi "github.com/iamacarpet/go-win64api"
"github.com/iamacarpet/go-win64api/shared"
Expand All @@ -26,7 +27,7 @@ var (
// readFile (Windows) uses ioutil's ReadFile function and passes the returned
// byte sequence to decodeString.
func readFile(filename string) (string, error) {
raw, err := ioutil.ReadFile(filename)
raw, err := os.ReadFile(filename)
if err != nil {
return "", err
}
Expand Down