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

Fix issues reported by static analysis #1357

Merged
merged 2 commits into from
Aug 14, 2024
Merged

Conversation

Danielius1922
Copy link
Member

No description provided.

Copy link
Contributor

coderabbitai bot commented Aug 14, 2024

Walkthrough

The recent updates across various Dockerfiles enhance readability and maintainability while preserving core functionality. Key improvements include restructuring package installations, refining build flag formatting, and consolidating commands for optimization. These changes result in a cleaner codebase, making navigation and future modifications easier for developers.

Changes

Files Change Summary
Dockerfile.test, bundle/Dockerfile, test/cloud-server/Dockerfile Improved clarity with reorganized installation commands, enhanced formatting of build flags, and optimized command consolidation.
m2m-oauth-server/store/mongodb/tokens_test.go Simplified timestamp assertion by replacing require.Greater with require.Positive.
pkg/net/grpc/authFromOutgoingMD.go Introduced errUnauthenticated function for centralized error handling; refined existing error handling.
pkg/security/certManager/general/certManager_test.go Removed //nolint:staticcheck comments for better compliance with linting rules.
resource-aggregate/... Refactored functions for enhanced modularity and error handling; streamlined method logic for clarity.
test/security/jwk.go Replaced io.WriteString with Write method for improved performance in NewTestJwks function.

Poem

🐇 In fields of code, where changes sprout,
Our builds are bright, with nary a doubt.
Flags neatly lined, errors tucked away,
A rabbit's delight in this refactor play!
Hops of joy as we refine,
With each fresh line, our code will shine! ✨


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@Danielius1922 Danielius1922 marked this pull request as ready for review August 14, 2024 10:37
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between a0f461c and 72e6d5a.

Files ignored due to path filters (4)
  • charts/plgd-hub/templates/certs/default/ca-issuer.yaml is excluded by !**/*.yaml
  • charts/plgd-hub/templates/certs/default/root-ca.yaml is excluded by !**/*.yaml
  • charts/plgd-hub/templates/certs/storage/scylla-crt.yaml is excluded by !**/*.yaml
  • charts/plgd-hub/templates/mongodb-standby-tool/config.yaml is excluded by !**/*.yaml
Files selected for processing (19)
  • Dockerfile.test (2 hunks)
  • bundle/Dockerfile (3 hunks)
  • grpc-gateway/client/maintenance.go (1 hunks)
  • http-gateway/Dockerfile (2 hunks)
  • http-gateway/Dockerfile.www (1 hunks)
  • m2m-oauth-server/store/mongodb/tokens_test.go (1 hunks)
  • pkg/net/grpc/authFromOutgoingMD.go (1 hunks)
  • pkg/security/certManager/general/certManager_test.go (1 hunks)
  • resource-aggregate/cqrs/eventstore/cqldb/load.go (2 hunks)
  • resource-aggregate/events/deviceMetadataSnapshotTaken.go (2 hunks)
  • resource-aggregate/events/resourceLinksSnapshotTaken.go (2 hunks)
  • resource-aggregate/events/resourceStateSnapshotTaken.go (3 hunks)
  • test/cloud-server/Dockerfile (1 hunks)
  • test/security/jwk.go (2 hunks)
  • tools/cert-tool/Dockerfile (2 hunks)
  • tools/docker/Dockerfile.in (2 hunks)
  • tools/grpc-reflection/Dockerfile (2 hunks)
  • tools/mongodb/admin-tool/Dockerfile (2 hunks)
  • tools/mongodb/standby-tool/Dockerfile (2 hunks)
Files skipped from review due to trivial changes (9)
  • http-gateway/Dockerfile
  • http-gateway/Dockerfile.www
  • pkg/security/certManager/general/certManager_test.go
  • test/cloud-server/Dockerfile
  • tools/cert-tool/Dockerfile
  • tools/docker/Dockerfile.in
  • tools/grpc-reflection/Dockerfile
  • tools/mongodb/admin-tool/Dockerfile
  • tools/mongodb/standby-tool/Dockerfile
