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

tables use tablehelpers.run #1696

Open
wants to merge 18 commits into
base: main
Choose a base branch
from

Conversation

James-Pickett
Copy link
Contributor

@James-Pickett James-Pickett commented Apr 26, 2024

relates to #1321

Adds helper functions to enforce timeout and simplify creating / execing commands. Follow on PR will add linting.

func RunSimple(ctx context.Context, slogger *slog.Logger, timeoutSeconds int, cmd allowedcmd.AllowedCommand, args []string, opts ...ExecOps)

func Run(ctx context.Context, slogger *slog.Logger, timeoutSeconds int, execCmd allowedcmd.AllowedCommand, args []string, stdout io.Writer, stderr io.Writer, opts ...ExecOps) error

Copy link
Contributor

@directionless directionless left a comment

Choose a reason for hiding this comment

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

love it

@James-Pickett James-Pickett changed the title touchid system config table use table helpers exec tables use table helpers exec May 1, 2024
@James-Pickett James-Pickett marked this pull request as ready for review May 1, 2024 15:21
RebeccaMahany
RebeccaMahany previously approved these changes May 1, 2024
Copy link
Contributor

@RebeccaMahany RebeccaMahany left a comment

Choose a reason for hiding this comment

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

LGTM, just one small/optional question!

pkg/osquery/table/touchid_system_darwin.go Outdated Show resolved Hide resolved
@James-Pickett James-Pickett marked this pull request as draft May 1, 2024 15:31
ee/tables/gsettings/metadata.go Outdated Show resolved Hide resolved
ee/tables/xrdb/xrdb.go Show resolved Hide resolved
@James-Pickett James-Pickett marked this pull request as ready for review May 6, 2024 16:19
@James-Pickett James-Pickett changed the title tables use table helpers exec tables use tablehelpers.run May 6, 2024
func Exec(ctx context.Context, slogger *slog.Logger, timeoutSeconds int, execCmd allowedcmd.AllowedCommand, args []string, includeStderr bool, opts ...ExecOps) ([]byte, error) {
// This is not suitable for high performance work -- it allocates new buffers each time
// Use Run() for more control over the stdout and stderr streams.
func RunSimple(ctx context.Context, slogger *slog.Logger, timeoutSeconds int, cmd allowedcmd.AllowedCommand, args []string, opts ...ExecOps) ([]byte, 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.

still not 100% sold on the functions .... wonder if we should make an option for WithStderr(w io.Writer)

Copy link
Contributor

Choose a reason for hiding this comment

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

TBH I'm not 100% sure either. But I think this is a great step, and we can refactor if it feels wrong.

RebeccaMahany
RebeccaMahany previously approved these changes May 6, 2024
directionless
directionless previously approved these changes May 7, 2024
Copy link
Contributor

@directionless directionless left a comment

Choose a reason for hiding this comment

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

I think this looks good. I'm not sure how to test it, aside from checking a lot of tables.

Copy link
Contributor

@directionless directionless left a comment

Choose a reason for hiding this comment

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

Still seems reasonable. Merge and iterate?

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.

None yet

3 participants