(derpMap *tailcfg.DERPMap, coordinator tailnet.Coordinator, dbAgent database.WorkspaceAgent, apps []codersdk.WorkspaceApp, scripts []codersdk.WorkspaceAgentScript, logSources []codersdk.WorkspaceAgentLogSource, agentInactiveDisconnectTimeout time.Duration, agentFallbackTroubleshootingURL string, )
| 518 | } |
| 519 | |
| 520 | func WorkspaceAgent(derpMap *tailcfg.DERPMap, coordinator tailnet.Coordinator, |
| 521 | dbAgent database.WorkspaceAgent, apps []codersdk.WorkspaceApp, scripts []codersdk.WorkspaceAgentScript, logSources []codersdk.WorkspaceAgentLogSource, |
| 522 | agentInactiveDisconnectTimeout time.Duration, agentFallbackTroubleshootingURL string, |
| 523 | ) (codersdk.WorkspaceAgent, error) { |
| 524 | envs, err := WorkspaceAgentEnvironment(dbAgent) |
| 525 | if err != nil { |
| 526 | return codersdk.WorkspaceAgent{}, err |
| 527 | } |
| 528 | troubleshootingURL := agentFallbackTroubleshootingURL |
| 529 | if dbAgent.TroubleshootingURL != "" { |
| 530 | troubleshootingURL = dbAgent.TroubleshootingURL |
| 531 | } |
| 532 | subsystems := make([]codersdk.AgentSubsystem, len(dbAgent.Subsystems)) |
| 533 | for i, subsystem := range dbAgent.Subsystems { |
| 534 | subsystems[i] = codersdk.AgentSubsystem(subsystem) |
| 535 | } |
| 536 | |
| 537 | legacyStartupScriptBehavior := codersdk.WorkspaceAgentStartupScriptBehaviorNonBlocking |
| 538 | for _, script := range scripts { |
| 539 | if !script.RunOnStart { |
| 540 | continue |
| 541 | } |
| 542 | if !script.StartBlocksLogin { |
| 543 | continue |
| 544 | } |
| 545 | legacyStartupScriptBehavior = codersdk.WorkspaceAgentStartupScriptBehaviorBlocking |
| 546 | } |
| 547 | |
| 548 | workspaceAgent := codersdk.WorkspaceAgent{ |
| 549 | ID: dbAgent.ID, |
| 550 | ParentID: dbAgent.ParentID, |
| 551 | CreatedAt: dbAgent.CreatedAt, |
| 552 | UpdatedAt: dbAgent.UpdatedAt, |
| 553 | ResourceID: dbAgent.ResourceID, |
| 554 | InstanceID: dbAgent.AuthInstanceID.String, |
| 555 | Name: dbAgent.Name, |
| 556 | Architecture: dbAgent.Architecture, |
| 557 | OperatingSystem: dbAgent.OperatingSystem, |
| 558 | Scripts: scripts, |
| 559 | StartupScriptBehavior: legacyStartupScriptBehavior, |
| 560 | LogsLength: dbAgent.LogsLength, |
| 561 | LogsOverflowed: dbAgent.LogsOverflowed, |
| 562 | LogSources: logSources, |
| 563 | Version: dbAgent.Version, |
| 564 | APIVersion: dbAgent.APIVersion, |
| 565 | EnvironmentVariables: envs, |
| 566 | Directory: dbAgent.Directory, |
| 567 | ExpandedDirectory: dbAgent.ExpandedDirectory, |
| 568 | Apps: apps, |
| 569 | ConnectionTimeoutSeconds: dbAgent.ConnectionTimeoutSeconds, |
| 570 | TroubleshootingURL: troubleshootingURL, |
| 571 | LifecycleState: codersdk.WorkspaceAgentLifecycle(dbAgent.LifecycleState), |
| 572 | Subsystems: subsystems, |
| 573 | DisplayApps: convertDisplayApps(dbAgent.DisplayApps), |
| 574 | } |
| 575 | node := coordinator.Node(dbAgent.ID) |
| 576 | if node != nil { |
| 577 | workspaceAgent.DERPLatency = map[string]codersdk.DERPRegion{} |
no test coverage detected