Skip to content

chore(lint): fixes#395

Open
mschfh wants to merge 3 commits intomasterfrom
mschfh-lint-fixes
Open

chore(lint): fixes#395
mschfh wants to merge 3 commits intomasterfrom
mschfh-lint-fixes

Conversation

@mschfh
Copy link
Copy Markdown
Contributor

@mschfh mschfh commented Feb 24, 2026

No description provided.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR applies linting fixes to address gosec security warnings and formatting issues throughout the codebase.

Changes:

  • Added gosec nolint directives with explanatory comments for intentional security suppressions (pprof endpoints, error handling in shutdown)
  • Changed maxSize parameter type from int64 to int32 in GetUpdatesForType method across all interfaces, implementations, mocks, and call sites to match AWS DynamoDB SDK requirements
  • Applied multi-line formatting to function calls and definitions with many parameters for improved readability

Reviewed changes

Copilot reviewed 13 out of 13 changed files in this pull request and generated no comments.

Show a summary per file
File Description
server/server.go Added gosec nolint comments for pprof import, server shutdown, and pprof listener
datastore/sync_entity_test.go Reformatted GetUpdatesForType test calls to multi-line format
datastore/sync_entity.go Changed maxSize parameter from int64 to int32; reformatted long function calls
datastore/item_count_test.go Reformatted ClientItemCounts struct initialization
datastore/item_count.go Reformatted long expression and UpdateClientItemCount signature
datastore/instrumented_datastore.go Updated GetUpdatesForType signature to use int32 for maxSize
datastore/datastoretest/mock_datastore.go Updated mock method signatures to use int32; applied multi-line formatting
datastore/datastore.go Updated interface signatures for GetUpdatesForType and UpdateClientItemCount
command/server_defined_unique_entity.go Reformatted createServerDefinedUniqueEntity signature
command/command_test.go Reformatted NewPBSyncAttrs signature and long function calls
command/command.go Changed maxGUBatchSize to int32; added gosec nolint for safe conversion; reformatted signatures
cache/cache.go Reformatted IncrementInterimCount signature
auth/auth.go Added gosec nolint for false positive on regex pattern

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@mschfh mschfh marked this pull request as ready for review March 17, 2026 19:08
@mihaiplesa mihaiplesa requested a review from Copilot March 17, 2026 19:09
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 13 out of 13 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 13 out of 13 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

clientToken int64,
fetchFolders bool,
clientID string,
maxSize int32,
Copy link

Copilot AI Mar 31, 2026

Choose a reason for hiding this comment

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

Changing the Datastore interface signature from maxSize int64 to maxSize int32 is a breaking API change for any external implementers/callers of this module. If the goal is only to satisfy AWS SDK types, consider keeping int64 in the public interface and converting/validating internally (or introduce a new method) to avoid an unintended breaking change.

Suggested change
maxSize int32,
maxSize int64,

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 13 out of 13 changed files in this pull request and generated 4 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

maxGUBatchSize = 500
maxClientObjectQuota = 50000
maxClientHistoryObjectQuota = 30000
maxGUBatchSize int32 = 500
Copy link

Copilot AI Mar 31, 2026

Choose a reason for hiding this comment

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

Changing maxGUBatchSize to int32 makes maxSize an int32, but later in this function maxSize is used as the slice capacity (guRsp.Entries = make(..., 0, maxSize)), which won’t compile because make() requires an int capacity. Either keep maxGUBatchSize/maxSize as int, or convert to int at the make() call (and any other places that require an int).

Suggested change
maxGUBatchSize int32 = 500
maxGUBatchSize int = 500

Copilot uses AI. Check for mistakes.
clientToken int64,
fetchFolders bool,
clientID string,
maxSize int32,
Copy link

Copilot AI Mar 31, 2026

Choose a reason for hiding this comment

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

GetUpdatesForType’s maxSize parameter was changed from int64 to int32, which is a breaking change to the exported Datastore interface (and the API surface of this module) even though the PR is labeled as a lint chore. If the goal is only to satisfy DynamoDB Limit’s int32 type, consider keeping the interface parameter as int/int64 and performing a checked conversion at the DynamoDB boundary (returning an error if out of range), to avoid forcing all downstream implementations/callers to change.