Additional comments not posted (21)
Dockerfile.test (2)

3-4: Reformatting improves readability.

The restructuring of the apt-get install command into multiple lines enhances readability and maintainability.


7-7: Verify the impact of WORKDIR /.

The addition of WORKDIR / changes the context for subsequent commands. Ensure that this change does not affect operations that rely on the current directory.

test/security/jwk.go (1)

73-75: Improved performance and simplicity.

Switching from io.WriteString to w.Write enhances performance by avoiding unnecessary string conversion and simplifies the code.

pkg/net/grpc/authFromOutgoingMD.go (2)

17-19: Centralized error handling improves maintainability.

The introduction of errUnauthenticated centralizes error creation, reducing redundancy and enhancing readability and maintainability.


26-26: Refactored error handling enhances clarity.

Refactoring error handling to use errUnauthenticated improves the clarity and consistency of the code.

Also applies to: 33-33

grpc-gateway/client/maintenance.go (1)

86-86: Improved error message formatting.

The addition of a format specifier ("%s") in the error message enhances clarity and consistency in error reporting.

resource-aggregate/cqrs/eventstore/cqldb/load.go (3)

Line range hint 139-160:
Modularized aggregate ID filtering.

The introduction of addAggregateIDsToFilter improves modularity and readability by separating the logic for handling aggregate IDs.


162-171: Modularized timestamp filtering.

The new addTimestampToFilter function enhances modularity by isolating the timestamp handling logic, making the code easier to maintain.


173-179: Refactored filter construction for snapshots.

The use of helper functions in snapshotQueriesToFilter streamlines the logic and improves maintainability by delegating specific responsibilities.

m2m-oauth-server/store/mongodb/tokens_test.go (1)

239-239: Simplified test assertion.

Replacing require.Greater with require.Positive clarifies the intent of the test by directly asserting that the timestamp is positive.

resource-aggregate/events/resourceLinksSnapshotTaken.go (2)

173-195: Centralize event handling logic in handleByEvent.

The handleByEvent method centralizes the event handling logic, improving code organization and maintainability. The switch statement effectively manages different event types by unmarshalling and invoking the corresponding handler methods.

  • Error Handling: The error handling for unmarshalling is consistent with the existing code style, returning internal status errors.
  • Maintainability: This refactoring enhances readability and makes future extensions easier.

Ensure that all potential event types are covered and that any new event types are added here in the future.


Line range hint 196-207:
Refactor Handle method to use handleByEvent.

The Handle method now delegates event-specific logic to the handleByEvent method. This refactoring separates concerns, making the code cleaner and more modular.

  • Error Handling: The check for an empty event type is appropriately placed before invoking handleByEvent, ensuring robustness.

Verify that all event types processed in handleByEvent are correctly handled in this method.

bundle/Dockerfile (4)

3-3: Reorder package installations for clarity.

The reordering of the apk add command improves readability but does not affect functionality. Ensure that the order aligns with any dependencies that might exist between packages.


24-29: Improve build flag formatting for readability.

Splitting the -ldflags across multiple lines enhances readability and maintainability. This change makes it easier to understand and modify the build process. Ensure that all flags are correctly specified and that there are no syntax errors.

Also applies to: 37-42, 50-55, 63-68, 76-81, 89-94, 102-107, 115-120, 128-133, 141-146, 154-159, 167-172, 180-185, 193-198


213-219: Consolidate commands to reduce image layers.

Consolidating multiple RUN commands into a single command using && reduces the number of layers in the Docker image, optimizing the build process. Ensure that all commands execute correctly in sequence.


228-232: Streamline package installation in the base image.

The changes to the apt-get install command enhance readability and maintainability. Ensure that the list of packages and the installation process remain correct and efficient.

resource-aggregate/events/deviceMetadataSnapshotTaken.go (1)

161-163: Relocate event type validation to Handle method.

The relocation of the event type validation to the Handle method ensures that events with undefined types are not processed. This change enhances the robustness of the error handling process.

  • Error Handling: The check for an empty event type is correctly placed before invoking handleByEvent.

