Skip to content

Commit

Permalink
*: fix errcheck warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
sohankunkerkar committed Dec 11, 2020
1 parent c547898 commit 6ed3271
Show file tree
Hide file tree
Showing 10 changed files with 46 additions and 33 deletions.
4 changes: 3 additions & 1 deletion internal/exec/stages/disks/luks.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,9 @@ func (s *stage) createLuks(config types.Config) error {
var ignitionCreatedKeyFile bool
// create keyfile inside of tmpfs, it will be copied to the
// sysroot by the files stage
os.MkdirAll(distro.LuksInitramfsKeyFilePath(), 0700)
if err := os.MkdirAll(distro.LuksInitramfsKeyFilePath(), 0700); err != nil {
return fmt.Errorf("creating directory for keyfile: %v", err)
}
keyFilePath := filepath.Join(distro.LuksInitramfsKeyFilePath(), luks.Name)
devAlias := execUtil.DeviceAlias(*luks.Device)
if util.NilOrEmpty(luks.KeyFile.Source) {
Expand Down
4 changes: 3 additions & 1 deletion internal/exec/stages/disks/partitions.go
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,9 @@ func (s stage) partitionDisk(dev types.Disk, devAlias string) error {
op := sgdisk.Begin(s.Logger, devAlias)
s.Logger.Info("wiping partition table requested on %q", devAlias)
op.WipeTable(true)
op.Commit()
if err := op.Commit(); err != nil {
return err
}
}

// Ensure all partitions with number 0 are last
Expand Down
2 changes: 1 addition & 1 deletion internal/exec/util/passwd.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ func (u Util) AuthorizeSSHKeys(c types.PasswdUser) error {
if err != nil {
return fmt.Errorf("failed to set SSH key: %v", err)
}
journal.Send(fmt.Sprintf("wrote ssh authorized keys file for user: %s", c.Name), journal.PriInfo, map[string]string{
_ = journal.Send(fmt.Sprintf("wrote ssh authorized keys file for user: %s", c.Name), journal.PriInfo, map[string]string{
"IGNITION_USER_NAME": c.Name,
"IGNITION_PATH": path,
"MESSAGE_ID": ignitionSSHAuthorizedkeysMessageID,
Expand Down
5 changes: 4 additions & 1 deletion internal/exec/util/user_group_lookup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,10 @@ func TestUserLookup(t *testing.T) {

// perform a user lookup to ensure libnss_files.so is loaded
// note this assumes /etc/nsswitch.conf invokes files.
user.Lookup("root")
_, err := user.Lookup("root")
if err != nil {
t.Fatalf("user lookup failed: %v", err)
}

td, err := tempBase()
if err != nil {
Expand Down
6 changes: 4 additions & 2 deletions tests/filesystem.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ func setupDisk(ctx context.Context, disk *types.Disk, diskIndex int, imageSize i
loopdev := disk.Device
defer func() {
if err != nil {
destroyDevice(loopdev)
_ = destroyDevice(loopdev)
}
}()

Expand Down Expand Up @@ -470,7 +470,9 @@ func createFilesFromSlice(basedir string, files []types.File) error {
}
writer.Flush()
}
os.Chown(filepath.Join(basedir, file.Directory, file.Name), file.User, file.Group)
if err := os.Chown(filepath.Join(basedir, file.Directory, file.Name), file.User, file.Group); err != nil {
return err
}
}
return nil
}
Expand Down
4 changes: 2 additions & 2 deletions tests/negative/security/tls.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,10 @@ var (
}`)

customCAServer = httptest.NewUnstartedServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Write(customCAServerFile)
_, _ = w.Write(customCAServerFile)
}))
customCAServer2 = httptest.NewUnstartedServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Write(customCAServerFile2)
_, _ = w.Write(customCAServerFile2)
}))
)

Expand Down
6 changes: 3 additions & 3 deletions tests/negative/timeouts/timeouts.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ var (
time.Sleep(time.Second * 2)
// Give a config that merges ourselves and sets the timeouts to 1
// second (less than we wait!)
w.Write([]byte(fmt.Sprintf(`{
_, _ = w.Write([]byte(fmt.Sprintf(`{
"ignition": {
"version": "$version",
"config": {
Expand Down Expand Up @@ -161,7 +161,7 @@ func AppendNoneThenLowerHTTPTimeouts() types.Test {
time.Sleep(time.Second * 2)
// Give a config that merges ourselves and sets the timeouts to 1
// second (less than we wait!)
w.Write([]byte(`{
_, _ = w.Write([]byte(`{
"ignition": {
"version": "$version"
}
Expand All @@ -171,7 +171,7 @@ func AppendNoneThenLowerHTTPTimeouts() types.Test {
configNoDelayServer = httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
// Give a config that merges ourselves and sets the timeouts to 1
// second (less than we wait!)
w.Write([]byte(fmt.Sprintf(`{
_, _ = w.Write([]byte(fmt.Sprintf(`{
"ignition":
"version": "$version",
"config": {
Expand Down
2 changes: 1 addition & 1 deletion tests/positive/proxy/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (

var (
proxyServer = httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte(ignConfig))
_, _ = w.Write([]byte(ignConfig))
}))

mockConfigURL = "http://www.fake.tld"
Expand Down
4 changes: 2 additions & 2 deletions tests/positive/security/tls.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,10 @@ var (
}`)

customCAServer = httptest.NewUnstartedServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Write(customCAServerFile)
_, _ = w.Write(customCAServerFile)
}))
customCAServer2 = httptest.NewUnstartedServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Write(customCAServerFile2)
_, _ = w.Write(customCAServerFile2)
}))
)

Expand Down
42 changes: 23 additions & 19 deletions tests/servers/servers.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,19 +61,19 @@ fdsa`)

// HTTP Server
func (server *HTTPServer) Config(w http.ResponseWriter, r *http.Request) {
w.Write(servedConfig)
_, _ = w.Write(servedConfig)
}

func (server *HTTPServer) Contents(w http.ResponseWriter, r *http.Request) {
w.Write(servedContents)
_, _ = w.Write(servedContents)
}

func (server *HTTPServer) Certificates(w http.ResponseWriter, r *http.Request) {
w.Write(fixtures.PublicKey)
_, _ = w.Write(fixtures.PublicKey)
}

func (server *HTTPServer) CABundle(w http.ResponseWriter, r *http.Request) {
w.Write(fixtures.CABundle)
_, _ = w.Write(fixtures.CABundle)
}

func compress(contents []byte) []byte {
Expand All @@ -89,20 +89,20 @@ func compress(contents []byte) []byte {
}

func (server *HTTPServer) ConfigCompressed(w http.ResponseWriter, r *http.Request) {
w.Write(compress(servedConfig))
_, _ = w.Write(compress(servedConfig))
}

func (server *HTTPServer) ContentsCompressed(w http.ResponseWriter, r *http.Request) {
w.Write(compress(servedContents))
_, _ = w.Write(compress(servedContents))
}

func (server *HTTPServer) CertificatesCompressed(w http.ResponseWriter, r *http.Request) {
w.Write(compress(fixtures.PublicKey))
_, _ = w.Write(compress(fixtures.PublicKey))
}

func errorHandler(w http.ResponseWriter, message string) {
w.WriteHeader(http.StatusBadRequest)
w.Write([]byte(message))
_, _ = w.Write([]byte(message))
}

// headerCheck validates that all required headers are present
Expand Down Expand Up @@ -161,19 +161,19 @@ func overwrittenHeaderCheck(w http.ResponseWriter, r *http.Request) {
func (server *HTTPServer) ConfigHeaders(w http.ResponseWriter, r *http.Request) {
headerCheck(w, r)

w.Write(servedConfig)
_, _ = w.Write(servedConfig)
}

func (server *HTTPServer) ContentsHeaders(w http.ResponseWriter, r *http.Request) {
headerCheck(w, r)

w.Write(servedContents)
_, _ = w.Write(servedContents)
}

func (server *HTTPServer) CertificatesHeaders(w http.ResponseWriter, r *http.Request) {
headerCheck(w, r)

w.Write(fixtures.PublicKey)
_, _ = w.Write(fixtures.PublicKey)
}

// redirectedHeaderCheck validates that user's headers from the original request are missing
Expand All @@ -198,7 +198,7 @@ func (server *HTTPServer) ConfigRedirect(w http.ResponseWriter, r *http.Request)
func (server *HTTPServer) ConfigRedirected(w http.ResponseWriter, r *http.Request) {
redirectedHeaderCheck(w, r)

w.Write(servedConfig)
_, _ = w.Write(servedConfig)
}

// ContentsRedirect redirects the request to ContentsRedirected
Expand All @@ -210,7 +210,7 @@ func (server *HTTPServer) ContentsRedirect(w http.ResponseWriter, r *http.Reques
func (server *HTTPServer) ContentsRedirected(w http.ResponseWriter, r *http.Request) {
redirectedHeaderCheck(w, r)

w.Write(servedContents)
_, _ = w.Write(servedContents)
}

// CertificatesRedirect redirects the request to CertificatesRedirected
Expand All @@ -222,25 +222,25 @@ func (server *HTTPServer) CertificatesRedirect(w http.ResponseWriter, r *http.Re
func (server *HTTPServer) CertificatesRedirected(w http.ResponseWriter, r *http.Request) {
redirectedHeaderCheck(w, r)

w.Write(fixtures.PublicKey)
_, _ = w.Write(fixtures.PublicKey)
}

func (server *HTTPServer) ConfigHeadersOverwrite(w http.ResponseWriter, r *http.Request) {
overwrittenHeaderCheck(w, r)

w.Write(servedConfig)
_, _ = w.Write(servedConfig)
}

func (server *HTTPServer) ContentsHeadersOverwrite(w http.ResponseWriter, r *http.Request) {
overwrittenHeaderCheck(w, r)

w.Write(servedContents)
_, _ = w.Write(servedContents)
}

func (server *HTTPServer) CertificatesHeadersOverwrite(w http.ResponseWriter, r *http.Request) {
overwrittenHeaderCheck(w, r)

w.Write(fixtures.PublicKey)
_, _ = w.Write(fixtures.PublicKey)
}

type HTTPServer struct{}
Expand All @@ -266,7 +266,9 @@ func (server *HTTPServer) Start() {
http.HandleFunc("/config_headers_overwrite", server.ConfigHeadersOverwrite)
http.HandleFunc("/caBundle", server.CABundle)
s := &http.Server{Addr: ":8080"}
go s.ListenAndServe()
go func() {
_ = s.ListenAndServe()
}()
}

// TFTP Server
Expand All @@ -293,5 +295,7 @@ type TFTPServer struct{}
func (server *TFTPServer) Start() {
s := tftp.NewServer(server.ReadHandler, nil)
s.SetTimeout(5 * time.Second)
go s.ListenAndServe(":69")
go func() {
_ = s.ListenAndServe(":69")
}()
}

0 comments on commit 6ed3271

Please sign in to comment.