Skip to content

Commit 00606c9

Browse files
committed
fix some stuff
1 parent 0824457 commit 00606c9

File tree

10 files changed

+47
-29
lines changed

10 files changed

+47
-29
lines changed

coderd/database/models.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/database/queries.sql.go

Lines changed: 9 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/database/sqlc.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ overrides:
2727
- column: "template_with_users.group_acl"
2828
go_type:
2929
type: "TemplateACL"
30+
- column: "workspace_agents.default_apps"
31+
go_type: "github.com/lib/pq.StringArray"
3032
rename:
3133
template: TemplateTable
3234
template_with_user: Template

coderd/oauthpki/oidcpki.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"encoding/base64"
99
"encoding/json"
1010
"encoding/pem"
11-
"fmt"
1211
"io"
1312
"net/http"
1413
"net/url"
@@ -243,7 +242,7 @@ func (src *jwtTokenSource) Token() (*oauth2.Token, error) {
243242
}
244243

245244
if unmarshalError != nil {
246-
return nil, fmt.Errorf("oauth2: cannot unmarshal token: %w", err)
245+
return nil, xerrors.Errorf("oauth2: cannot unmarshal token: %w", err)
247246
}
248247

249248
newToken := &oauth2.Token{
@@ -264,7 +263,7 @@ func (src *jwtTokenSource) Token() (*oauth2.Token, error) {
264263
// decode returned id token to get expiry
265264
claimSet, err := jws.Decode(v)
266265
if err != nil {
267-
return nil, fmt.Errorf("oauth2: error decoding JWT token: %w", err)
266+
return nil, xerrors.Errorf("oauth2: error decoding JWT token: %w", err)
268267
}
269268
newToken.Expiry = time.Unix(claimSet.Exp, 0)
270269
}

coderd/provisionerdserver/provisionerdserver.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import (
3838
"github.com/coder/coder/v2/coderd/tracing"
3939
"github.com/coder/coder/v2/codersdk"
4040
"github.com/coder/coder/v2/provisioner"
41+
"github.com/coder/coder/v2/provisioner/terraform"
4142
"github.com/coder/coder/v2/provisionerd/proto"
4243
"github.com/coder/coder/v2/provisionersdk"
4344
sdkproto "github.com/coder/coder/v2/provisionersdk/proto"
@@ -1185,6 +1186,10 @@ func InsertWorkspaceResource(ctx context.Context, db database.Store, jobID uuid.
11851186
prAgent.StartupScriptBehavior = string(codersdk.WorkspaceAgentStartupScriptBehaviorNonBlocking)
11861187
}
11871188

1189+
if slices.Contains(prAgent.DefaultApps, terraform.AllDefaultApps) {
1190+
prAgent.DefaultApps = nil
1191+
}
1192+
11881193
agentID := uuid.New()
11891194
dbAgent, err := db.InsertWorkspaceAgent(ctx, database.InsertWorkspaceAgentParams{
11901195
ID: agentID,

coderd/workspaceagents.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
"github.com/bep/debounce"
2525
"github.com/go-chi/chi/v5"
2626
"github.com/google/uuid"
27+
"github.com/lib/pq"
2728
"golang.org/x/exp/slices"
2829
"golang.org/x/mod/semver"
2930
"golang.org/x/sync/errgroup"
@@ -1398,7 +1399,11 @@ func convertWorkspaceAgent(derpMap *tailcfg.DERPMap, coordinator tailnet.Coordin
13981399
return workspaceAgent, nil
13991400
}
14001401

1401-
func convertDefaultApps(apps []string) []codersdk.DefaultApp {
1402+
func convertDefaultApps(apps pq.StringArray) []codersdk.DefaultApp {
1403+
if apps == nil {
1404+
return codersdk.DefaultApps
1405+
}
1406+
14021407
dapps := make([]codersdk.DefaultApp, 0, len(apps))
14031408
for _, app := range apps {
14041409
switch codersdk.DefaultApp(app) {

codersdk/workspaceagents.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,8 @@ const (
143143
DefaultAppSSH DefaultApp = "ssh-helper"
144144
)
145145

146+
var DefaultApps = []DefaultApp{DefaultAppVSCodeDesktop, DefaultAppWebTerminal, DefaultAppPortForward, DefaultAppWebTerminal, DefaultAppSSH}
147+
146148
type WorkspaceAgent struct {
147149
ID uuid.UUID `json:"id" format:"uuid"`
148150
CreatedAt time.Time `json:"created_at" format:"date-time"`

provisioner/terraform/resources.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ import (
1818
"github.com/coder/coder/v2/provisionersdk/proto"
1919
)
2020

21+
// AllDefaultApps denotes an agent resource that does not explicitly
22+
// specify a value for the 'default_apps' field. Protobuf does not distinguish
23+
// between an empty array and a nil array necessitating this special token.
24+
const AllDefaultApps = "*"
25+
2126
type agentMetadata struct {
2227
Key string `mapstructure:"key"`
2328
DisplayName string `mapstructure:"display_name"`
@@ -183,7 +188,7 @@ func ConvertState(modules []*tfjson.StateModule, rawGraph string) (*State, error
183188
})
184189
}
185190

186-
var defaultApps = []string{"*"}
191+
defaultApps := []string{AllDefaultApps}
187192
if attrs.DefaultApps != nil {
188193
defaultApps = *attrs.DefaultApps
189194
}

site/src/components/Resources/AgentRow.tsx

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -171,17 +171,6 @@ export const AgentRow: FC<AgentRowProps> = ({
171171
[logListDivRef],
172172
)
173173

174-
const containsDefaultApp = (
175-
agent: WorkspaceAgent,
176-
name: DefaultApp,
177-
): boolean => {
178-
if (agent.default_apps.length == 0) {
179-
return false
180-
}
181-
182-
return agent.default_apps.includes(name)
183-
}
184-
185174
return (
186175
<Stack
187176
key={agent.id}
@@ -231,13 +220,15 @@ export const AgentRow: FC<AgentRowProps> = ({
231220
<div className={styles.agentButtons}>
232221
{shouldDisplayApps && (
233222
<>
234-
{containsDefaultApp(agent, "vscode-desktop") &&
223+
{(agent.default_apps.includes("vscode-desktop") ||
224+
agent.default_apps.includes("vscode-insiders")) &&
235225
!hideVSCodeDesktopButton && (
236226
<VSCodeDesktopButton
237227
userName={workspace.owner_name}
238228
workspaceName={workspace.name}
239229
agentName={agent.name}
240230
folderPath={agent.expanded_directory}
231+
defaultApps={agent.default_apps}
241232
/>
242233
)}
243234
{agent.apps.map((app) => (

site/src/components/VSCodeDesktopButton/VSCodeDesktopButton.tsx

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,14 @@ import ButtonGroup from "@mui/material/ButtonGroup"
88
import { useLocalStorage } from "hooks"
99
import Menu from "@mui/material/Menu"
1010
import MenuItem from "@mui/material/MenuItem"
11+
import { DefaultApp } from "api/typesGenerated"
1112

1213
export interface VSCodeDesktopButtonProps {
1314
userName: string
1415
workspaceName: string
1516
agentName?: string
1617
folderPath?: string
18+
defaultApps: DefaultApp[]
1719
}
1820

1921
type VSCodeVariant = "vscode" | "vscode-insiders"
@@ -40,13 +42,16 @@ export const VSCodeDesktopButton: FC<
4042
setIsVariantMenuOpen(false)
4143
}
4244

43-
return (
45+
const includesVSCodeDestop = props.defaultApps.includes("vscode-desktop")
46+
const includesVSCodeInsiders = props.defaultApps.includes("vscode-insiders")
47+
48+
return includesVSCodeDestop && includesVSCodeInsiders ? (
4449
<div>
4550
<ButtonGroup
4651
ref={menuAnchorRef}
4752
variant="outlined"
4853
sx={{
49-
// Workaround to make the border transitions smmothly on button groups
54+
// Workaround to make the border transitions smoothly on button groups
5055
"& > button:hover + button": {
5156
borderLeft: "1px solid #FFF",
5257
},
@@ -105,6 +110,10 @@ export const VSCodeDesktopButton: FC<
105110
</MenuItem>
106111
</Menu>
107112
</div>
113+
) : includesVSCodeDestop ? (
114+
<VSCodeButton {...props} />
115+
) : (
116+
<VSCodeInsidersButton {...props} />
108117
)
109118
}
110119

0 commit comments

Comments
 (0)