Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitd29a524

Browse files
author
Rafael Rodriguez
authored
feat: remove agent name from app URLs (#19750)
## SummaryIn this pull request we're removing `agent_name` from subdomains in APPurls when an `app` is used in the subdomain. `agent_names` will still beused when a `port` is used in the subdomain.Closes:#18485### Changes- Updated regex to support an optional agent name- Added logic to support checking the app slug for a matching port(e.g., 8080 or 8080s)### Testing- Updated all tests to support an optional `agent_name`
1 parent403a9e5 commitd29a524

File tree

6 files changed

+359
-99
lines changed

6 files changed

+359
-99
lines changed

‎coderd/agentapi/manifest.go‎

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ func (a *ManifestAPI) GetManifest(ctx context.Context, _ *agentproto.GetManifest
110110
}
111111
}
112112

113-
apps,err:=dbAppsToProto(dbApps,workspaceAgent,workspace.OwnerUsername,workspace)
113+
apps,err:=dbAppsToProto(dbApps,workspaceAgent,workspace.OwnerUsername,workspace,a.AppHostname)
114114
iferr!=nil {
115115
returnnil,xerrors.Errorf("converting workspace apps: %w",err)
116116
}
@@ -196,19 +196,19 @@ func dbAgentScriptToProto(script database.WorkspaceAgentScript) *agentproto.Work
196196
}
197197
}
198198

