chore: get rid of deprecated ioutil package

Fixes #3
This commit is contained in:
Emmanuel BENOîT 2024-07-26 11:31:12 +02:00
parent 9e8010279b
commit a4c4fef01b
Signed by: Emmanuel BENOîT
SSH key fingerprint: SHA256:l7PFUUF5TCDsvYeQC9OnTNz08dFY7Fvf4Hv3neIqYpg
4 changed files with 9 additions and 11 deletions

View file

@ -4,7 +4,6 @@ import (
"context"
"encoding/pem"
"fmt"
"io/ioutil"
"os"
"os/exec"
"os/user"
@ -128,7 +127,7 @@ func (b *tCertificateBuilder) MustWrite(force bool) bool {
if force || sys_stat.Size != int64(len(b.text)) {
return true
}
existing, err := ioutil.ReadFile(b.Config.Path)
existing, err := os.ReadFile(b.Config.Path)
if err != nil {
return true
}
@ -143,7 +142,7 @@ func (b *tCertificateBuilder) MustWrite(force bool) bool {
// Write the file's data
func (b *tCertificateBuilder) WriteFile() error {
log.WithField("file", b.Config.Path).Info("Writing certificate data to file")
err := ioutil.WriteFile(b.Config.Path, b.text, b.Config.FileMode())
err := os.WriteFile(b.Config.Path, b.text, b.Config.FileMode())
if err == nil {
b.changed = true
}
@ -262,7 +261,7 @@ func (b *tCertificateBuilder) appendPemFiles(files []string) error {
// Append a PEM file to the current list of data chunks
func (b *tCertificateBuilder) appendPem(input string) error {
data, err := ioutil.ReadFile(input)
data, err := os.ReadFile(input)
if err != nil {
return fmt.Errorf("Could not load '%s': %w", input, err)
}

View file

@ -3,7 +3,6 @@ package main
import (
"crypto/x509"
"fmt"
"io/ioutil"
"os"
"os/user"
"strconv"
@ -153,7 +152,7 @@ func (c *tLdapConnectionConfig) Validate() error {
return fmt.Errorf("Invalid TLS mode '%s' (valid values are 'yes', 'starttls' and 'no'", c.TLS)
}
if c.CaChain != "" {
data, err := ioutil.ReadFile(c.CaChain)
data, err := os.ReadFile(c.CaChain)
if err != nil {
return fmt.Errorf("Unable to read CA chain from '%s': %w", c.CaChain, err)
}
@ -351,7 +350,7 @@ func defaultConfiguration() tConfiguration {
// Load and check the configuration file
func LoadConfiguration(file string) (tConfiguration, error) {
cfg := defaultConfiguration()
cfgData, err := ioutil.ReadFile(file)
cfgData, err := os.ReadFile(file)
if err != nil {
return cfg, fmt.Errorf("Could not load configuration: %w", err)
}

View file

@ -5,7 +5,7 @@ import (
"crypto/x509"
"encoding/pem"
"fmt"
"io/ioutil"
"os"
ldap "github.com/go-ldap/ldap/v3"
"github.com/sirupsen/logrus"
@ -68,7 +68,7 @@ func getLdapServerConnection(cfg tLdapConfig, server int) *tLdapConn {
}
if scfg.TLS != "no" && scfg.CaChain != "" {
log := log.WithField("cachain", scfg.CaChain)
data, err := ioutil.ReadFile(scfg.CaChain)
data, err := os.ReadFile(scfg.CaChain)
if err != nil {
log.WithField("error", err).Error("Failed to read CA certificate chain")
return nil

View file

@ -1,7 +1,7 @@
package main
import (
"io/ioutil"
"io"
"log/syslog"
"os"
@ -67,7 +67,7 @@ func configureLogging(flags tCliFlags) error {
log.Logger.AddHook(hook)
}
if flags.quiet {
log.Logger.SetOutput(ioutil.Discard)
log.Logger.SetOutput(io.Discard)
}
return nil
}