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

removes ioutil usage everywhere which was deprecated in go1.16 #15297

Merged
merged 12 commits into from
Nov 10, 2022

Conversation

kschoche
Copy link
Contributor

@kschoche kschoche commented Nov 8, 2022

Description

This is a cleanup PR that I'm testing, it would be sweet if it passed all the unit tests :-D

Deprecated: As of Go 1.16, the same functionality is now provided by package io or package os, and those implementations should be preferred in new code. See the specific function documentation for details.
https://pkg.go.dev/io/ioutil 

This PR also introduces a new rules to the golangci-lint tool which forbids the use of the ioutil package and will result in output like this:

demo $ make lint
--> Running golangci-lint
command/logout/logout_test.go:34:12: use of `ioutil.ReadFile` forbidden because "Use io and os packages instead of ioutil" (forbidigo)
        _, err := ioutil.ReadFile("abcd")
                  ^
make: *** [lint] Error 1

PR Checklist

  • updated test coverage
  • external facing docs updated
  • not a security concern

@github-actions github-actions bot added theme/api Relating to the HTTP API interface theme/certificates Related to creating, distributing, and rotating certificates in Consul theme/cli Flags and documentation for the CLI interface theme/config Relating to Consul Agent configuration, including reloading theme/connect Anything related to Consul Connect, Service Mesh, Side Car Proxies theme/envoy/xds Related to Envoy support theme/internals Serf, Raft, SWIM, Lifeguard, Anti-Entropy, locking topics theme/telemetry Anything related to telemetry or observability theme/tls Using TLS (Transport Layer Security) or mTLS (mutual TLS) to secure communication labels Nov 8, 2022
@kschoche kschoche added the pr/no-changelog PR does not need a corresponding .changelog entry label Nov 8, 2022
@kschoche
Copy link
Contributor Author

kschoche commented Nov 9, 2022

@dhiaayachi I'm not sure if this one's been proposed before, but thought I'd see if there was any interest in this PR. Thoughts?

Copy link
Collaborator

@dhiaayachi dhiaayachi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for working on this @kschoche!
Seems like your experiment is working 🚀
I added a comment about a commented code that I think we should remove.

I also have a suggestion to avoid regression for this (as long as ioutils is existing in golang). Maybe we can use something like this https://github.com/le0tk0k/noioutil to vet the code in the CI but feel free to merge this as is and have this in a subsequent PR.

command/logout/logout_test.go Outdated Show resolved Hide resolved
@rboyer
Copy link
Member

rboyer commented Nov 9, 2022

You might be able to use the forbidigo golanglint-ci configuration to prohibit calls: https://github.com/hashicorp/consul/blob/main/.golangci.yml#L85

@kschoche
Copy link
Contributor Author

kschoche commented Nov 9, 2022

You might be able to use the forbidigo golanglint-ci configuration to prohibit calls: https://github.com/hashicorp/consul/blob/main/.golangci.yml#L85

Ahh this is a great find, thanks!

--> Running golangci-lint
command/logout/logout_test.go:34:12: use of `ioutil.ReadFile` forbidden because "Use io and os packages instead of ioutil" (forbidigo)
        _, err := ioutil.ReadFile("abcd")
                  ^
make: *** [lint] Error 1

