Skip to content

Commit 04872d2

Browse files
committed
update subagent api
1 parent ae27911 commit 04872d2

File tree

1 file changed

+6
-10
lines changed

1 file changed

+6
-10
lines changed

coderd/agentapi/subagent.go

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"database/sql"
66
"errors"
77
"fmt"
8+
"strings"
89

910
"github.com/google/uuid"
1011
"github.com/sqlc-dev/pqtype"
@@ -140,20 +141,15 @@ func (a *SubAgentAPI) CreateSubAgent(ctx context.Context, req *agentproto.Create
140141
health = database.WorkspaceAppHealthInitializing
141142
}
142143

143-
var sharingLevel database.AppSharingLevel
144-
switch app.GetShare() {
145-
case agentproto.CreateSubAgentRequest_App_OWNER:
146-
sharingLevel = database.AppSharingLevelOwner
147-
case agentproto.CreateSubAgentRequest_App_AUTHENTICATED:
148-
sharingLevel = database.AppSharingLevelAuthenticated
149-
case agentproto.CreateSubAgentRequest_App_PUBLIC:
150-
sharingLevel = database.AppSharingLevelPublic
151-
default:
144+
share := app.GetShare()
145+
protoSharingLevel, ok := agentproto.CreateSubAgentRequest_App_SharingLevel_name[int32(share)]
146+
if !ok {
152147
return codersdk.ValidationError{
153148
Field: "share",
154-
Detail: fmt.Sprintf("%q is not a valid app sharing level", app.GetShare()),
149+
Detail: fmt.Sprintf("%q is not a valid app sharing level", share.String()),
155150
}
156151
}
152+
sharingLevel := database.AppSharingLevel(strings.ToLower(protoSharingLevel))
157153

158154
var openIn database.WorkspaceAppOpenIn
159155
switch app.GetOpenIn() {

0 commit comments

Comments
 (0)