Skip to content

Adding support to osctrl-cli to look up nodes via osctrl-api #658

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

Merged
merged 5 commits into from
Jun 1, 2025

Conversation

javuto
Copy link
Collaborator

@javuto javuto commented Jun 1, 2025

@javuto javuto requested a review from Copilot June 1, 2025 17:26
@javuto javuto added osctrl-api osctrl-api related changes osctrl-cli osctrl-cli related changes labels Jun 1, 2025
Copy link
Contributor

@Copilot 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

Adds support for looking up nodes via the osctrl API in the CLI and cleans up related types and handlers.

  • Removes the old ApiLookupResponse type and swaps schema references to use OsqueryNode
  • Implements a new lookup CLI command and the underlying OsctrlAPI.LookupNode method
  • Refactors handler code to return raw OsqueryNode, and standardizes some error messages

Reviewed Changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
pkg/types/types.go Deleted unused ApiLookupResponse type
osctrl-api.yaml Changed lookup response reference to OsqueryNode schema
cmd/cli/node.go Refactored showNode, added lookupNode using _showNode helper
cmd/cli/main.go Added lookup command; lowercased backend creation error messages
cmd/cli/api-node.go Added LookupNode implementation on OsctrlAPI
cmd/api/handlers/utils.go Removed unused node-to-API conversion helper
cmd/api/handlers/nodes.go Updated handler to return nodes.OsqueryNode directly
Comments suppressed due to low confidence (5)

cmd/cli/api-node.go:70

  • [nitpick] Variable name 'l' is ambiguous (looks like '1'); consider renaming to 'req' or 'lookupReq' for clarity.
l := types.ApiLookupRequest{

cmd/cli/main.go:1704

  • [nitpick] Error message casing is inconsistent with other messages; consider standardizing (e.g., start with uppercase or lowercase consistently).
return fmt.Errorf("failed to create backend - %w", err)

cmd/cli/main.go:1709

  • [nitpick] Error message casing is inconsistent with other messages; consider standardizing (e.g., start with uppercase or lowercase consistently).
return fmt.Errorf("failed to create backend - %w", err)

cmd/cli/node.go:255

  • New lookup functionality is introduced without accompanying unit or integration tests; consider adding tests for lookupNode behavior.
func lookupNode(c *cli.Context) error {

cmd/cli/main.go:1210

  • [nitpick] The alias 'f' for the 'lookup' command may be non-intuitive; consider using a more descriptive alias like 'l' or 'id'.
Aliases: []string{"f"},

javuto and others added 4 commits June 1, 2025 19:34
Use `bytes.NewReader(jsonMessage)` instead of converting to string to avoid unnecessary memory allocation.

Co-authored-by: Copilot <[email protected]>
Constructing the URL using `path.Join` to avoid manual concatenation errors.

Co-authored-by: Copilot <[email protected]>
@javuto javuto merged commit 5f3d72b into main Jun 1, 2025
54 checks passed
@javuto javuto deleted the cli-lookup-identifier branch June 1, 2025 19:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
osctrl-api osctrl-api related changes osctrl-cli osctrl-cli related changes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant