Skip to content

Commit c8916e1

Browse files
chore: do some more defensive programming
1 parent fdedcd1 commit c8916e1

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

coderd/agentapi/subagent.go

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,17 +115,32 @@ func (a *SubAgentAPI) CreateSubAgent(ctx context.Context, req *agentproto.Create
115115
health = database.WorkspaceAppHealthInitializing
116116
}
117117

118-
sharingLevel := database.AppSharingLevelOwner
118+
var sharingLevel database.AppSharingLevel
119119
switch app.GetShare() {
120+
case agentproto.CreateSubAgentRequest_App_OWNER:
121+
sharingLevel = database.AppSharingLevelOwner
120122
case agentproto.CreateSubAgentRequest_App_AUTHENTICATED:
121123
sharingLevel = database.AppSharingLevelAuthenticated
122124
case agentproto.CreateSubAgentRequest_App_PUBLIC:
123125
sharingLevel = database.AppSharingLevelPublic
126+
default:
127+
return codersdk.ValidationError{
128+
Field: "share",
129+
Detail: fmt.Sprint("%q is not a valid app sharing level"),
130+
}
124131
}
125132

126-
openIn := database.WorkspaceAppOpenInSlimWindow
127-
if app.GetOpenIn() == agentproto.CreateSubAgentRequest_App_TAB {
133+
var openIn database.WorkspaceAppOpenIn
134+
switch app.GetOpenIn() {
135+
case agentproto.CreateSubAgentRequest_App_SLIM_WINDOW:
136+
openIn = database.WorkspaceAppOpenInSlimWindow
137+
case agentproto.CreateSubAgentRequest_App_TAB:
128138
openIn = database.WorkspaceAppOpenInTab
139+
default:
140+
return codersdk.ValidationError{
141+
Field: "open_in",
142+
Detail: fmt.Sprint("%q is not an open in setting"),
143+
}
129144
}
130145

131146
_, err := a.Database.InsertWorkspaceApp(ctx, database.InsertWorkspaceAppParams{

0 commit comments

Comments
 (0)