@kschoche kschoche changed the title [wip] removes ioutil usage everywhere which was deprecated in go1.16 removes ioutil usage everywhere which was deprecated in go1.16 Nov 9, 2022
@kschoche kschoche marked this pull request as ready for review November 9, 2022 21:54
@kschoche kschoche removed the pr/no-changelog PR does not need a corresponding .changelog entry label Nov 9, 2022
@kschoche kschoche requested a review from rboyer November 9, 2022 22:02
@@ -0,0 +1,3 @@
```release-note:improvement
all: Remove the use of the deprecated ioutil package throughout the codebase in favour of io and os packages which are still maintained and also introduce a lint rule which forbids the use of ioutil in commits.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Many times this sort of fixup doesn't necessitate a changelog entry. Your call if you think we should have one.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense! I was on the fence about it, so I'll remove it then, I think the commit message should be good enough!

@kschoche kschoche added the pr/no-changelog PR does not need a corresponding .changelog entry label Nov 9, 2022
@@ -1047,7 +1046,7 @@ func (a *ACL) RulesTranslate(rules io.Reader) (string, error) {
parseQueryMeta(resp, qm)
qm.RequestTime = rtt

ruleBytes, err := ioutil.ReadAll(resp.Body)
ruleBytes, err := io.ReadAll(resp.Body)
Copy link
Member

@rboyer rboyer Nov 9, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Usually we handle go version compatibility differently in the api package so that folks using the library aren't forced to upgrade to a future version before they're ready. I think the policy seems to be assuming folks are using a go version that is still receiving security updates (which 1.16 is definitely NOT anymore).

So in this case it's fine to do the swap. I wonder if we should correlate this with bumping the go directive in api/go.mod from 1.12 to at least 1.16 or maybe all the way to 1.18 (which is the oldest version we test against in CI).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The same logic would apply to sdk/go.mod too.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍🏽 Can do, I think 1.18 makes sense here then.
There is a ton of module tidying, save that for another PR?

@kschoche kschoche removed the pr/no-changelog PR does not need a corresponding .changelog entry label Nov 10, 2022
@kschoche kschoche merged commit bf0f61a into main Nov 10, 2022
@kschoche kschoche deleted the remove_deprecated_ioutil branch November 10, 2022 16:26
jmurret pushed a commit that referenced this pull request May 8, 2023
* update go version to 1.18 for api and sdk, go mod tidy
* removes ioutil usage everywhere which was deprecated in go1.16 in favour of io and os packages. Also introduces a lint rule which forbids use of ioutil going forward.
Co-authored-by: R.B. Boyer <4903+rboyer@users.noreply.github.com>
jmurret added a commit that referenced this pull request May 9, 2023
…#17243)

* no-op commit due to failed cherry-picking

* security: update go version to 1.20.4 (#17240)

* update go version to 1.20.3

* add changelog

* rename changelog file to remove underscore

* update to use 1.20.4

* update change log entry to reflect 1.20.4

* upgrading to 1.20

* [OSS] security: update go to 1.20.1 (#16263)

* security: update go to 1.20.1

* fixing auto_config_endpoint_test that was merged incorrectly

* go mod tidy

* fixing auto_config_endpoint_test that was merged incorrectly

* updating linter to 1.51.1

* go mod tidy on api

* go mod tidy

* removes ioutil usage everywhere which was deprecated in go1.16 (#15297)

* update go version to 1.18 for api and sdk, go mod tidy
* removes ioutil usage everywhere which was deprecated in go1.16 in favour of io and os packages. Also introduces a lint rule which forbids use of ioutil going forward.
Co-authored-by: R.B. Boyer <4903+rboyer@users.noreply.github.com>

* go mod tidy

* getting rd of net in imports

* get rid of use of math.rand

* get rid of use of math/rand in audo_config_endpoint_test.go

* update leader test

---------

Co-authored-by: temp <temp@hashicorp.com>
Co-authored-by: John Murret <john.murret@hashicorp.com>
Co-authored-by: Dan Stough <dan.stough@hashicorp.com>
Co-authored-by: Kyle Schochenmaier <kschoche@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
theme/api Relating to the HTTP API interface theme/certificates Related to creating, distributing, and rotating certificates in Consul theme/cli Flags and documentation for the CLI interface theme/config Relating to Consul Agent configuration, including reloading theme/connect Anything related to Consul Connect, Service Mesh, Side Car Proxies theme/envoy/xds Related to Envoy support theme/internals Serf, Raft, SWIM, Lifeguard, Anti-Entropy, locking topics theme/telemetry Anything related to telemetry or observability theme/tls Using TLS (Transport Layer Security) or mTLS (mutual TLS) to secure communication
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants