fleet/orbit/pkg/execuser/execuser.go
Victor Lyuboslavsky bab0e159a9
Adding telemetry for specific Fleet Desktop errors (#23349)
Adding telemetry for catching issue #19172

# Docs changes

In another PR: https://github.com/fleetdm/fleet/pull/23423/files

# Demo
<div>
<a href="https://www.loom.com/share/233625875eec46508c26ae315cd52d19">
<p>[Demo] Add telemetry for vital fleetd errors - Issue #23413 - Watch
Video</p>
    </a>
<a href="https://www.loom.com/share/233625875eec46508c26ae315cd52d19">
<img style="max-width:300px;"
src="https://cdn.loom.com/sessions/thumbnails/233625875eec46508c26ae315cd52d19-45ca0ec1b7b5e9e7-full-play.gif">
    </a>
  </div>

# Checklist for submitter

- [x] Changes file added for user-visible changes in `changes/`,
`orbit/changes/` or `ee/fleetd-chrome/changes`.
See [Changes
files](https://github.com/fleetdm/fleet/blob/main/docs/Contributing/Committing-Changes.md#changes-files)
for more information.
- [x] Added/updated tests
- [x] Manual QA for all new/changed functionality
- For Orbit and Fleet Desktop changes:
- [x] Orbit runs on macOS, Linux and Windows. Check if the orbit
feature/bugfix should only apply to one platform (`runtime.GOOS`).
- [x] Manual QA must be performed in the three main OSs, macOS, Windows
and Linux.
- [x] Auto-update manual QA, from released version of component to new
version (see [tools/tuf/test](../tools/tuf/test/README.md)).
2024-10-31 14:24:42 -05:00

42 lines
1.2 KiB
Go

// Package execuser is used to run applications from a high privilege user (root on Unix,
// SYSTEM service on Windows) as the current login user.
package execuser
type eopts struct {
env [][2]string
args [][2]string
stderrPath string //nolint:structcheck,unused
}
// Option allows configuring the application.
type Option func(*eopts)
// WithEnv sets environment variables for the application.
func WithEnv(name, value string) Option {
return func(a *eopts) {
a.env = append(a.env, [2]string{name, value})
}
}
// WithArg sets command line arguments for the application.
//
// TODO: for now CLI arguments are only used by the darwin
// implementation, just because it's the only platform that needs
// them.
func WithArg(name, value string) Option {
return func(a *eopts) {
a.args = append(a.args, [2]string{name, value})
}
}
// Run runs an application as the current login user.
// It assumes the caller is running with high privileges (root on Unix, SYSTEM on Windows).
//
// It returns after starting the child process.
func Run(path string, opts ...Option) (lastLogs string, err error) {
var o eopts
for _, fn := range opts {
fn(&o)
}
return run(path, o)
}