Skip to content

Refactor terminal and service classes#4

Merged
eggy03 merged 5 commits into
masterfrom
refactor-terminal-and-service
Apr 21, 2026
Merged

Refactor terminal and service classes#4
eggy03 merged 5 commits into
masterfrom
refactor-terminal-and-service

Conversation

@eggy03
Copy link
Copy Markdown
Owner

@eggy03 eggy03 commented Apr 21, 2026

Description

This PR includes security improvements regarding arbitrary command execution in the terminal, and service refactors to improve
mocking of dependencies via injection, in tests, for the upcoming test rewrites.

Type of Change

Refactor

  • Change getCommandFor() to an instance method getCommand(), in DMIType.
  • Rename TerminalUtility to TerminalService and refactored it to become an instance based class from utility class and reduced the possibility of arbitrary command execution.
  • Refactor service classes to allow dependency injection of TerminalService and mappers.
  • Rename DMIPortConnectionInformationMapper to DMIPortConnectorInformationMapper.
  • Introduce default method configureObjectMapper() to allow custom ObjectMapper configuration in CommonDMIMapper interface.

eggy03 added 5 commits April 21, 2026 11:06
- Change `getCommandFor` to an instance method `getCommand`
- Add `@NonNull` annotation to the return type of `getCommand`

Signed-off-by: Egg-03 <111327101+eggy03@users.noreply.github.com>
- Rename `TerminalExecutionException` to `TerminalIOException`.
- Introduce a new class `TerminalResult` to encapsulate both stdout and stderr from terminal execution.
- Update `TerminalUtility` (renamed to `TerminalService`) to return `TerminalResult` instead of a raw string.
- Modify the `execute` method to handle and return both stdout and stderr. It has also been made package private to reduce arbitrary command execution
- Update the exception handling to throw `TerminalIOException` for I/O errors.
- Add a new method `executeCommand` to `TerminalService` for executing specific DMI commands originating from the `DMIType` enum.

Signed-off-by: Egg-03 <111327101+eggy03@users.noreply.github.com>
…orInformationMapper

Signed-off-by: Egg-03 <111327101+eggy03@users.noreply.github.com>
- introduce `configureObjectMapper` method to allow custom ObjectMapper configuration
- use `configureObjectMapper` to create `jacksonMapper` instance in `map` and `mapList` methods

Signed-off-by: Egg-03 <111327101+eggy03@users.noreply.github.com>
- Replace direct instantiation of `TerminalUtility` and mappers with dependency injection of `TerminalService` and specific mappers.
- Introduce package-private constructors to facilitate dependency injection.
- Update `get` methods to utilize the injected `TerminalService` and mappers.
- Add `Objects.requireNonNull` checks for injected dependencies to ensure non-nullability.
- This change improves testability and maintainability by decoupling service classes from their dependencies, for the upcoming test rewrite

Signed-off-by: Egg-03 <111327101+eggy03@users.noreply.github.com>
@eggy03 eggy03 merged commit e66fce5 into master Apr 21, 2026
1 check failed
@eggy03 eggy03 deleted the refactor-terminal-and-service branch April 21, 2026 07:27
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