mirror of
https://github.com/fleetdm/fleet
synced 2026-04-21 21:47:20 +00:00
Resolves #38484. This includes a CI job change to make sure we don't introduce any more env vars that don't get proxied (and thus turned off outside `--dev`). # Checklist for submitter If some of the following don't apply, delete the relevant line. - [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/guides/committing-changes.md#changes-files) for more information. - [x] Input data is properly validated, `SELECT *` is avoided, SQL injection is prevented (using placeholders for values in statements) ## Testing - [x] Added/updated automated tests Manual QA touched hot paths, but did _not_ manually test every FLEET_DEV_* environment variable change. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Centralized dev-mode environment management for consistent FLEET_DEV_* handling and test-friendly overrides. * Dev-mode allows targeted overrides for certain dev-only configuration when running with --dev. * **Chores** * Migrated environment access to the centralized dev-mode helper across the codebase. * Added CI checks to enforce proper usage of FLEET_DEV_* variables. * **Documentation** * Added guidance on dev-mode environment variable rules and overrides. <sub>✏️ Tip: You can customize this high-level summary in your review settings.</sub> <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Co-authored-by: Victor Lyuboslavsky <2685025+getvictor@users.noreply.github.com>
43 lines
857 B
Go
43 lines
857 B
Go
package dev_mode
|
|
|
|
import (
|
|
"os"
|
|
"testing"
|
|
)
|
|
|
|
var IsEnabled bool
|
|
|
|
var envOverrides = map[string]string{}
|
|
|
|
type GetEnv func(name string) string
|
|
|
|
func Env(name string) string {
|
|
if !IsEnabled {
|
|
return ""
|
|
}
|
|
if override, ok := envOverrides[name]; ok {
|
|
return override
|
|
}
|
|
|
|
return os.Getenv(name)
|
|
}
|
|
|
|
func SetOverride(name string, value string, cleanup ...*testing.T) { // optional parameter to reset on test cleanup
|
|
if len(cleanup) > 0 {
|
|
cleanup[0].Setenv("FLEET_DEV_OVERRIDE_SET", "1") // triggers test deny-parallel check
|
|
cleanup[0].Cleanup(func() {
|
|
ClearOverride(name)
|
|
})
|
|
}
|
|
|
|
IsEnabled = true // if we're setting overrides, we're in a test environment so want to turn dev mode on
|
|
envOverrides[name] = value
|
|
}
|
|
|
|
func ClearOverride(name string) {
|
|
delete(envOverrides, name)
|
|
}
|
|
|
|
func ClearAllOverrides() {
|
|
envOverrides = map[string]string{}
|
|
}
|