MCPcopy Index your code
hub / github.com/coder/coder / getWorkspaceAgent

Function getWorkspaceAgent

codersdk/toolsdk/bash.go:244–275  ·  view source on GitHub ↗

getWorkspaceAgent finds the specified agent in the workspace

(workspace codersdk.Workspace, agentName string)

Source from the content-addressed store, hash-verified

242
243// getWorkspaceAgent finds the specified agent in the workspace
244func getWorkspaceAgent(workspace codersdk.Workspace, agentName string) (codersdk.WorkspaceAgent, error) {
245 resources := workspace.LatestBuild.Resources
246
247 var agents []codersdk.WorkspaceAgent
248 var availableNames []string
249
250 for _, resource := range resources {
251 for _, agent := range resource.Agents {
252 availableNames = append(availableNames, agent.Name)
253 agents = append(agents, agent)
254 }
255 }
256
257 if len(agents) == 0 {
258 return codersdk.WorkspaceAgent{}, xerrors.Errorf("workspace %q has no agents", workspace.Name)
259 }
260
261 if agentName != "" {
262 for _, agent := range agents {
263 if agent.Name == agentName || agent.ID.String() == agentName {
264 return agent, nil
265 }
266 }
267 return codersdk.WorkspaceAgent{}, xerrors.Errorf("agent not found by name %q, available agents: %v", agentName, availableNames)
268 }
269
270 if len(agents) == 1 {
271 return agents[0], nil
272 }
273
274 return codersdk.WorkspaceAgent{}, xerrors.Errorf("multiple agents found, please specify the agent name, available agents: %v", availableNames)
275}
276
277// executeCommandWithTimeout executes a command with timeout support
278func executeCommandWithTimeout(ctx context.Context, session *gossh.Session, command string) ([]byte, error) {

Callers 2

findWorkspaceAndAgentFunction · 0.70
fetchWorkspaceContextMethod · 0.50

Calls 2

ErrorfMethod · 0.45
StringMethod · 0.45

Tested by

no test coverage detected