Skip to content

Conversation

blink-so-v1[bot]
Copy link

@blink-so-v1 blink-so-v1 bot commented Sep 11, 2025

Summary

Migrated all environment variable reads to the CLI package and centralized the processing logic. This improves code organization, testability, and eliminates redundant parsing throughout the codebase.

Changes

Environment Variable Centralization

  • Moved all os.Getenv() calls to CLI package: All environment variable reads now happen in a single location
  • Created SudoData struct: Holds processed environment data with both raw and computed values
  • Added readSudoData() function: Centralizes environment variable reading, parsing, and validation

Integer-Based Processing

  • Convert strings to integers once: Environment variables are parsed to integers in readSudoData() and used as integers throughout
  • Eliminated redundant parsing: Removed strconv.Atoi() calls from TLS, jail, and namespace packages
  • Updated all EnvConfig structs: Changed UID/GID fields from string to int across all packages

Code Organization

  • Updated function signatures: All constructors now accept EnvConfig parameters instead of reading environment variables directly
  • Added helper methods: ToTLSEnvConfig() and ToJailEnvConfig() for clean data conversion
  • Removed unused imports: Cleaned up strconv imports where no longer needed
  • Fixed cross-platform compatibility: Updated stub files to match new function signatures

Environment Variables Handled

  • SUDO_USER - Original username when running under sudo
  • SUDO_UID - Original user ID (parsed to int)
  • SUDO_GID - Original group ID (parsed to int)
  • XDG_CONFIG_HOME - XDG config directory path

Testing

  • ✅ All existing tests pass
  • ✅ Code compiles successfully on all platforms
  • ✅ Cross-platform stub files updated
  • ✅ No breaking changes to external interfaces

Benefits

  • Better Testability: Environment variables can now be mocked easily
  • Cleaner Code: Single source of truth for environment variable access
  • Improved Performance: No redundant string parsing
  • Maintainability: Environment variable usage is centralized and easy to track
  • Type Safety: Integer values used directly instead of error-prone string parsing

blink-so-v1 bot and others added 3 commits September 11, 2025 17:32
Moved all os.Getenv() calls to the CLI package and pass environment
variables as parameters to components that need them. This centralizes
environment variable access and makes the code more testable.

Changes:
- Updated CLI package to read all environment variables directly
- Modified TLS, jail, and namespace packages to accept env config
- Removed all os.Getenv() calls from non-CLI packages
- Updated function signatures across all affected components
- Fixed stub files for cross-platform compatibility

Co-authored-by: f0ssel <[email protected]>
Centralized environment variable reading and processing logic into a
single function that returns a SudoData struct with both raw and
processed values.

Improvements:
- Created SudoData struct with raw env vars and processed values
- Added readSudoData() function that handles all sudo-related logic
- Centralized user lookup, UID/GID parsing, and error handling
- Eliminated duplicate os.Getenv() calls throughout the code
- Added proper logging for sudo environment processing
- Made the code more testable and maintainable

All environment variable reads are now in a single location with
consistent error handling and logging.

Co-authored-by: f0ssel <[email protected]>
Simplified the codebase by converting string environment variables to
integers once in readSudoData() and using integers throughout instead
of converting back and forth between strings and integers.

Changes:
- Removed raw string fields from SudoData struct
- Updated all EnvConfig structs to use integers for UID/GID
- Eliminated string parsing in TLS, jail, and namespace packages
- Removed unnecessary strconv imports
- Simplified credential handling by working with integers directly
- Maintained centralized environment variable reading in CLI package

All environment variable processing now happens once in readSudoData(),
with processed integer values used throughout the codebase.

Co-authored-by: f0ssel <[email protected]>
@f0ssel f0ssel closed this Sep 11, 2025
@f0ssel f0ssel deleted the blink/migrate-env-vars-to-cli branch September 16, 2025 15:52
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