Skip to content

Add endpoint subcommand and add audit log#2

Merged
looplj merged 1 commit intomasterfrom
development
Mar 31, 2026
Merged

Add endpoint subcommand and add audit log#2
looplj merged 1 commit intomasterfrom
development

Conversation

@looplj
Copy link
Copy Markdown
Owner

@looplj looplj commented Mar 31, 2026

No description provided.

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request restructures the CLI command hierarchy by moving endpoint-related commands under a new endpoint parent command and introduces a GraphQL operation audit logging system. The audit system records executed queries and mutations to a local log file, which can be inspected using the new audit list command. Feedback focuses on improving the robustness and performance of the audit log parser, specifically by handling corrupted log lines gracefully and reducing memory allocations during scanning.

Comment on lines +38 to +40
if err := json.Unmarshal([]byte(line), &entry); err != nil {
return nil, fmt.Errorf("parse audit log line %d: %w", lineNumber, err)
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

A single malformed or corrupted line in the audit log will cause the entire audit list command to fail. It would be more robust to log a warning to stderr and continue parsing the remaining entries.

Suggested change
if err := json.Unmarshal([]byte(line), &entry); err != nil {
return nil, fmt.Errorf("parse audit log line %d: %w", lineNumber, err)
}
if err := json.Unmarshal(line, &entry); err != nil {
fmt.Fprintf(os.Stderr, "warning: skipping corrupted audit log line %d: %v\n", lineNumber, err)
continue
}

for scanner.Scan() {
lineNumber++

line := strings.TrimSpace(scanner.Text())
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

Using scanner.Text() followed by strings.TrimSpace creates unnecessary string allocations. Using scanner.Bytes() and bytes.TrimSpace is more efficient as json.Unmarshal accepts a byte slice.

Suggested change
line := strings.TrimSpace(scanner.Text())
line := bytes.TrimSpace(scanner.Bytes())
if len(line) == 0 {
continue
}

@looplj looplj merged commit da4b90d into master Mar 31, 2026
1 check passed
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