mirror of
https://github.com/coder/coder.git
synced 2026-06-02 20:48:20 +00:00
feat: integrate new agentexec pkg (#15609)
- Integrates the `agentexec` pkg into the agent and removes the legacy system of iterating over the process tree. It adds some linting rules to hopefully catch future improper uses of `exec.Command` in the package.
This commit is contained in:
@@ -487,3 +487,39 @@ func workspaceActivity(m dsl.Matcher) {
|
||||
!m.File().Name.Matches(`_test\.go$`),
|
||||
).Report("Updating workspace activity should always be done in the workspacestats package.")
|
||||
}
|
||||
|
||||
// noExecInAgent ensures that packages under agent/ don't use exec.Command or
|
||||
// exec.CommandContext directly.
|
||||
//
|
||||
//nolint:unused,deadcode,varnamelen
|
||||
func noExecInAgent(m dsl.Matcher) {
|
||||
m.Import("os/exec")
|
||||
m.Match(
|
||||
`exec.Command($*_)`,
|
||||
`exec.CommandContext($*_)`,
|
||||
).
|
||||
Where(
|
||||
m.File().PkgPath.Matches("/agent/") &&
|
||||
!m.File().PkgPath.Matches("/agentexec") &&
|
||||
!m.File().Name.Matches(`_test\.go$`),
|
||||
).
|
||||
Report("The agent and its subpackages should not use exec.Command or exec.CommandContext directly. Consider using agentexec.CommandContext instead.")
|
||||
}
|
||||
|
||||
// noPTYInAgent ensures that packages under agent/ don't use pty.Command or
|
||||
// pty.CommandContext directly.
|
||||
//
|
||||
//nolint:unused,deadcode,varnamelen
|
||||
func noPTYInAgent(m dsl.Matcher) {
|
||||
m.Import("github.com/coder/coder/v2/pty")
|
||||
m.Match(
|
||||
`pty.Command($*_)`,
|
||||
`pty.CommandContext($*_)`,
|
||||
).
|
||||
Where(
|
||||
m.File().PkgPath.Matches(`/agent/`) &&
|
||||
!m.File().PkgPath.Matches(`/agentexec`) &&
|
||||
!m.File().Name.Matches(`_test\.go$`),
|
||||
).
|
||||
Report("The agent and its subpackages should not use pty.Command or pty.CommandContext directly. Consider using agentexec.PTYCommandContext instead.")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user