From a4c4fef01b4e260df44681824f79d9136534f1ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emmanuel=20BENO=C3=8ET?= Date: Fri, 26 Jul 2024 11:31:12 +0200 Subject: [PATCH] chore: get rid of deprecated `ioutil` package Fixes #3 --- buildcert.go | 7 +++---- config.go | 5 ++--- ldap.go | 4 ++-- logging.go | 4 ++-- 4 files changed, 9 insertions(+), 11 deletions(-) diff --git a/buildcert.go b/buildcert.go index d352ec2..e365ecd 100644 --- a/buildcert.go +++ b/buildcert.go @@ -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) } diff --git a/config.go b/config.go index 58ee6ee..9a22b1c 100644 --- a/config.go +++ b/config.go @@ -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) } diff --git a/ldap.go b/ldap.go index e21da6a..961a7d6 100644 --- a/ldap.go +++ b/ldap.go @@ -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 diff --git a/logging.go b/logging.go index 3613fc1..9a077c1 100644 --- a/logging.go +++ b/logging.go @@ -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 }