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

Add golangci config file and fix linter issues #108

Merged
merged 13 commits into from
Sep 19, 2023

Conversation

PanGan21
Copy link
Contributor

@PanGan21 PanGan21 commented Mar 8, 2023

@PanGan21 PanGan21 mentioned this pull request Mar 15, 2023
@PanGan21 PanGan21 marked this pull request as draft March 15, 2023 22:41
@nguyer
Copy link
Contributor

nguyer commented Mar 16, 2023

@PanGan21 Looks like this is on the right track! Now it's just a matter of working through all of the issues that the linter is catching.

@PanGan21 PanGan21 force-pushed the 106-add-linter-rules branch from 6040c5f to 03725d3 Compare March 17, 2023 19:44
@PanGan21 PanGan21 marked this pull request as ready for review March 20, 2023 18:25
@@ -133,7 +133,7 @@ func (g *RESTGateway) ValidateConf() error {
}

// Start kicks off the HTTP listener and router
func (g *RESTGateway) Start() error {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

It seems that I need to add a ReadHeaderTimeout because of the following error from gosec:

G112: Potential Slowloris Attack because ReadHeaderTimeout is not configured in the http.Server (gosec)

Should I add that in RESTGatewayConf ? What is recommended?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I ignored the linter on those places for now

Copy link
Contributor

Choose a reason for hiding this comment

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

That's fine for now. Can you put a // TODO: comment in the code explaining that please?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

added

@nguyer
Copy link
Contributor

nguyer commented Sep 15, 2023

@PanGan21 Apologies that I didn't realize this one was ready for re-review. Your comment brought it back up in my inbox and I'll take another look now. Thanks!

@@ -158,7 +158,7 @@ const (
// LevelDBFailedRetriveOriginalKey problem retrieving entry - original key
LevelDBFailedRetriveOriginalKey = "Failed to retrieve the entry for the original key: %s. %s"
// LevelDBFailedRetriveGeneratedID problem retrieving entry - generated ID
LevelDBFailedRetriveGeneratedID = "Failed to retrieve the entry for the generated ID: %s. %s"
LevelDBFailedRetriveGeneratedID = "failed to retrieve the entry for the generated ID: %s. %s"
Copy link
Contributor

Choose a reason for hiding this comment

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

Just curious why this one was lowercased but not the others?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's because I am getting this:

internal/rest/receipt/leveldb.go:227:15: ST1005: error strings should not be capitalized (stylecheck)
                return nil, fmt.Errorf(errors.LevelDBFailedRetriveGeneratedID, requestID, err)

@@ -44,7 +44,7 @@ type levelDBReceipts struct {
func newLevelDBReceipts(conf *conf.ReceiptsDBConf) *levelDBReceipts {
store := kvstore.NewLDBKeyValueStore(conf.LevelDB.Path)
t := time.Unix(1000000, 0)
entropy := ulid.Monotonic(rand.New(rand.NewSource(t.UnixNano())), 0)
entropy := ulid.Monotonic(rand.New(rand.NewSource(t.UnixNano())), 0) // #nosec
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm curious why the #nosec on this 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.

It actually throws this error:

internal/rest/receipt/leveldb.go:47:28: G404: Use of weak random number generator (math/rand instead of crypto/rand) (gosec)
        entropy := ulid.Monotonic(rand.New(rand.NewSource(t.UnixNano())), 0)

@@ -61,11 +61,11 @@ func CreateTLSConfiguration(tlsConfig *conf.TLSConfig) (t *tls.Config, err error
caCertPool = x509.NewCertPool()
caCertPool.AppendCertsFromPEM(caCert)
}

// #nosec G402
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you mind putting a comment here as to why this is required also please?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

added todo as well

Copy link
Contributor

@nguyer nguyer left a comment

Choose a reason for hiding this comment

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

This looks great! Just a couple questions and minor places a comment could be helpful, but I'm happy to merge this after that!

.golangci.yml Outdated
disable:
- structcheck
enable:
# - depguard
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I had to disable this linter because it throws error for many packages being used. Maybe another issue is required to upgrade those packages which might require more fixes.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I actually removed the depguard linter because I saw that it is also removed here: https://github.com/hyperledger/firefly/blob/main/.golangci.yml

@PanGan21
Copy link
Contributor Author

@PanGan21 Apologies that I didn't realize this one was ready for re-review. Your comment brought it back up in my inbox and I'll take another look now. Thanks!

No worries, i also have forgotten to submit my comments so i did it now😅
A bit of a hassle to fix all the conflicts after such long period but managed it.

@codecov-commenter
Copy link

Codecov Report

Merging #108 (ed7b113) into main (2346ff4) will increase coverage by 0.11%.
The diff coverage is 56.35%.

❗ Current head ed7b113 differs from pull request most recent head 6385858. Consider uploading reports for the commit 6385858 to get more accurate results

@@            Coverage Diff             @@
##             main     #108      +/-   ##
==========================================
+ Coverage   68.56%   68.67%   +0.11%     
==========================================
  Files          47       47              
  Lines        4504     4482      -22     
==========================================
- Hits         3088     3078      -10     
+ Misses       1215     1209       -6     
+ Partials      201      195       -6     
Files Changed Coverage Δ
cmd/debugrouter.go 0.00% <0.00%> (ø)
internal/errors/errors.go 100.00% <ø> (ø)
internal/events/test_helper.go 90.90% <ø> (-3.04%) ⬇️
internal/fabric/client/api.go 0.00% <ø> (ø)
internal/fabric/client/client_common.go 11.90% <0.00%> (ø)
internal/fabric/client/invokehandler.go 0.00% <0.00%> (ø)
internal/fabric/tx.go 0.00% <0.00%> (ø)
internal/messages/messages.go 0.00% <ø> (ø)
internal/utils/swagger-ui.go 0.00% <0.00%> (ø)
internal/utils/utils.go 59.57% <ø> (ø)
... and 33 more

@nguyer
Copy link
Contributor

nguyer commented Sep 18, 2023

The code looks good. You will need to amend your commit history to satisfy the DCO requirement though. The bot has linked to a page that explains how to do that, and which commits need to be updated: https://github.com/hyperledger/firefly-fabconnect/pull/108/checks?check_run_id=16863753560

@PanGan21 PanGan21 force-pushed the 106-add-linter-rules branch from 6385858 to d86d6ba Compare September 19, 2023 09:28
@PanGan21
Copy link
Contributor Author

The code looks good. You will need to amend your commit history to satisfy the DCO requirement though. The bot has linked to a page that explains how to do that, and which commits need to be updated: https://github.com/hyperledger/firefly-fabconnect/pull/108/checks?check_run_id=16863753560

I think I fixed it but I didn't sign the merge commit because it was double signing older commits. Could you please rerun the pipeline to see if everything is in place?

Copy link
Contributor

@nguyer nguyer left a comment

Choose a reason for hiding this comment

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

DCO looks good now. Thanks!

@nguyer nguyer merged commit 92a9508 into hyperledger:main Sep 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants