-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: browser database name should contain a valid DevWorkspace identi…
…fier (#273) (#274) * fix: use DevWorkspace ID to form browser database identifier Signed-off-by: Vitaliy Gulyy <vgulyy@redhat.com>
- Loading branch information
1 parent
85a5294
commit c16e042
Showing
11 changed files
with
162 additions
and
8 deletions.
There are no files selected for viewing
24 changes: 24 additions & 0 deletions
24
code/src/vs/workbench/services/workspaces/browser/che/devWorkspaceId.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/********************************************************************** | ||
* Copyright (c) 2023 Red Hat, Inc. | ||
* | ||
* This program and the accompanying materials are made | ||
* available under the terms of the Eclipse Public License 2.0 | ||
* which is available at https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
***********************************************************************/ | ||
/* eslint-disable header/header */ | ||
|
||
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
// NOTE: DO NOT CHANGE. Launcher updates this constant on workspace startup | ||
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
const DEVWORKSPACE = "https://{{che-cluster}}.{{host}}/{{namespace}}/{{workspace-name}}/{{port}}/"; | ||
|
||
export function getDevWorkspaceId(): string | undefined { | ||
// checking for "https://" guarantees we apply here the ID set by che-code launcher | ||
if (DEVWORKSPACE && !DEVWORKSPACE.startsWith("https://")) { | ||
return DEVWORKSPACE; | ||
} | ||
|
||
return undefined; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/********************************************************************** | ||
* Copyright (c) 2023 Red Hat, Inc. | ||
* | ||
* This program and the accompanying materials are made | ||
* available under the terms of the Eclipse Public License 2.0 | ||
* which is available at https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
***********************************************************************/ | ||
|
||
import { env } from "process"; | ||
import { FILE_WORKBENCH_WEB_MAIN } from "./files"; | ||
import * as fs from "./fs-extra"; | ||
|
||
const DEVWORKSPACE_ID_MASK = | ||
"https://{{che-cluster}}.{{host}}/{{namespace}}/{{workspace-name}}/{{port}}/"; | ||
|
||
export class DevWorkspaceId { | ||
async configure(): Promise<void> { | ||
console.log("# Setting curent DevWorkspace ID to che-code..."); | ||
|
||
if (!env.DEVWORKSPACE_ID) { | ||
console.log(" > env.DEVWORKSPACE_ID is not set, skip this step"); | ||
return; | ||
} | ||
|
||
console.log(` > apply DevWorkspace ID [${env.DEVWORKSPACE_ID}]`); | ||
|
||
try { | ||
await this.update( | ||
FILE_WORKBENCH_WEB_MAIN, | ||
DEVWORKSPACE_ID_MASK, | ||
env.DEVWORKSPACE_ID | ||
); | ||
} catch (err) { | ||
console.error(`${err.message} Webviews will not work if CDN disabled.`); | ||
} | ||
} | ||
|
||
async update(file: string, text: string, newText: string): Promise<void> { | ||
const content = await fs.readFile(file); | ||
const newContent = content.replace(text, newText); | ||
await fs.writeFile(file, newContent); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/********************************************************************** | ||
* Copyright (c) 2023 Red Hat, Inc. | ||
* | ||
* This program and the accompanying materials are made | ||
* available under the terms of the Eclipse Public License 2.0 | ||
* which is available at https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
***********************************************************************/ | ||
|
||
export const FILE_WORKBENCH_WEB_MAIN = "out/vs/workbench/workbench.web.main.js"; | ||
|
||
export const FILE_EXTENSION_HOST_PROCESS = | ||
"out/vs/workbench/api/node/extensionHostProcess.js"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/********************************************************************** | ||
* Copyright (c) 2023 Red Hat, Inc. | ||
* | ||
* This program and the accompanying materials are made | ||
* available under the terms of the Eclipse Public License 2.0 | ||
* which is available at https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
***********************************************************************/ | ||
|
||
import * as fs from "../src/fs-extra"; | ||
import { env } from "process"; | ||
|
||
import { DevWorkspaceId } from "../src/devworkspace-id"; | ||
|
||
const ORIGIN_WORKBENCH_WEB_MAIN = ` | ||
some code, some code, a mask to be replaced https://{{che-cluster}}.{{host}}/{{namespace}}/{{workspace-name}}/{{port}}/, some code | ||
`; | ||
|
||
const NEW_WORKBENCH_WEB_MAIN = ` | ||
some code, some code, a mask to be replaced test-workspace-1234567890, some code | ||
`; | ||
|
||
describe("Test setting DevWorkspace ID to VS Code", () => { | ||
beforeEach(() => { | ||
delete env.DEVWORKSPACE_ID; | ||
}); | ||
|
||
test("should return if env.DEVWORKSPACE_ID is not set", async () => { | ||
const readFileMock = jest.fn(); | ||
Object.assign(fs, { | ||
readFile: readFileMock, | ||
}); | ||
|
||
const devWorkspaceId = new DevWorkspaceId(); | ||
await devWorkspaceId.configure(); | ||
|
||
expect(readFileMock).toBeCalledTimes(0); | ||
}); | ||
|
||
test("should apply env.DEVWORKSPACE_ID", async () => { | ||
env.DEVWORKSPACE_ID = "test-workspace-1234567890"; | ||
|
||
const readFileMock = jest.fn(); | ||
const writeFileMock = jest.fn(); | ||
|
||
Object.assign(fs, { | ||
readFile: readFileMock, | ||
writeFile: writeFileMock, | ||
}); | ||
|
||
readFileMock.mockImplementation(() => ORIGIN_WORKBENCH_WEB_MAIN); | ||
|
||
const devWorkspaceId = new DevWorkspaceId(); | ||
await devWorkspaceId.configure(); | ||
|
||
expect(readFileMock).toBeCalledTimes(1); | ||
expect(writeFileMock).toBeCalledWith( | ||
"out/vs/workbench/workbench.web.main.js", | ||
NEW_WORKBENCH_WEB_MAIN | ||
); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters