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

remove ioutils and configure golangci-lint #51

Merged
merged 1 commit into from
Aug 10, 2022
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
8 changes: 8 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@ linters:
disable:
- errcheck

linters-settings:
goimports:
local-prefixes: github.com/open-component-model/ocm
staticcheck:
go: "1.18"
stylecheck:
go: "1.18"

issues:
exclude:
- composites
3 changes: 1 addition & 2 deletions cmds/helminstaller/app/execute.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ package app

import (
"fmt"
"io/ioutil"
"os"
"strings"

Expand Down Expand Up @@ -68,7 +67,7 @@ func Execute(d driver.Driver, action string, ctx ocm.Context, octx out.Context,
}

// have to use the OS filesystem here for using the helm library
file, err := ioutil.TempFile("", "helm-*")
file, err := os.CreateTemp("", "helm-*")
if err != nil {
return err
}
Expand Down
14 changes: 0 additions & 14 deletions hack/check.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,4 @@ echo "Executing golangci-lint"
echo " golangci-lint run $GOLANGCI_LINT_CONFIG_FILE --timeout 10m $@"
golangci-lint run $GOLANGCI_LINT_CONFIG_FILE --timeout 10m $@

echo "Executing goimports"
folders=()
for f in $@; do
folders+=( "$(echo "$f" | sed 's/\(.*\)\/\.\.\./\1/')" )
done

GOBIN=$(go env GOPATH)
unformatted_files="$("${GOBIN}/bin"/goimports -l -local=github.com/open-component-model/ocm ${folders[*]})"
if [[ "$unformatted_files" ]]; then
echo "Unformatted files detected:"
echo "$unformatted_files"
exit 1
fi

echo "All checks successful"
3 changes: 1 addition & 2 deletions pkg/common/compression/c_bzip2.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
"compress/bzip2"
"fmt"
"io"
"io/ioutil"
)

// Bzip2AlgorithmName is the name used by pkg/compression.Bzip2.
Expand All @@ -37,7 +36,7 @@ func init() {

// bzip2Decompressor is a DecompressorFunc for the bzip2 compression algorithm.
func bzip2Decompressor(r io.Reader) (io.ReadCloser, error) {
return ioutil.NopCloser(bzip2.NewReader(r)), nil
return io.NopCloser(bzip2.NewReader(r)), nil
}

// bzip2Compressor is a CompressorFunc for the bzip2 compression algorithm.
Expand Down
3 changes: 1 addition & 2 deletions pkg/common/compression/c_xz.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ package compression

import (
"io"
"io/ioutil"

"github.com/ulikunitz/xz"
)
Expand All @@ -41,7 +40,7 @@ func xzDecompressor(r io.Reader) (io.ReadCloser, error) {
if err != nil {
return nil, err
}
return ioutil.NopCloser(r), nil
return io.NopCloser(r), nil
}

// xzCompressor is a CompressorFunc for the xz compression algorithm.
Expand Down
13 changes: 6 additions & 7 deletions pkg/common/compression/compression_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
"bytes"
"fmt"
"io"
"io/ioutil"
"os"
"testing"

Expand Down Expand Up @@ -59,7 +58,7 @@ func TestDetectCompression(t *testing.T) {
// The original stream is preserved.
fmt.Printf("***preserve***\n")
for _, c := range cases {
originalContents, err := ioutil.ReadFile(c)
originalContents, err := os.ReadFile(c)
require.NoError(t, err, c)

stream, err := os.Open(c)
Expand All @@ -70,7 +69,7 @@ func TestDetectCompression(t *testing.T) {
_, updatedStream, err := DetectCompression(stream)
require.NoError(t, err, c)

updatedContents, err := ioutil.ReadAll(updatedStream)
updatedContents, err := io.ReadAll(updatedStream)
require.NoError(t, err, c)
assert.Equal(t, originalContents, updatedContents, c)
}
Expand All @@ -92,7 +91,7 @@ func TestDetectCompression(t *testing.T) {
defer s.Close()
updatedStream = s

uncompressedContents, err := ioutil.ReadAll(updatedStream)
uncompressedContents, err := io.ReadAll(updatedStream)
require.NoError(t, err, c)
assert.Equal(t, []byte("Hello"), uncompressedContents, c)
}
Expand All @@ -103,7 +102,7 @@ func TestDetectCompression(t *testing.T) {
algo, updatedStream, err := DetectCompression(bytes.NewReader([]byte{}))
require.NoError(t, err)
assert.Equal(t, None, algo)
updatedContents, err := ioutil.ReadAll(updatedStream)
updatedContents, err := io.ReadAll(updatedStream)
require.NoError(t, err)
assert.Equal(t, []byte{}, updatedContents)

Expand Down Expand Up @@ -139,7 +138,7 @@ func TestAutoDecompress(t *testing.T) {

assert.Equal(t, c.isCompressed, isCompressed)

uncompressedContents, err := ioutil.ReadAll(uncompressedStream)
uncompressedContents, err := io.ReadAll(uncompressedStream)
require.NoError(t, err, c.filename)
assert.Equal(t, []byte("Hello"), uncompressedContents, c.filename)
}
Expand All @@ -148,7 +147,7 @@ func TestAutoDecompress(t *testing.T) {
uncompressedStream, isCompressed, err := AutoDecompress(bytes.NewReader([]byte{}))
require.NoError(t, err)
assert.False(t, isCompressed)
uncompressedContents, err := ioutil.ReadAll(uncompressedStream)
uncompressedContents, err := io.ReadAll(uncompressedStream)
require.NoError(t, err)
assert.Equal(t, []byte{}, uncompressedContents)

Expand Down
3 changes: 1 addition & 2 deletions pkg/common/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ package config

import (
"fmt"
"io/ioutil"
"os"
"strings"

Expand Down Expand Up @@ -47,7 +46,7 @@ func Configure(file string) error {
}
file = h + file[1:]
}
data, err := ioutil.ReadFile(file)
data, err := os.ReadFile(file)
if err != nil {
return errors.Wrapf(err, "cannot read config file %q", file)
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/contexts/config/config/context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
package config_test

import (
"io/ioutil"
"os"
"reflect"

. "github.com/onsi/ginkgo"
Expand All @@ -31,7 +31,7 @@ var _ = Describe("generic config handling", func() {
var scheme config.ConfigTypeScheme
var cfgctx config.Context

testdataconfig, _ := ioutil.ReadFile("testdata/config.yaml")
testdataconfig, _ := os.ReadFile("testdata/config.yaml")
testdatajson, _ := yaml.YAMLToJSON(testdataconfig)

_ = testdatajson
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ package dockerconfig
import (
"bytes"
"fmt"
"io/ioutil"
"os"
"strings"
"sync"
Expand Down Expand Up @@ -97,7 +96,8 @@ func (r *Repository) Read(force bool) error {
home := os.Getenv("HOME")
path = home + path[1:]
}
data, err := ioutil.ReadFile(path)

data, err := os.ReadFile(path)
if err != nil {
return err
}
Expand Down
3 changes: 1 addition & 2 deletions pkg/contexts/oci/repositories/docker/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
"context"
"fmt"
"io"
"io/ioutil"
"regexp"
"strings"
"sync"
Expand Down Expand Up @@ -131,7 +130,7 @@ func readAll(reader io.ReadCloser, err error) ([]byte, error) {
}
defer reader.Close()

data, err := ioutil.ReadAll(reader)
data, err := io.ReadAll(reader)
if err != nil {
return nil, err
}
Expand Down
3 changes: 1 addition & 2 deletions pkg/contexts/oci/repositories/ocireg/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
"context"
"fmt"
"io"
"io/ioutil"
"sync"

"github.com/containerd/containerd/errdefs"
Expand Down Expand Up @@ -96,7 +95,7 @@ func readAll(reader io.ReadCloser, err error) ([]byte, error) {
}
defer reader.Close()

data, err := ioutil.ReadAll(reader)
data, err := io.ReadAll(reader)
if err != nil {
return nil, err
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/contexts/ocm/accessmethods/github/method_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ package github_test
import (
"bytes"
"fmt"
"io/ioutil"
"io"
"net/http"
"os"
"path/filepath"
Expand Down Expand Up @@ -69,7 +69,7 @@ func (m *mockDownloader) Download(link string) ([]byte, error) {
}

func Configure(ctx ocm.Context) {
data, err := ioutil.ReadFile(filepath.Join(os.Getenv("HOME"), ".ocmconfig"))
data, err := os.ReadFile(filepath.Join(os.Getenv("HOME"), ".ocmconfig"))
if err != nil {
return
}
Expand Down Expand Up @@ -98,7 +98,7 @@ var _ = Describe("Method", func() {
return &http.Response{
StatusCode: 302,
Status: http.StatusText(http.StatusFound),
Body: ioutil.NopCloser(bytes.NewBufferString(`{}`)),
Body: io.NopCloser(bytes.NewBufferString(`{}`)),
// Must be set to non-nil value or it panics
Header: http.Header{
"Location": []string{defaultLink},
Expand Down
3 changes: 1 addition & 2 deletions pkg/docker/fetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"encoding/json"
"fmt"
"io"
"io/ioutil"
"net/http"
"net/url"
"strings"
Expand Down Expand Up @@ -201,7 +200,7 @@ func (r dockerFetcher) open(ctx context.Context, req *request, mediatype string,

// Discard up to offset
// Could use buffer pool here but this case should be rare
n, err := io.Copy(ioutil.Discard, io.LimitReader(resp.Body, offset))
n, err := io.Copy(io.Discard, io.LimitReader(resp.Body, offset))
if err != nil {
return nil, errors.Wrap(err, "failed to discard to offset")
}
Expand Down
3 changes: 1 addition & 2 deletions pkg/docker/httpreadseeker.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package docker
import (
"bytes"
"io"
"io/ioutil"

"github.com/containerd/containerd/errdefs"
"github.com/containerd/containerd/log"
Expand Down Expand Up @@ -162,7 +161,7 @@ func (hrs *httpReadSeeker) reader() (io.Reader, error) {
// as the length is already satisfied but we just return the empty
// reader instead.

hrs.rc = ioutil.NopCloser(bytes.NewReader([]byte{}))
hrs.rc = io.NopCloser(bytes.NewReader([]byte{}))
}

return hrs.rc, nil
Expand Down
3 changes: 1 addition & 2 deletions pkg/docker/pusher.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package docker
import (
"context"
"io"
"io/ioutil"
"net/http"
"net/url"
"strings"
Expand Down Expand Up @@ -263,7 +262,7 @@ func (p dockerPusher) push(ctx context.Context, desc ocispec.Descriptor, ref str

pr, pw := io.Pipe()
respC := make(chan response, 1)
body := ioutil.NopCloser(pr)
body := io.NopCloser(pr)

req.body = func() (io.ReadCloser, error) {
if body == nil {
Expand Down
3 changes: 1 addition & 2 deletions pkg/docker/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"context"
"fmt"
"io"
"io/ioutil"
"net/http"
"net/url"
"path"
Expand Down Expand Up @@ -359,7 +358,7 @@ func (r *dockerResolver) Resolve(ctx context.Context, ref string) (string, ocisp
return "", ocispec.Descriptor{}, err
}
}
} else if _, err := io.Copy(ioutil.Discard, &bodyReader); err != nil {
} else if _, err := io.Copy(io.Discard, &bodyReader); err != nil {
return "", ocispec.Descriptor{}, err
}
size = bodyReader.bytesRead
Expand Down
4 changes: 2 additions & 2 deletions pkg/signing/handlers/rsa-signingservice/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"encoding/pem"
"errors"
"fmt"
"io/ioutil"
"io"
"net/http"

"github.com/open-component-model/ocm/pkg/signing"
Expand Down Expand Up @@ -68,7 +68,7 @@ func (signer *SigningServerSigner) Sign(algo string, digest string, issuer strin
}
defer res.Body.Close()

responseBodyBytes, err := ioutil.ReadAll(res.Body)
responseBodyBytes, err := io.ReadAll(res.Body)
if err != nil {
return nil, fmt.Errorf("failed reading response body: %w", err)
}
Expand Down
8 changes: 4 additions & 4 deletions pkg/signing/x509_certificate.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"encoding/pem"
"errors"
"fmt"
"io/ioutil"
"os"
)

// CreateAndVerifyX509CertificateFromFiles creates and verifies a x509 certificate from certificate files.
Expand All @@ -30,21 +30,21 @@ func CreateAndVerifyX509CertificateFromFiles(certPath, intermediateCAsCertsPath,

var rootCACert []byte
if rootCACertPath != "" {
rootCACert, err = ioutil.ReadFile(rootCACertPath)
rootCACert, err = os.ReadFile(rootCACertPath)
if err != nil {
return nil, fmt.Errorf("unable to read root CA certificate file: %w", err)
}
}

var intermediateCAsCerts []byte
if intermediateCAsCertsPath != "" {
intermediateCAsCerts, err = ioutil.ReadFile(intermediateCAsCertsPath)
intermediateCAsCerts, err = os.ReadFile(intermediateCAsCertsPath)
if err != nil {
return nil, fmt.Errorf("unable to read intermediate CAs certificates file: %w", err)
}
}

cert, err := ioutil.ReadFile(certPath)
cert, err := os.ReadFile(certPath)
if err != nil {
return nil, fmt.Errorf("unable to read certificate file: %w", err)
}
Expand Down
Loading