Skip to content

Commit a26f76b

Browse files
Pranav GoyalGitHub Enterprise
authored andcommitted
Merge pull request #530 from mq-cloudpak/pranav-2680-remove-ioutil-cd
2680 - Remove ioutil dependency from mq-container CD branch
2 parents 4fd3a48 + 502f3a3 commit a26f76b

File tree

16 files changed

+57
-60
lines changed

16 files changed

+57
-60
lines changed

cmd/runmqdevserver/main.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ package main
1717

1818
import (
1919
"fmt"
20-
"io/ioutil"
2120
"os"
2221
"strings"
2322
"syscall"
@@ -92,7 +91,7 @@ func logTermination(args ...interface{}) {
9291
// that Kubernetes will look for termination information.
9392
log.Debugf("Writing termination message: %v", msg)
9493
// #nosec G306 - its a read by owner/s group, and pose no harm.
95-
err := ioutil.WriteFile("/run/termination-log", []byte(msg), 0660)
94+
err := os.WriteFile("/run/termination-log", []byte(msg), 0660)
9695
if err != nil {
9796
log.Debug(err)
9897
}

cmd/runmqserver/license.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
© Copyright IBM Corporation 2017, 2018
2+
© Copyright IBM Corporation 2017, 2023
33
44
Licensed under the Apache License, Version 2.0 (the "License");
55
you may not use this file except in compliance with the License.
@@ -17,7 +17,6 @@ package main
1717

1818
import (
1919
"errors"
20-
"io/ioutil"
2120
"os"
2221
"path/filepath"
2322
"strings"
@@ -79,7 +78,7 @@ func checkLicense() (bool, error) {
7978
case ok && lic == "view":
8079
file := filepath.Join("/opt/mqm/licenses", resolveLicenseFile())
8180
// #nosec G304
82-
buf, err := ioutil.ReadFile(file)
81+
buf, err := os.ReadFile(file)
8382
if err != nil {
8483
log.Println(err)
8584
return false, err

cmd/runmqserver/logging.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import (
1919
"context"
2020
"encoding/json"
2121
"fmt"
22-
"io/ioutil"
2322
"os"
2423
"os/exec"
2524
"path/filepath"
@@ -47,7 +46,7 @@ func logTermination(args ...interface{}) {
4746
// that Kubernetes will look for termination information.
4847
log.Debugf("Writing termination message: %v", msg)
4948
// #nosec G306 - its a read by owner/s group, and pose no harm.
50-
err := ioutil.WriteFile("/run/termination-log", []byte(msg), 0660)
49+
err := os.WriteFile("/run/termination-log", []byte(msg), 0660)
5150
if err != nil {
5251
log.Debug(err)
5352
}

cmd/runmqserver/main_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
© Copyright IBM Corporation 2017, 2019
2+
© Copyright IBM Corporation 2017, 2023
33
44
Licensed under the Apache License, Version 2.0 (the "License");
55
you may not use this file except in compliance with the License.
@@ -17,7 +17,6 @@ package main
1717

1818
import (
1919
"flag"
20-
"io/ioutil"
2120
"os"
2221
"path/filepath"
2322
"strconv"
@@ -51,7 +50,7 @@ func TestSystem(t *testing.T) {
5150
osExit = func(rc int) {
5251
// Write the exit code to a file instead
5352
log.Printf("Writing exit code %v to file %v", strconv.Itoa(rc), filename)
54-
err := ioutil.WriteFile(filename, []byte(strconv.Itoa(rc)), 0644)
53+
err := os.WriteFile(filename, []byte(strconv.Itoa(rc)), 0644)
5554
if err != nil {
5655
log.Print(err)
5756
}

cmd/runmqserver/mirror_test.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
© Copyright IBM Corporation 2018, 2019
2+
© Copyright IBM Corporation 2018, 2023
33
44
Licensed under the Apache License, Version 2.0 (the "License");
55
you may not use this file except in compliance with the License.
@@ -18,7 +18,6 @@ package main
1818
import (
1919
"context"
2020
"fmt"
21-
"io/ioutil"
2221
"os"
2322
"strconv"
2423
"strings"
@@ -32,7 +31,7 @@ func TestMirrorLogWithoutRotation(t *testing.T) {
3231
for i := 0; i < 10; i++ {
3332
t.Run(t.Name()+strconv.Itoa(i), func(t *testing.T) {
3433
// Use just the sub-test name in the file name
35-
tmp, err := ioutil.TempFile("", strings.Split(t.Name(), "/")[1])
34+
tmp, err := os.CreateTemp("", strings.Split(t.Name(), "/")[1])
3635
if err != nil {
3736
t.Fatal(err)
3837
}
@@ -71,7 +70,7 @@ func TestMirrorLogWithRotation(t *testing.T) {
7170
for i := 0; i < 5; i++ {
7271
t.Run(t.Name()+strconv.Itoa(i), func(t *testing.T) {
7372
// Use just the sub-test name in the file name
74-
tmp, err := ioutil.TempFile("", strings.Split(t.Name(), "/")[1])
73+
tmp, err := os.CreateTemp("", strings.Split(t.Name(), "/")[1])
7574
if err != nil {
7675
t.Fatal(err)
7776
}
@@ -126,13 +125,13 @@ func TestMirrorLogWithRotation(t *testing.T) {
126125
}
127126

128127
func testMirrorLogExistingFile(t *testing.T, newQM bool) int {
129-
tmp, err := ioutil.TempFile("", t.Name())
128+
tmp, err := os.CreateTemp("", t.Name())
130129
if err != nil {
131130
t.Fatal(err)
132131
}
133132
t.Log(tmp.Name())
134133
log.Println("Logging 1 message before we start")
135-
ioutil.WriteFile(tmp.Name(), []byte("{\"message\"=\"A\"}\n"), 0600)
134+
os.WriteFile(tmp.Name(), []byte("{\"message\"=\"A\"}\n"), 0600)
136135
defer os.Remove(tmp.Name())
137136
count := 0
138137
ctx, cancel := context.WithCancel(context.Background())

cmd/runmqserver/qmgr.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ package main
1818
import (
1919
"context"
2020
"fmt"
21-
"io/ioutil"
2221
"os"
2322
"path/filepath"
2423
"regexp"
@@ -109,19 +108,19 @@ func createQueueManager(name string, devMode bool) (bool, error) {
109108
return true, nil
110109
}
111110

112-
//readQMIni reads the qm.ini file and returns it as a byte array
113-
//This function is specific to comply with the nosec.
111+
// readQMIni reads the qm.ini file and returns it as a byte array
112+
// This function is specific to comply with the nosec.
114113
func readQMIni(dataDir string) ([]byte, error) {
115114
qmgrDir := filepath.Join(dataDir, "qm.ini")
116115
// #nosec G304 - qmgrDir filepath is derived from dspmqinf
117-
iniFileBytes, err := ioutil.ReadFile(qmgrDir)
116+
iniFileBytes, err := os.ReadFile(qmgrDir)
118117
if err != nil {
119118
return nil, err
120119
}
121120
return iniFileBytes, err
122121
}
123122

124-
//validateLogFilePageSetting validates if the specified logFilePage number is equal to the existing value in the qm.ini
123+
// validateLogFilePageSetting validates if the specified logFilePage number is equal to the existing value in the qm.ini
125124
func validateLogFilePageSetting(iniFileBytes []byte, logFilePages string) bool {
126125
lfpString := "LogFilePages=" + logFilePages
127126
qminiConfigStr := string(iniFileBytes)
@@ -320,7 +319,7 @@ func updateQMini(qmname string) error {
320319
qmgrDir := filepath.Join(dataDir, "qm.ini")
321320
//read the initial version.
322321
// #nosec G304 - qmgrDir filepath is derived from dspmqinf
323-
iniFileBytes, err := ioutil.ReadFile(qmgrDir)
322+
iniFileBytes, err := os.ReadFile(qmgrDir)
324323
if err != nil {
325324
return err
326325
}
@@ -330,7 +329,7 @@ func updateQMini(qmname string) error {
330329
curFile := re.ReplaceAllString(qminiConfigStr, "")
331330
// #nosec G304 G306 - qmgrDir filepath is derived from dspmqinf and
332331
// its a read by owner/s group, and pose no harm.
333-
err := ioutil.WriteFile(qmgrDir, []byte(curFile), 0660)
332+
err := os.WriteFile(qmgrDir, []byte(curFile), 0660)
334333
if err != nil {
335334
return err
336335
}

cmd/runmqserver/qmgr_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ limitations under the License.
1616
package main
1717

1818
import (
19-
"io/ioutil"
19+
"os"
2020
"testing"
2121
)
2222

@@ -73,7 +73,7 @@ func Test_validateLogFilePageSetting(t *testing.T) {
7373
}
7474
for _, tt := range tests {
7575
t.Run(tt.name, func(t *testing.T) {
76-
iniFileBytes, err := ioutil.ReadFile(tt.args.iniFilePath)
76+
iniFileBytes, err := os.ReadFile(tt.args.iniFilePath)
7777
if err != nil {
7878
t.Fatal(err)
7979
}

internal/containerruntime/amicontained.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,15 @@ SOFTWARE.
2424
The code was forked when the latest details are as "Latest commit 871fc34 on Sep 18, 2018"
2525
*/
2626

27+
// Adding IBM Copyright since the forked code had to be modified to remove deprecated ioutil package
28+
/*
29+
© Copyright IBM Corporation 2023
30+
*/
31+
2732
package containerruntime
2833

2934
import (
3035
"fmt"
31-
"io/ioutil"
3236
"os"
3337
"path/filepath"
3438
"regexp"
@@ -172,7 +176,8 @@ func readFile(file string) []byte {
172176
}
173177
// filepath.clean was added to resolve the gosec build failure
174178
// with error "Potential file inclusion via variable"
175-
b, err := ioutil.ReadFile(filepath.Clean(file))
179+
// IBM Modified the below line to remove the deprecated ioutil dependency
180+
b, err := os.ReadFile(filepath.Clean(file))
176181
if err != nil {
177182
return nil
178183
}

internal/containerruntime/runtime.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ package containerruntime
1717

1818
import (
1919
"fmt"
20-
"io/ioutil"
20+
"os"
2121
"strings"
2222
)
2323

@@ -26,7 +26,7 @@ func DetectContainerRuntime() ContainerRuntime {
2626
}
2727

2828
func GetBaseImage() (string, error) {
29-
buf, err := ioutil.ReadFile("/etc/os-release")
29+
buf, err := os.ReadFile("/etc/os-release")
3030
if err != nil {
3131
return "", fmt.Errorf("Failed to read /etc/os-release: %v", err)
3232
}
@@ -70,7 +70,7 @@ func GetSecurityAttributes() string {
7070

7171
func readProc(filename string) (value string, err error) {
7272
// #nosec G304
73-
buf, err := ioutil.ReadFile(filename)
73+
buf, err := os.ReadFile(filename)
7474
if err != nil {
7575
return "", err
7676
}

internal/htpasswd/htpasswd.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
© Copyright IBM Corporation 2020, 2021
2+
© Copyright IBM Corporation 2020, 2023
33
44
Licensed under the Apache License, Version 2.0 (the "License");
55
you may not use this file except in compliance with the License.
@@ -20,7 +20,7 @@ package htpasswd
2020

2121
import (
2222
"fmt"
23-
"io/ioutil"
23+
"os"
2424
"strings"
2525

2626
"golang.org/x/crypto/bcrypt"
@@ -79,7 +79,7 @@ func (htpfile mapHtPasswd) ReadHtPasswordFile(isTest bool) error {
7979
file = "my.htpasswd"
8080
}
8181

82-
pwdsBytes, err := ioutil.ReadFile(file)
82+
pwdsBytes, err := os.ReadFile(file)
8383
if err != nil {
8484
return err
8585
}
@@ -109,5 +109,5 @@ func (htpfile mapHtPasswd) updateHtPasswordFile(isTest bool) error {
109109
file = "my.htpasswd"
110110
}
111111
// #nosec G306 - its a read by owner/s group, and pose no harm.
112-
return ioutil.WriteFile(file, htpfile.GetBytes(), 0660)
112+
return os.WriteFile(file, htpfile.GetBytes(), 0660)
113113
}

0 commit comments

Comments
 (0)