Suggested change
maxSize int32,
maxSize int64,

Copilot uses AI. Check for mistakes.
Comment on lines +145 to 146
//nolint:errcheck,gosec // Error during shutdown in signal handler is acceptable
srv.Shutdown(serverCtx)
Copy link

Copilot AI Mar 31, 2026

Choose a reason for hiding this comment

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

srv.Shutdown(serverCtx) error is intentionally ignored here, but suppressing both errcheck and gosec removes any visibility into failed graceful shutdowns (e.g., context deadline exceeded). Consider capturing and logging the returned error instead of dropping it, even in the signal handler, so operational issues are diagnosable.

Suggested change
//nolint:errcheck,gosec // Error during shutdown in signal handler is acceptable
srv.Shutdown(serverCtx)
if err := srv.Shutdown(serverCtx); err != nil {
log.Err(err).Msg("HTTP server graceful shutdown failed")
}

Copilot uses AI. Check for mistakes.
Comment on lines 152 to 155
// host:6061/debug/pprof/
go func() {
//nolint:gosec // G114: pprof diagnostic server
if err := http.ListenAndServe(":6061", http.DefaultServeMux); err != nil {
Copy link

Copilot AI Mar 31, 2026

Choose a reason for hiding this comment

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

The pprof listener is started with http.ListenAndServe(":6061", ...) (binds all interfaces) and has no server timeouts; adding a //nolint:gosec suppresses G114, but it doesn’t mitigate the underlying exposure/DoS risk if PPROF_ENABLED is enabled accidentally or in the wrong environment. Prefer binding to localhost (127.0.0.1:6061) and using an http.Server with reasonable timeouts (ReadHeaderTimeout/IdleTimeout/etc.), or otherwise restricting access at the network layer and documenting that requirement.

Suggested change
// host:6061/debug/pprof/
go func() {
//nolint:gosec // G114: pprof diagnostic server
if err := http.ListenAndServe(":6061", http.DefaultServeMux); err != nil {
// 127.0.0.1:6061/debug/pprof/
go func() {
pprofSrv := &http.Server{
Addr: "127.0.0.1:6061",
Handler: http.DefaultServeMux,
ReadHeaderTimeout: 5 * time.Second,
IdleTimeout: 60 * time.Second,
}
if err := pprofSrv.ListenAndServe(); err != nil {

Copilot uses AI. Check for mistakes.
maxGUBatchSize = 500
maxClientObjectQuota = 50000
maxClientHistoryObjectQuota = 30000
maxGUBatchSize int32 = 500
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I agree with Copilot's comment here. I suspect the "won't compile" part isn't correct because the checks pass, but it would be good to use int anyway for simplicity.

// FromProgressMarker, where the returned token stays the same as the one
// passed in FromProgressMarker.
if len(guRsp.Entries) >= maxSize {
if len(guRsp.Entries) >= int(maxSize) {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

if maxGUBatchSize becomes int, then we don't need a cast


curMaxSize := int64(maxSize) - int64(len(guRsp.Entries))
hasChangesRemaining, entities, err := db.GetUpdatesForType(ctx, int(*fromProgressMarker.DataTypeId), token, fetchFolders, clientID, curMaxSize)
curMaxSize := int32(int(maxSize) - len(guRsp.Entries)) //nolint:gosec // maxSize is 500 and the >= check above ensures entries fits within it
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

It would be nice if we could simplify to maxSize - len(guRsp.Entries), making curMaxSize an int

clientToken int64,
fetchFolders bool,
clientID string,
maxSize int32,
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

maxSize could be int

ProjectionExpression: aws.String(projPk),
TableName: aws.String(Table),
Limit: aws.Int32(int32(maxSize)),
Limit: aws.Int32(maxSize),
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

changing the maxSize param type to int, and keeping the int32 cast here will help remove the convoluted casting near the call site of this function.

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