Verify that this change does not affect the handling of valid events.

resource-aggregate/events/resourceStateSnapshotTaken.go (4)

115-118: Interface Definition Looks Good.

The pendingEvent interface is well-defined and ensures that types implementing it can be used with the generic function checkForDuplicityCorrelationID.


120-130: Generic Function Implementation Looks Good.

The checkForDuplicityCorrelationID function effectively uses generics to reduce code duplication and enhance modularity while maintaining the original functionality.


132-143: Refactored Method Looks Good.

The refactoring of checkForDuplicityCorrelationID simplifies the method by removing repetitive code and using the generic function. Error handling is appropriately retained.


410-412: Event Type Check Placement Looks Good.

Moving the check for an empty event type string within the loop improves clarity by ensuring validation before processing.

@Danielius1922 Danielius1922 force-pushed the adam/feature/golansci-upd-8 branch from 72e6d5a to d4e70a7 Compare August 14, 2024 12:13
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Outside diff range, codebase verification and nitpick comments (1)
resource-aggregate/cqrs/eventstore/cqldb/load.go (1)

Line range hint 139-160: Optimize string concatenation with strings.Builder.

Using strings.Builder for aggrs can improve performance by reducing memory allocations during string concatenation.

func addAggregateIDsToFilter(filter *strings.Builder, queries []eventstore.SnapshotQuery) {
	var aggrs strings.Builder
	for _, q := range queries {
		if q.AggregateID != "" && q.AggregateID != uuid.Nil.String() {
			if aggrs.Len() > 0 {
				aggrs.WriteString(",")
			}
			aggrs.WriteString(q.AggregateID)
		}
	}
	if aggrs.Len() > 0 {
		if filter.Len() > 0 {
			filter.WriteString(" and ")
		}
		filter.WriteString(idKey)
		filter.WriteString(" in (")
		filter.WriteString(aggrs.String())
		filter.WriteString(")")
	}
}
Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 72e6d5a and d4e70a7.

Files ignored due to path filters (4)
  • charts/plgd-hub/templates/certs/default/ca-issuer.yaml is excluded by !**/*.yaml
  • charts/plgd-hub/templates/certs/default/root-ca.yaml is excluded by !**/*.yaml
  • charts/plgd-hub/templates/certs/storage/scylla-crt.yaml is excluded by !**/*.yaml
  • charts/plgd-hub/templates/mongodb-standby-tool/config.yaml is excluded by !**/*.yaml
Files selected for processing (19)
  • Dockerfile.test (2 hunks)
  • bundle/Dockerfile (3 hunks)
  • grpc-gateway/client/maintenance.go (1 hunks)
  • http-gateway/Dockerfile (2 hunks)
  • http-gateway/Dockerfile.www (1 hunks)
  • m2m-oauth-server/store/mongodb/tokens_test.go (1 hunks)
  • pkg/net/grpc/authFromOutgoingMD.go (1 hunks)
  • pkg/security/certManager/general/certManager_test.go (1 hunks)
  • resource-aggregate/cqrs/eventstore/cqldb/load.go (2 hunks)
  • resource-aggregate/events/deviceMetadataSnapshotTaken.go (2 hunks)
  • resource-aggregate/events/resourceLinksSnapshotTaken.go (2 hunks)
  • resource-aggregate/events/resourceStateSnapshotTaken.go (3 hunks)
  • test/cloud-server/Dockerfile (1 hunks)
  • test/security/jwk.go (2 hunks)
  • tools/cert-tool/Dockerfile (2 hunks)
  • tools/docker/Dockerfile.in (2 hunks)
  • tools/grpc-reflection/Dockerfile (2 hunks)
  • tools/mongodb/admin-tool/Dockerfile (2 hunks)
  • tools/mongodb/standby-tool/Dockerfile (2 hunks)