199-
funcdbAppsToProto(dbApps []database.WorkspaceApp,agent database.WorkspaceAgent,ownerNamestring,workspace database.Workspace) ([]*agentproto.WorkspaceApp,error) {
199+
funcdbAppsToProto(dbApps []database.WorkspaceApp,agent database.WorkspaceAgent,ownerNamestring,workspace database.Workspace,appHostnamestring) ([]*agentproto.WorkspaceApp,error) {
200200
ret:=make([]*agentproto.WorkspaceApp,len(dbApps))
201201
fori,dbApp:=rangedbApps {
202202
varerrerror
203-
ret[i],err=dbAppToProto(dbApp,agent,ownerName,workspace)
203+
ret[i],err=dbAppToProto(dbApp,agent,ownerName,workspace,appHostname)
204204
iferr!=nil {
205205
returnnil,xerrors.Errorf("parse app %v (%q): %w",i,dbApp.Slug,err)
206206
}
207207
}
208208
returnret,nil
209209
}
210210

211-
funcdbAppToProto(dbApp database.WorkspaceApp,agent database.WorkspaceAgent,ownerNamestring,workspace database.Workspace) (*agentproto.WorkspaceApp,error) {
211+
funcdbAppToProto(dbApp database.WorkspaceApp,agent database.WorkspaceAgent,ownerNamestring,workspace database.Workspace,appHostnamestring) (*agentproto.WorkspaceApp,error) {
212212
sharingLevelRaw,ok:=agentproto.WorkspaceApp_SharingLevel_value[strings.ToUpper(string(dbApp.SharingLevel))]
213213
if!ok {
214214
returnnil,xerrors.Errorf("unknown app sharing level: %q",dbApp.SharingLevel)
@@ -219,6 +219,12 @@ func dbAppToProto(dbApp database.WorkspaceApp, agent database.WorkspaceAgent, ow
219219
returnnil,xerrors.Errorf("unknown app health: %q",dbApp.SharingLevel)
220220
}
221221

222+
// SubdomainName should be empty if AppHostname is not configured
223+
subdomainName:=""
224+
ifappHostname!="" {
225+
subdomainName=db2sdk.AppSubdomain(dbApp,agent.Name,workspace.Name,ownerName)
226+
}
227+
222228
return&agentproto.WorkspaceApp{
223229
Id:dbApp.ID[:],
224230
Url:dbApp.Url.String,
@@ -228,7 +234,7 @@ func dbAppToProto(dbApp database.WorkspaceApp, agent database.WorkspaceAgent, ow
228234
Command:dbApp.Command.String,
229235
Icon:dbApp.Icon,
230236
Subdomain:dbApp.Subdomain,
231-
SubdomainName:db2sdk.AppSubdomain(dbApp,agent.Name,workspace.Name,ownerName),
237+
SubdomainName:subdomainName,
232238
SharingLevel:agentproto.WorkspaceApp_SharingLevel(sharingLevelRaw),
233239
Healthcheck:&agentproto.WorkspaceApp_Healthcheck{
234240
Url:dbApp.HealthcheckUrl,

‎coderd/agentapi/manifest_test.go‎

Lines changed: 120 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -191,65 +191,6 @@ func TestGetManifest(t *testing.T) {
191191
// These are done manually to ensure the conversion logic matches what a
192192
// human expects.
193193
var (
194-
protoApps= []*agentproto.WorkspaceApp{
195-
{
196-
Id:apps[0].ID[:],
197-
Url:apps[0].Url.String,
198-
External:apps[0].External,
199-
Slug:apps[0].Slug,
200-
DisplayName:apps[0].DisplayName,
201-
Command:apps[0].Command.String,
202-
Icon:apps[0].Icon,
203-
Subdomain:apps[0].Subdomain,
204-
SubdomainName:fmt.Sprintf("%s--%s--%s--%s",apps[0].Slug,agent.Name,workspace.Name,owner.Username),
205-
SharingLevel:agentproto.WorkspaceApp_AUTHENTICATED,
206-
Healthcheck:&agentproto.WorkspaceApp_Healthcheck{
207-
Url:apps[0].HealthcheckUrl,
208-
Interval:durationpb.New(time.Duration(apps[0].HealthcheckInterval)*time.Second),
209-
Threshold:apps[0].HealthcheckThreshold,
210-
},
211-
Health:agentproto.WorkspaceApp_HEALTHY,
212-
Hidden:false,
213-
},
214-
{
215-
Id:apps[1].ID[:],
216-
Url:apps[1].Url.String,
217-
External:apps[1].External,
218-
Slug:apps[1].Slug,
219-
DisplayName:apps[1].DisplayName,
220-
Command:apps[1].Command.String,
221-
Icon:apps[1].Icon,
222-
Subdomain:false,
223-
SubdomainName:"",
224-
SharingLevel:agentproto.WorkspaceApp_PUBLIC,
225-
Healthcheck:&agentproto.WorkspaceApp_Healthcheck{
226-
Url:"",
227-
Interval:durationpb.New(0),
228-
Threshold:0,
229-
},
230-
Health:agentproto.WorkspaceApp_DISABLED,
231-
Hidden:false,
232-
},
233-
{
234-
Id:apps[2].ID[:],
235-
Url:apps[2].Url.String,
236-
External:apps[2].External,
237-
Slug:apps[2].Slug,
238-
DisplayName:apps[2].DisplayName,
239-
Command:apps[2].Command.String,
240-
Icon:apps[2].Icon,
241-
Subdomain:false,
242-
SubdomainName:"",
243-
SharingLevel:agentproto.WorkspaceApp_OWNER,
244-
Healthcheck:&agentproto.WorkspaceApp_Healthcheck{
245-
Url:apps[2].HealthcheckUrl,
246-
Interval:durationpb.New(time.Duration(apps[2].HealthcheckInterval)*time.Second),
247-
Threshold:apps[2].HealthcheckThreshold,
248-
},
249-
Health:agentproto.WorkspaceApp_UNHEALTHY,
250-
Hidden:true,
251-
},
252-
}
253194
protoScripts= []*agentproto.WorkspaceAgentScript{
254195
{
255196
Id:scripts[0].ID[:],
@@ -308,6 +249,66 @@ func TestGetManifest(t *testing.T) {
308249
t.Run("OK",func(t*testing.T) {
309250
t.Parallel()
310251

252+
protoApps:= []*agentproto.WorkspaceApp{
253+
{
254+
Id:apps[0].ID[:],
255+
Url:apps[0].Url.String,
256+
External:apps[0].External,
257+
Slug:apps[0].Slug,
258+
DisplayName:apps[0].DisplayName,
259+
Command:apps[0].Command.String,
260+
Icon:apps[0].Icon,
261+
Subdomain:apps[0].Subdomain,
262+
SubdomainName:fmt.Sprintf("%s--%s--%s",apps[0].Slug,workspace.Name,owner.Username),
263+
SharingLevel:agentproto.WorkspaceApp_AUTHENTICATED,
264+
Healthcheck:&agentproto.WorkspaceApp_Healthcheck{
265+
Url:apps[0].HealthcheckUrl,
266+
Interval:durationpb.New(time.Duration(apps[0].HealthcheckInterval)*time.Second),
267+
Threshold:apps[0].HealthcheckThreshold,
268+
},
269+
Health:agentproto.WorkspaceApp_HEALTHY,
270+
Hidden:false,
271+
},
272+
{
273+
Id:apps[1].ID[:],
274+
Url:apps[1].Url.String,
275+
External:apps[1].External,
276+
Slug:apps[1].Slug,
277+
DisplayName:apps[1].DisplayName,
278+
Command:apps[1].Command.String,
279+
Icon:apps[1].Icon,
280+
Subdomain:false,
281+
SubdomainName:"",
282+
SharingLevel:agentproto.WorkspaceApp_PUBLIC,
283+
Healthcheck:&agentproto.WorkspaceApp_Healthcheck{
284+
Url:"",
285+
Interval:durationpb.New(0),
286+
Threshold:0,
287+
},
288+
Health:agentproto.WorkspaceApp_DISABLED,
289+
Hidden:false,
290+
},
291+
{
292+
Id:apps[2].ID[:],
293+
Url:apps[2].Url.String,
294+
External:apps[2].External,
295+
Slug:apps[2].Slug,
296+
DisplayName:apps[2].DisplayName,
297+
Command:apps[2].Command.String,
298+
Icon:apps[2].Icon,
299+
Subdomain:false,
300+
SubdomainName:"",
301+
SharingLevel:agentproto.WorkspaceApp_OWNER,
302+
Healthcheck:&agentproto.WorkspaceApp_Healthcheck{
303+
Url:apps[2].HealthcheckUrl,
304+
Interval:durationpb.New(time.Duration(apps[2].HealthcheckInterval)*time.Second),
305+
Threshold:apps[2].HealthcheckThreshold,
306+
},
307+
Health:agentproto.WorkspaceApp_UNHEALTHY,
308+
Hidden:true,
309+
},
310+
}
311+
311312
mDB:=dbmock.NewMockStore(gomock.NewController(t))
312313

313314
api:=&agentapi.ManifestAPI{
@@ -438,6 +439,66 @@ func TestGetManifest(t *testing.T) {
438439
t.Run("NoAppHostname",func(t*testing.T) {
439440
t.Parallel()
440441

442+
protoApps:= []*agentproto.WorkspaceApp{
443+
{
444+
Id:apps[0].ID[:],
445+
Url:apps[0].Url.String,
446+
External:apps[0].External,
447+
Slug:apps[0].Slug,
448+
DisplayName:apps[0].DisplayName,
449+
Command:apps[0].Command.String,
450+
Icon:apps[0].Icon,
451+
Subdomain:apps[0].Subdomain,
452+
SubdomainName:"",// Empty because AppHostname is empty
453+
SharingLevel:agentproto.WorkspaceApp_AUTHENTICATED,
454+
Healthcheck:&agentproto.WorkspaceApp_Healthcheck{
455+
Url:apps[0].HealthcheckUrl,
456+
Interval:durationpb.New(time.Duration(apps[0].HealthcheckInterval)*time.Second),
457+
Threshold:apps[0].HealthcheckThreshold,
458+
},
459+
Health:agentproto.WorkspaceApp_HEALTHY,
460+
Hidden:false,
461+
},
462+
{
463+
Id:apps[1].ID[:],
464+
Url:apps[1].Url.String,
465+
External:apps[1].External,
466+
Slug:apps[1].Slug,
467+
DisplayName:apps[1].DisplayName,
468+
Command:apps[1].Command.String,
469+
Icon:apps[1].Icon,
470+
Subdomain:false,
471+
SubdomainName:"",
472+
SharingLevel:agentproto.WorkspaceApp_PUBLIC,
473+
Healthcheck:&agentproto.WorkspaceApp_Healthcheck{
474+
Url:"",
475+
Interval:durationpb.New(0),
476+
Threshold:0,
477+
},
478+
Health:agentproto.WorkspaceApp_DISABLED,
479+
Hidden:false,
480+
},
481+
{
482+
Id:apps[2].ID[:],
483+
Url:apps[2].Url.String,
484+
External:apps[2].External,
485+
Slug:apps[2].Slug,
486+
DisplayName:apps[2].DisplayName,
487+
Command:apps[2].Command.String,
488+
Icon:apps[2].Icon,
489+
Subdomain:false,
490+
SubdomainName:"",
491+
SharingLevel:agentproto.WorkspaceApp_OWNER,
492+
Healthcheck:&agentproto.WorkspaceApp_Healthcheck{
493+
Url:apps[2].HealthcheckUrl,
494+
Interval:durationpb.New(time.Duration(apps[2].HealthcheckInterval)*time.Second),
495+
Threshold:apps[2].HealthcheckThreshold,
496+
},
497+
Health:agentproto.WorkspaceApp_UNHEALTHY,
498+
Hidden:true,
499+
},
500+
}
501+
441502
mDB:=dbmock.NewMockStore(gomock.NewController(t))
442503

443504
api:=&agentapi.ManifestAPI{

‎coderd/database/db2sdk/db2sdk.go‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -532,13 +532,20 @@ func AppSubdomain(dbApp database.WorkspaceApp, agentName, workspaceName, ownerNa
532532
ifappSlug=="" {
533533
appSlug=dbApp.DisplayName
534534
}
535+
536+
// Agent name is optional when app slug is present
537+
normalizedAgentName:=agentName
538+
if!appurl.PortRegex.MatchString(appSlug) {
539+
normalizedAgentName=""
540+
}
541+
535542
return appurl.ApplicationURL{
536543
// We never generate URLs with a prefix. We only allow prefixes when
537544
// parsing URLs from the hostname. Users that want this feature can
538545
// write out their own URLs.
539546
Prefix:"",
540547
AppSlugOrPort:appSlug,
541-
AgentName:agentName,
548+
AgentName:normalizedAgentName,
542549
WorkspaceName:workspaceName,
543550
Username:ownerName,
544551
}.String()

‎coderd/workspaceapps/apptest/setup.go‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -159,10 +159,16 @@ func (d *Details) PathAppURL(app App) *url.URL {
159159

160160
// SubdomainAppURL returns the URL for the given subdomain app.
161161
func (d*Details)SubdomainAppURL(appApp)*url.URL {
162+
// Agent name is optional when app slug is present
163+
agentName:=app.AgentName
164+
if!appurl.PortRegex.MatchString(app.AppSlugOrPort) {
165+
agentName=""
166+
}
167+
162168
appHost:= appurl.ApplicationURL{
163169
Prefix:app.Prefix,
164170
AppSlugOrPort:app.AppSlugOrPort,
165-
AgentName:app.AgentName,
171+
AgentName:agentName,
166172
WorkspaceName:app.WorkspaceName,
167173
Username:app.Username,
168174
}
@@ -234,7 +240,7 @@ func setupProxyTestWithFactory(t *testing.T, factory DeploymentFactory, opts *De
234240
details.Apps.Owner=App{
235241
Username:me.Username,
236242
WorkspaceName:workspace.Name,
237-
AgentName:agnt.Name,
243+
AgentName:"",// Agent name is optional when app slug is present
238244
AppSlugOrPort:proxyTestAppNameOwner,
239245
Query:proxyTestAppQuery,
240246
}
@@ -474,7 +480,6 @@ func createWorkspaceWithApps(t *testing.T, client *codersdk.Client, orgID uuid.U
474480
// findProtoApp is needed as the order of apps returned from PG database
475481
// is not guaranteed.
476482
AppSlugOrPort:findProtoApp(t,protoApps,app.Slug).Slug,
477-
AgentName:proxyTestAgentName,
478483
WorkspaceName:workspace.Name,
479484
Username:me.Username,
480485
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp