Skip to content

Commit 164160c

Browse files
Pranav GoyalGitHub Enterprise
authored andcommitted
Merge pull request #529 from mq-cloudpak/pranav-2680-remove-ioutil-lts
2680 - Remove ioutil dependency from mq-container LTS Branch
2 parents cdd0f83 + 8fc0368 commit 164160c

File tree

16 files changed

+66
-70
lines changed

16 files changed

+66
-70
lines changed

cmd/runmqdevserver/main.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
© Copyright IBM Corporation 2018, 2021
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.
@@ -17,7 +17,6 @@ package main
1717

1818
import (
1919
"fmt"
20-
"io/ioutil"
2120
"os"
2221
"syscall"
2322

@@ -78,7 +77,7 @@ func logTermination(args ...interface{}) {
7877
// that Kubernetes will look for termination information.
7978
log.Debugf("Writing termination message: %v", msg)
8079
// #nosec G306 - its a read by owner/s group, and pose no harm.
81-
err := ioutil.WriteFile("/run/termination-log", []byte(msg), 0660)
80+
err := os.WriteFile("/run/termination-log", []byte(msg), 0660)
8281
if err != nil {
8382
log.Debug(err)
8483
}

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: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
© Copyright IBM Corporation 2017, 2021
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.
@@ -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
@@ -17,7 +17,6 @@ package main
1717

1818
import (
1919
"fmt"
20-
"io/ioutil"
2120
"os"
2221
"path/filepath"
2322
"regexp"
@@ -108,19 +107,19 @@ func createQueueManager(name string, devMode bool) (bool, error) {
108107
return true, nil
109108
}
110109

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

123-
//validateLogFilePageSetting validates if the specified logFilePage number is equal to the existing value in the qm.ini
122+
// validateLogFilePageSetting validates if the specified logFilePage number is equal to the existing value in the qm.ini
124123
func validateLogFilePageSetting(iniFileBytes []byte, logFilePages string) bool {
125124
lfpString := "LogFilePages=" + logFilePages
126125
qminiConfigStr := string(iniFileBytes)
@@ -318,7 +317,7 @@ func updateQMini(qmname string) error {
318317
qmgrDir := filepath.Join(dataDir, "qm.ini")
319318
//read the initial version.
320319
// #nosec G304 - qmgrDir filepath is derived from dspmqinf
321-
iniFileBytes, err := ioutil.ReadFile(qmgrDir)
320+
iniFileBytes, err := os.ReadFile(qmgrDir)
322321
if err != nil {
323322
return err
324323
}
@@ -328,7 +327,7 @@ func updateQMini(qmname string) error {
328327
curFile := re.ReplaceAllString(qminiConfigStr, "")
329328
// #nosec G304 G306 - qmgrDir filepath is derived from dspmqinf and
330329
// its a read by owner/s group, and pose no harm.
331-
err := ioutil.WriteFile(qmgrDir, []byte(curFile), 0660)
330+
err := os.WriteFile(qmgrDir, []byte(curFile), 0660)
332331
if err != nil {
333332
return err
334333
}

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: 8 additions & 3 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
}
@@ -273,4 +278,4 @@ func readFileString(file string) string {
273278
return ""
274279
}
275280
return strings.TrimSpace(string(b))
276-
}
281+
}

internal/containerruntime/runtime.go

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

1818
import (
1919
"fmt"
20-
"io/ioutil"
20+
"os"
2121
"strings"
22-
2322
)
2423

2524
func DetectContainerRuntime() ContainerRuntime {
2625
return GetContainerRuntime(0, 1)
2726
}
2827

2928
func GetBaseImage() (string, error) {
30-
buf, err := ioutil.ReadFile("/etc/os-release")
29+
buf, err := os.ReadFile("/etc/os-release")
3130
if err != nil {
3231
return "", fmt.Errorf("Failed to read /etc/os-release: %v", err)
3332
}
@@ -71,7 +70,7 @@ func GetSecurityAttributes() string {
7170

7271
func readProc(filename string) (value string, err error) {
7372
// #nosec G304
74-
buf, err := ioutil.ReadFile(filename)
73+
buf, err := os.ReadFile(filename)
7574
if err != nil {
7675
return "", err
7776
}

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)