Skip to content

Commit 0f3552f

Browse files
committed
poc
1 parent 83a98be commit 0f3552f

File tree

13 files changed

+142
-68
lines changed

13 files changed

+142
-68
lines changed

components/ide-service/pkg/server/server.go

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -301,10 +301,11 @@ func grpcProbe(cfg baseserver.ServerConfiguration) func() error {
301301
}
302302

303303
type IDESettings struct {
304-
DefaultIde string `json:"defaultIde,omitempty"`
305-
UseLatestVersion bool `json:"useLatestVersion,omitempty"`
306-
PreferToolbox bool `json:"preferToolbox,omitempty"`
307-
PinnedIDEversions map[string]string `json:"pinnedIDEversions,omitempty"`
304+
DefaultIde string `json:"defaultIde,omitempty"`
305+
UseLatestVersion bool `json:"useLatestVersion,omitempty"`
306+
PreferToolbox bool `json:"preferToolbox,omitempty"`
307+
PinnedIDEversions map[string]string `json:"pinnedIDEversions,omitempty"`
308+
RestrictedEditorNames []string `json:"restrictedEditorNames,omitempty"`
308309
}
309310

310311
type WorkspaceContext struct {
@@ -395,6 +396,11 @@ func (s *IDEServiceServer) ResolveWorkspaceConfig(ctx context.Context, req *api.
395396
}
396397

397398
pinnedIDEversions := make(map[string]string)
399+
restrictedEditorNames := make(map[string]struct{})
400+
401+
for _, editorName := range ideSettings.RestrictedEditorNames {
402+
restrictedEditorNames[editorName] = struct{}{}
403+
}
398404

399405
if ideSettings != nil {
400406
pinnedIDEversions = ideSettings.PinnedIDEversions
@@ -482,6 +488,11 @@ func (s *IDEServiceServer) ResolveWorkspaceConfig(ctx context.Context, req *api.
482488
resp.WebImage = getUserIDEImage(ideConfig.IdeOptions.DefaultIde, useLatest)
483489
resp.IdeImageLayers = getUserImageLayers(ideConfig.IdeOptions.DefaultIde, useLatest)
484490

491+
if _, ok := restrictedEditorNames["code"]; ok {
492+
resp.WebImage = ""
493+
resp.IdeImageLayers = []string{}
494+
}
495+
485496
var desktopImageLayer string
486497
var desktopUserImageLayers []string
487498
if chosenIDE.Type == config.IDETypeDesktop {

components/server/src/ide-service.spec.ts

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,19 @@ const expect = chai.expect;
1313
describe("ide-service", function () {
1414
describe("migrateSettings", function () {
1515
const ideService = new IDEService();
16-
it("with no ideSettings should be undefined", function () {
16+
it("with no ideSettings should be undefined", async function () {
1717
const user: User = {
1818
id: "string",
1919

2020
creationDate: "string",
2121
identities: [],
2222
additionalData: {},
2323
};
24-
const result = ideService.migrateSettings(user);
24+
const result = await ideService.migrateSettings(user);
2525
expect(result).to.undefined;
2626
});
2727

28-
it("with settingVersion 2.0 should be latest", function () {
28+
it("with settingVersion 2.0 should be latest", async function () {
2929
const user: User = {
3030
id: "string",
3131
creationDate: "string",
@@ -38,15 +38,15 @@ describe("ide-service", function () {
3838
},
3939
},
4040
};
41-
const result = ideService.migrateSettings(user);
41+
const result = await ideService.migrateSettings(user);
4242
expect(result).to.deep.equal({
4343
settingVersion: IDESettingsVersion,
4444
defaultIde: "code",
4545
useLatestVersion: true,
4646
});
4747
});
4848

49-
it("with settingVersion 2.0 should be latest and remove intellij-previous", function () {
49+
it("with settingVersion 2.0 should be latest and remove intellij-previous", async function () {
5050
const user: User = {
5151
id: "string",
5252
creationDate: "string",
@@ -59,15 +59,15 @@ describe("ide-service", function () {
5959
},
6060
},
6161
};
62-
const result = ideService.migrateSettings(user);
62+
const result = await ideService.migrateSettings(user);
6363
expect(result).to.deep.equal({
6464
settingVersion: IDESettingsVersion,
6565
defaultIde: "code",
6666
useLatestVersion: false,
6767
});
6868
});
6969

70-
it("with settingVersion latest should be undefined", function () {
70+
it("with settingVersion latest should be undefined", async function () {
7171
const user: User = {
7272
id: "string",
7373
creationDate: "string",
@@ -80,11 +80,11 @@ describe("ide-service", function () {
8080
},
8181
},
8282
};
83-
const result = ideService.migrateSettings(user);
83+
const result = await ideService.migrateSettings(user);
8484
expect(result).to.undefined;
8585
});
8686

87-
it("with code-latest should be code latest", function () {
87+
it("with code-latest should be code latest", async function () {
8888
const user: User = {
8989
id: "string",
9090
creationDate: "string",
@@ -96,12 +96,12 @@ describe("ide-service", function () {
9696
},
9797
},
9898
};
99-
const result = ideService.migrateSettings(user);
99+
const result = await ideService.migrateSettings(user);
100100
expect(result?.defaultIde).to.equal("code");
101101
expect(result?.useLatestVersion ?? false).to.be.true;
102102
});
103103

104-
it("with code-desktop-insiders should be code-desktop latest", function () {
104+
it("with code-desktop-insiders should be code-desktop latest", async function () {
105105
const user: User = {
106106
id: "string",
107107
creationDate: "string",
@@ -114,12 +114,12 @@ describe("ide-service", function () {
114114
},
115115
},
116116
};
117-
const result = ideService.migrateSettings(user);
117+
const result = await ideService.migrateSettings(user);
118118
expect(result?.defaultIde).to.equal("code-desktop");
119119
expect(result?.useLatestVersion ?? false).to.be.true;
120120
});
121121

122-
it("with code-desktop should be code-desktop", function () {
122+
it("with code-desktop should be code-desktop", async function () {
123123
const user: User = {
124124
id: "string",
125125
creationDate: "string",
@@ -132,12 +132,12 @@ describe("ide-service", function () {
132132
},
133133
},
134134
};
135-
const result = ideService.migrateSettings(user);
135+
const result = await ideService.migrateSettings(user);
136136
expect(result?.defaultIde).to.equal("code-desktop");
137137
expect(result?.useLatestVersion ?? false).to.be.false;
138138
});
139139

140-
it("with intellij should be intellij", function () {
140+
it("with intellij should be intellij", async function () {
141141
const user: User = {
142142
id: "string",
143143
creationDate: "string",
@@ -151,12 +151,12 @@ describe("ide-service", function () {
151151
},
152152
},
153153
};
154-
const result = ideService.migrateSettings(user);
154+
const result = await ideService.migrateSettings(user);
155155
expect(result?.defaultIde).to.equal("intellij");
156156
expect(result?.useLatestVersion ?? false).to.be.false;
157157
});
158158

159-
it("with intellij latest version should be intellij latest", function () {
159+
it("with intellij latest version should be intellij latest", async function () {
160160
const user: User = {
161161
id: "string",
162162
creationDate: "string",
@@ -170,12 +170,12 @@ describe("ide-service", function () {
170170
},
171171
},
172172
};
173-
const result = ideService.migrateSettings(user);
173+
const result = await ideService.migrateSettings(user);
174174
expect(result?.defaultIde).to.equal("intellij");
175175
expect(result?.useLatestVersion ?? false).to.be.true;
176176
});
177177

178-
it("with user desktopIde false should be code latest", function () {
178+
it("with user desktopIde false should be code latest", async function () {
179179
const user: User = {
180180
id: "string",
181181
creationDate: "string",
@@ -189,7 +189,7 @@ describe("ide-service", function () {
189189
},
190190
},
191191
};
192-
const result = ideService.migrateSettings(user);
192+
const result = await ideService.migrateSettings(user);
193193
expect(result?.defaultIde).to.equal("code");
194194
expect(result?.useLatestVersion ?? false).to.be.true;
195195
});

components/server/src/ide-service.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ interface ExtendedIDEOptions extends Omit<IDEOptions, "options"> {
3333

3434
export interface ExtendedIDESettings extends IDESettings {
3535
pinnedIDEversions?: { [key: string]: string };
36+
restrictedEditorNames?: string[];
3637
}
3738

3839
export interface IDEConfig {
@@ -75,7 +76,7 @@ export class IDEService {
7576
return Object.keys(config.ideOptions.options).includes(ide);
7677
}
7778

78-
migrateSettings(user: User): IDESettings | undefined {
79+
async migrateSettings(user: User): Promise<IDESettings | undefined> {
7980
if (
8081
!user?.additionalData?.ideSettings ||
8182
user.additionalData.ideSettings.settingVersion === IDESettingsVersion
@@ -102,7 +103,7 @@ export class IDEService {
102103
newIDESettings.useLatestVersion = useLatest;
103104
}
104105

105-
if (ideSettings.defaultIde && !this.isIDEAvailable(ideSettings.defaultIde, { user })) {
106+
if (ideSettings.defaultIde && !(await this.isIDEAvailable(ideSettings.defaultIde, { user }))) {
106107
ideSettings.defaultIde = "code";
107108
}
108109
return newIDESettings;
@@ -117,7 +118,10 @@ export class IDEService {
117118
workspace.type === "prebuild" ? IdeServiceApi.WorkspaceType.PREBUILD : IdeServiceApi.WorkspaceType.REGULAR;
118119

119120
// in case users have `auto-start` options set
120-
if (userSelectedIdeSettings?.defaultIde && !this.isIDEAvailable(userSelectedIdeSettings.defaultIde, { user })) {
121+
if (
122+
userSelectedIdeSettings?.defaultIde &&
123+
!(await this.isIDEAvailable(userSelectedIdeSettings.defaultIde, { user }))
124+
) {
121125
userSelectedIdeSettings.defaultIde = "code";
122126
}
123127

components/server/src/workspace/workspace-service.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -863,6 +863,12 @@ export class WorkspaceService {
863863
options.ideSettings.pinnedIDEversions = orgSettings.pinnedEditorVersions;
864864
}
865865

866+
if (orgSettings.restrictedEditorNames) {
867+
if (!options.ideSettings) {
868+
options.ideSettings = {};
869+
}
870+
options.ideSettings.restrictedEditorNames = orgSettings.restrictedEditorNames;
871+
}
866872
// at this point we're about to actually start a new workspace
867873
const result = await this.workspaceStarter.startWorkspace(ctx, workspace, user, await projectPromise, options);
868874
this.asyncUpdateDeletionEligibilityTime(user.id, workspaceId, true);

components/server/src/workspace/workspace-starter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,7 @@ export class WorkspaceStarter {
458458
) {
459459
const span = TraceContext.startSpan("resolveIDEConfiguration", ctx);
460460
try {
461-
const migrated = this.ideService.migrateSettings(user);
461+
const migrated = await this.ideService.migrateSettings(user);
462462
if (user.additionalData?.ideSettings && migrated) {
463463
user.additionalData.ideSettings = migrated;
464464
}

components/supervisor/pkg/supervisor/config.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ const supervisorConfigFile = "supervisor-config.json"
4141
// Config configures supervisor.
4242
type Config struct {
4343
StaticConfig
44-
IDE IDEConfig
44+
IDE *IDEConfig
4545
DesktopIDEs []*IDEConfig
4646
WorkspaceConfig
4747
}
@@ -573,9 +573,12 @@ func GetConfig() (*Config, error) {
573573
return nil, err
574574
}
575575

576-
ide, err := loadIDEConfigFromFile(static.IDEConfigLocation)
577-
if err != nil {
578-
return nil, err
576+
var ide *IDEConfig
577+
if _, err := os.Stat(static.IDEConfigLocation); !os.IsNotExist(err) {
578+
ide, err = loadIDEConfigFromFile(static.IDEConfigLocation)
579+
if err != nil {
580+
return nil, err
581+
}
579582
}
580583
desktopIDEs, err := loadDesktopIDEs(static)
581584
if err != nil {
@@ -589,7 +592,7 @@ func GetConfig() (*Config, error) {
589592

590593
return &Config{
591594
StaticConfig: *static,
592-
IDE: *ide,
595+
IDE: ide,
593596
DesktopIDEs: desktopIDEs,
594597
WorkspaceConfig: *workspace,
595598
}, nil

components/supervisor/pkg/supervisor/services.go

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -141,17 +141,20 @@ func (s *statusService) SupervisorStatus(ctx context.Context, req *api.Superviso
141141

142142
func (s *statusService) IDEStatus(ctx context.Context, req *api.IDEStatusRequest) (*api.IDEStatusResponse, error) {
143143
if req.Wait {
144-
select {
145-
case <-s.ideReady.Wait():
146-
{
147-
// do nothing
148-
}
149-
case <-ctx.Done():
150-
if errors.Is(ctx.Err(), context.Canceled) {
151-
return nil, status.Error(codes.Canceled, "execution canceled")
152-
}
144+
if s.ideReady != nil {
153145

154-
return nil, status.Error(codes.DeadlineExceeded, ctx.Err().Error())
146+
select {
147+
case <-s.ideReady.Wait():
148+
{
149+
// do nothing
150+
}
151+
case <-ctx.Done():
152+
if errors.Is(ctx.Err(), context.Canceled) {
153+
return nil, status.Error(codes.Canceled, "execution canceled")
154+
}
155+
156+
return nil, status.Error(codes.DeadlineExceeded, ctx.Err().Error())
157+
}
155158
}
156159

157160
if s.desktopIdeReady != nil {
@@ -169,8 +172,10 @@ func (s *statusService) IDEStatus(ctx context.Context, req *api.IDEStatusRequest
169172
}
170173
}
171174
}
172-
173-
ok, _ := s.ideReady.Get()
175+
ok := true
176+
if s.ideReady != nil {
177+
ok, _ = s.ideReady.Get()
178+
}
174179
desktopStatus := &api.IDEStatusResponse_DesktopStatus{}
175180
if s.desktopIdeReady != nil {
176181
okR, i := s.desktopIdeReady.Get()

0 commit comments

Comments
 (0)