Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: remove refs to deprecated io/ioutil #639

Merged
merged 1 commit into from
Sep 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"crypto/tls"
"crypto/x509"
"fmt"
"io/ioutil"
"log"
"net/http"
"os"
Expand Down Expand Up @@ -789,7 +788,7 @@ func main() {
log.Printf("[DEBUG] : running mTLS server")
}

caCert, err := ioutil.ReadFile(config.TLSServer.CaCertFile)
caCert, err := os.ReadFile(config.TLSServer.CaCertFile)
if err != nil {
log.Printf("[ERROR] : %v\n", err.Error())
}
Expand Down
21 changes: 11 additions & 10 deletions outputs/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ import (
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"io"
"log"
"net/http"
"net/url"
"os"
"regexp"
"strings"
"sync"
Expand Down Expand Up @@ -208,7 +209,7 @@ func (c *Client) sendRequest(method string, payload interface{}) error {
}

if c.Config.TLSClient.CaCertFile != "" {
caCert, err := ioutil.ReadFile(c.Config.TLSClient.CaCertFile)
caCert, err := os.ReadFile(c.Config.TLSClient.CaCertFile)
if err != nil {
log.Printf("[ERROR] : %v - %v\n", c.OutputType, err.Error())
}
Expand Down Expand Up @@ -239,7 +240,7 @@ func (c *Client) sendRequest(method string, payload interface{}) error {
}

// Load CA cert
caCert, err := ioutil.ReadFile(MutualTLSClientCaCertPath)
caCert, err := os.ReadFile(MutualTLSClientCaCertPath)
if err != nil {
log.Printf("[ERROR] : %v - %v\n", c.OutputType, err.Error())
}
Expand Down Expand Up @@ -285,33 +286,33 @@ func (c *Client) sendRequest(method string, payload interface{}) error {
switch resp.StatusCode {
case http.StatusOK, http.StatusCreated, http.StatusAccepted, http.StatusNoContent: //200, 201, 202, 204
log.Printf("[INFO] : %v - Post OK (%v)\n", c.OutputType, resp.StatusCode)
body, _ := ioutil.ReadAll(resp.Body)
body, _ := io.ReadAll(resp.Body)
if ot := c.OutputType; ot == Kubeless || ot == Openfaas || ot == Fission {
log.Printf("[INFO] : %v - Function Response : %v\n", ot, string(body))
}
return nil
case http.StatusBadRequest: //400
body, _ := ioutil.ReadAll(resp.Body)
body, _ := io.ReadAll(resp.Body)
log.Printf("[ERROR] : %v - %v (%v): %v\n", c.OutputType, ErrHeaderMissing, resp.StatusCode, string(body))
return ErrHeaderMissing
case http.StatusUnauthorized: //401
body, _ := ioutil.ReadAll(resp.Body)
body, _ := io.ReadAll(resp.Body)
log.Printf("[ERROR] : %v - %v (%v): %v\n", c.OutputType, ErrClientAuthenticationError, resp.StatusCode, string(body))
return ErrClientAuthenticationError
case http.StatusForbidden: //403
body, _ := ioutil.ReadAll(resp.Body)
body, _ := io.ReadAll(resp.Body)
log.Printf("[ERROR] : %v - %v (%v): %v\n", c.OutputType, ErrForbidden, resp.StatusCode, string(body))
return ErrForbidden
case http.StatusNotFound: //404
body, _ := ioutil.ReadAll(resp.Body)
body, _ := io.ReadAll(resp.Body)
log.Printf("[ERROR] : %v - %v (%v): %v\n", c.OutputType, ErrNotFound, resp.StatusCode, string(body))
return ErrNotFound
case http.StatusUnprocessableEntity: //422
body, _ := ioutil.ReadAll(resp.Body)
body, _ := io.ReadAll(resp.Body)
log.Printf("[ERROR] : %v - %v (%v): %v\n", c.OutputType, ErrUnprocessableEntityError, resp.StatusCode, string(body))
return ErrUnprocessableEntityError
case http.StatusTooManyRequests: //429
body, _ := ioutil.ReadAll(resp.Body)
body, _ := io.ReadAll(resp.Body)
log.Printf("[ERROR] : %v - %v (%v): %v\n", c.OutputType, ErrTooManyRequest, resp.StatusCode, string(body))
return ErrTooManyRequest
case http.StatusInternalServerError: //500
Expand Down
7 changes: 3 additions & 4 deletions outputs/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"crypto/x509/pkix"
"encoding/base64"
"encoding/pem"
"io/ioutil"
"math/big"
"net"
"net/http"
Expand Down Expand Up @@ -259,7 +258,7 @@ func certsetup(config *types.Configuration) (serverTLSConf *tls.Config, err erro
})

// save ca to ca.crt file (it will be used by Client)
err = ioutil.WriteFile(config.MutualTLSClient.CaCertFile, caPEM.Bytes(), 0600)
err = os.WriteFile(config.MutualTLSClient.CaCertFile, caPEM.Bytes(), 0600)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -359,7 +358,7 @@ func certsetup(config *types.Configuration) (serverTLSConf *tls.Config, err erro
})

// save client cert and key to client.crt and client.key
err = ioutil.WriteFile(config.MutualTLSClient.CertFile, clientCertPEM.Bytes(), 0600)
err = os.WriteFile(config.MutualTLSClient.CertFile, clientCertPEM.Bytes(), 0600)
if err != nil {
return nil, err
}
Expand All @@ -368,7 +367,7 @@ func certsetup(config *types.Configuration) (serverTLSConf *tls.Config, err erro
Type: "RSA PRIVATE KEY",
Bytes: x509.MarshalPKCS1PrivateKey(clientCertPrivKey),
})
err = ioutil.WriteFile(config.MutualTLSClient.KeyFile, clientCertPrivKeyPEM.Bytes(), 0600)
err = os.WriteFile(config.MutualTLSClient.KeyFile, clientCertPrivKeyPEM.Bytes(), 0600)
if err != nil {
return nil, err
}
Expand Down
6 changes: 3 additions & 3 deletions outputs/spyderbat.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"io"
"log"
"net/http"
"net/url"
Expand Down Expand Up @@ -40,7 +40,7 @@ func isSourcePresent(config *types.Configuration) (bool, error) {
}
defer resp.Body.Close()

body, err := ioutil.ReadAll(resp.Body)
body, err := io.ReadAll(resp.Body)
if err != nil {
return false, err
}
Expand Down Expand Up @@ -93,7 +93,7 @@ func makeSource(config *types.Configuration) error {
}
if resp.StatusCode != http.StatusOK {
if resp.StatusCode == http.StatusBadRequest {
if b, err := ioutil.ReadAll(resp.Body); err == nil {
if b, err := io.ReadAll(resp.Body); err == nil {
return errors.New("Bad request: " + string(b))
}
}
Expand Down
Loading