Files skipped from review due to trivial changes (6)
  • http-gateway/Dockerfile
  • http-gateway/Dockerfile.www
  • test/cloud-server/Dockerfile
  • tools/cert-tool/Dockerfile
  • tools/mongodb/admin-tool/Dockerfile
  • tools/mongodb/standby-tool/Dockerfile
Files skipped from review as they are similar to previous changes (11)
  • Dockerfile.test
  • bundle/Dockerfile
  • grpc-gateway/client/maintenance.go
  • m2m-oauth-server/store/mongodb/tokens_test.go
  • pkg/net/grpc/authFromOutgoingMD.go
  • resource-aggregate/events/deviceMetadataSnapshotTaken.go
  • resource-aggregate/events/resourceLinksSnapshotTaken.go
  • resource-aggregate/events/resourceStateSnapshotTaken.go
  • test/security/jwk.go
  • tools/docker/Dockerfile.in
  • tools/grpc-reflection/Dockerfile
Additional context used
golangci-lint
pkg/security/certManager/general/certManager_test.go

181-181: SA1019: pool.Subjects has been deprecated since Go 1.18: if s was returned by [SystemCertPool], Subjects will not include the system roots.

(staticcheck)


185-185: SA1019: pool.Subjects has been deprecated since Go 1.18: if s was returned by [SystemCertPool], Subjects will not include the system roots.

(staticcheck)


192-192: SA1019: pool.Subjects has been deprecated since Go 1.18: if s was returned by [SystemCertPool], Subjects will not include the system roots.

(staticcheck)

Additional comments not posted (4)
resource-aggregate/cqrs/eventstore/cqldb/load.go (2)

174-180: LGTM!

The function is well-structured, using helper functions effectively to construct the filter string.


162-172: Verify the use of ALLOW FILTERING.

The use of ALLOW FILTERING can impact query performance and correctness. Ensure it is necessary and used appropriately.

pkg/security/certManager/general/certManager_test.go (2)

185-185: Replace deprecated pool.Subjects usage.

pool.Subjects has been deprecated. Consider using pool.VerifyPeerCertificate or another appropriate method to check certificate subjects.

Tools
golangci-lint

185-185: SA1019: pool.Subjects has been deprecated since Go 1.18: if s was returned by [SystemCertPool], Subjects will not include the system roots.

(staticcheck)


192-192: Replace deprecated pool.Subjects usage.

pool.Subjects has been deprecated. Consider using pool.VerifyPeerCertificate or another appropriate method to check certificate subjects.

Tools
golangci-lint

192-192: SA1019: pool.Subjects has been deprecated since Go 1.18: if s was returned by [SystemCertPool], Subjects will not include the system roots.

(staticcheck)

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between d4e70a7 and 6e98277.

Files selected for processing (3)
  • Dockerfile.test (2 hunks)
  • bundle/Dockerfile (3 hunks)
  • test/cloud-server/Dockerfile (2 hunks)
Files skipped from review due to trivial changes (1)
  • test/cloud-server/Dockerfile
Files skipped from review as they are similar to previous changes (2)
  • Dockerfile.test
  • bundle/Dockerfile

@Danielius1922 Danielius1922 force-pushed the adam/feature/golansci-upd-8 branch from 6e98277 to e360303 Compare August 14, 2024 14:29
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 6e98277 and e360303.

Files selected for processing (3)
  • Dockerfile.test (2 hunks)
  • bundle/Dockerfile (3 hunks)
  • test/cloud-server/Dockerfile (2 hunks)
Files skipped from review due to trivial changes (1)
  • test/cloud-server/Dockerfile
Files skipped from review as they are similar to previous changes (2)
  • Dockerfile.test
  • bundle/Dockerfile

Copy link

sonarqubecloud bot commented Aug 14, 2024

@Danielius1922 Danielius1922 merged commit 6428ac1 into main Aug 14, 2024
39 checks passed
@Danielius1922 Danielius1922 deleted the adam/feature/golansci-upd-8 branch August 14, 2024 15:31
@coderabbitai coderabbitai bot mentioned this pull request Sep 16, 2024
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.

1 participant