Skip to content

Commit

Permalink
*: ioutil to other packages
Browse files Browse the repository at this point in the history
The ioutil functions are calling out to alternatives. Replace these
calls to appease the linter
  • Loading branch information
dschofie committed Jun 4, 2024
1 parent 187d507 commit 3731e7a
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 17 deletions.
6 changes: 3 additions & 3 deletions cmd/runner/tui.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package runner
import (
"fmt"
"io"
"io/ioutil"
"os"
"os/exec"
"sync"
"sync/atomic"
Expand Down Expand Up @@ -78,13 +78,13 @@ func (t *tui) createIfNotExists(acct resource.Account) {
t.main.SetText(tview.TranslateANSI(currText()))
})

file, err := ioutil.TempFile("/tmp", acctId)
file, err := os.CreateTemp("/tmp", acctId)
if err != nil {
panic(err)
}

setter := func() string {
bytes, err := ioutil.ReadFile(file.Name())
bytes, err := os.ReadFile(file.Name())
if err != nil {
fmt.Printf("ERR: %s \n", err)
return ""
Expand Down
6 changes: 3 additions & 3 deletions lib/telophase/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"bytes"
"encoding/json"
"fmt"
"io/ioutil"
"io"
"net/http"
"os"
)
Expand Down Expand Up @@ -35,7 +35,7 @@ func UpsertAccount(accountID string, accountName string) {
}
if resp.StatusCode != 200 {
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
body, err := io.ReadAll(resp.Body)
if err != nil {
fmt.Println(err)
}
Expand All @@ -58,7 +58,7 @@ func RecordDeploy(accountID string, accountName string) {
}
if resp.StatusCode != 200 {
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
body, err := io.ReadAll(resp.Body)
if err != nil {
fmt.Println(err)
}
Expand Down
5 changes: 2 additions & 3 deletions lib/terraform/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"encoding/hex"
"fmt"
"io/fs"
"io/ioutil"
"os"
"path"
"path/filepath"
Expand Down Expand Up @@ -57,7 +56,7 @@ func replaceVariablesInFile(srcFile, dstFile string, resource resource.Resource,
return oops.Wrapf(err, "error accessing file %s", srcFile)
}

content, err := ioutil.ReadFile(srcFile)
content, err := os.ReadFile(srcFile)
if err != nil {
return err
}
Expand All @@ -81,5 +80,5 @@ func replaceVariablesInFile(srcFile, dstFile string, resource resource.Resource,
return oops.Errorf("Region needs to be set on stack if performing substitution")
}

return ioutil.WriteFile(dstFile, []byte(updatedContent), fileInfo.Mode())
return os.WriteFile(dstFile, []byte(updatedContent), fileInfo.Mode())
}
7 changes: 3 additions & 4 deletions lib/ymlparser/organization.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"errors"
"fmt"
"io/ioutil"
"os"

"github.com/aws/aws-sdk-go/aws"
Expand Down Expand Up @@ -34,7 +33,7 @@ func (o Parser) ParseOrganization(ctx context.Context, filepath string) (*resour
return nil, errors.New("filepath is empty")
}

data, err := ioutil.ReadFile(filepath)
data, err := os.ReadFile(filepath)
if err != nil {
return nil, fmt.Errorf("err: %s reading file %s", err.Error(), filepath)
}
Expand Down Expand Up @@ -65,7 +64,7 @@ func (o Parser) ParseOrganization(ctx context.Context, filepath string) (*resour

func (p Parser) hydrateOUFilepaths(ctx context.Context, ou *resource.OrganizationUnit) error {
if ou.OUFilepath != nil {
data, err := ioutil.ReadFile(*ou.OUFilepath)
data, err := os.ReadFile(*ou.OUFilepath)
if err != nil {
return fmt.Errorf("err: %s reading file for OUFilepath %s", err.Error(), *ou.OUFilepath)
}
Expand Down Expand Up @@ -222,7 +221,7 @@ func WriteOrgFile(filepath string, org *resource.OrganizationUnit) error {
return fmt.Errorf("file %s already exists we will not overwrite it", filepath)
}

if err := ioutil.WriteFile(filepath, result, 0644); err != nil {
if err := os.WriteFile(filepath, result, 0644); err != nil {
return err
}

Expand Down
2 changes: 1 addition & 1 deletion resourceoperation/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func (ao *accountOperation) SetAllowDelete(allowDelete bool) {
ao.AllowDelete = allowDelete
}

func (ao *accountOperation) SetDelegateAdminPrincipal(principal string) {
func (ao *accountOperation) SetDelegatedAdminPrincipal(principal string) {
ao.DelegateAdminPrincipal = principal
}

Expand Down
2 changes: 1 addition & 1 deletion resourceoperation/organization_unit.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ func CollectOrganizationUnitOps(
nil,
nil,
)
op.SetDelegateAdminPrincipal(delegatedAdminService)
op.SetDelegatedAdminPrincipal(delegatedAdminService)
operations = append(operations, op)
}
}
Expand Down
4 changes: 2 additions & 2 deletions tests/end2end_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package tests
import (
"context"
"fmt"
"io/ioutil"
"os"
"runtime/debug"
"testing"

Expand Down Expand Up @@ -1071,7 +1071,7 @@ func TestEndToEnd(t *testing.T) {
compareOrganizationUnits(t, test.OrgInitialState, &fetchedOrg, true)
}

err = ioutil.WriteFile("organization.yml", []byte(test.OrgYaml), 0644)
err = os.WriteFile("organization.yml", []byte(test.OrgYaml), 0644)
assert.NoError(t, err, "Failed to write organization.yml")

parsedOrg, err := ymlparser.NewParser(orgClient).ParseOrganization(ctx, "organization.yml")
Expand Down

0 comments on commit 3731e7a

Please sign in to comment.