Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: allow the extensions to authenticate (#339)
Signed-off-by: vitaliy-guliy <vgulyy@redhat.com>
- Loading branch information
1 parent
c5bae35
commit a028116
Showing
10 changed files
with
394 additions
and
4 deletions.
There are no files selected for viewing
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
10 changes: 10 additions & 0 deletions
10
.rebase/replace/code/src/vs/platform/product/common/product.ts.json
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,10 @@ | ||
[ | ||
{ | ||
"from": "import { ISandboxConfiguration } from 'vs/base/parts/sandbox/common/sandboxTypes';", | ||
"by": "import { ISandboxConfiguration } from 'vs/base/parts/sandbox/common/sandboxTypes';\\\nimport { loadFromFileSystem } from 'vs/platform/product/common/che/product';" | ||
}, | ||
{ | ||
"from": "product = { /\\*BUILD->INSERT_PRODUCT_CONFIGURATION\\*/ } as IProductConfiguration;", | ||
"by": "product = { /\\*BUILD->INSERT_PRODUCT_CONFIGURATION\\*/ } as IProductConfiguration;\\\n\\\tproduct = loadFromFileSystem();" | ||
} | ||
] |
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,32 @@ | ||
/********************************************************************** | ||
* Copyright (c) 2024 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 */ | ||
|
||
import { IProductConfiguration } from 'vs/base/common/product'; | ||
|
||
export function loadFromFileSystem(): IProductConfiguration { | ||
const href = `./oss-dev/static/product.json`; | ||
|
||
try { | ||
var xmlhttp = new XMLHttpRequest(); | ||
xmlhttp.open("GET", href, false); | ||
xmlhttp.send(); | ||
|
||
if (xmlhttp.status == 200 && xmlhttp.readyState == 4) { | ||
return JSON.parse(xmlhttp.responseText); | ||
} | ||
|
||
console.log(`Request failed with status: ${xmlhttp.status}, readyState: ${xmlhttp.readyState}`); | ||
} catch (err) { | ||
console.error(err); | ||
} | ||
|
||
throw new Error(`Unable to load product.json from ${href}.`); | ||
} |
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,72 @@ | ||
/********************************************************************** | ||
* Copyright (c) 2024 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 { ProductJSON } from './product-json'; | ||
|
||
export class TrustedExtensions { | ||
async configure(): Promise<void> { | ||
console.log('# Configuring Trusted Extensions...'); | ||
|
||
if (!env.VSCODE_TRUSTED_EXTENSIONS) { | ||
console.log(' > env.VSCODE_TRUSTED_EXTENSIONS is not defined, skip this step'); | ||
return; | ||
} | ||
|
||
console.log(` > env.VSCODE_TRUSTED_EXTENSIONS is set to [${env.VSCODE_TRUSTED_EXTENSIONS}]`); | ||
|
||
try { | ||
const extensions: string[] = []; | ||
|
||
for (const extension of env.VSCODE_TRUSTED_EXTENSIONS.split(',')) { | ||
if (extension) { | ||
if (extension.match(/^[a-z0-9][a-z0-9-]*\.[a-z0-9][a-z0-9-.]*$/)) { | ||
extensions.push(extension); | ||
console.log(` > add ${extension}`); | ||
} else { | ||
console.log(` > failure to add [${extension}] because of wrong identifier`); | ||
} | ||
} | ||
} | ||
|
||
if (!extensions.length) { | ||
console.log( | ||
' > ERROR: The variable provided most likely has wrong format. It should specify one or more extensions separated by comma.' | ||
); | ||
return; | ||
} | ||
|
||
const productJSON = await new ProductJSON().load(); | ||
let productJSONChanged = false; | ||
|
||
let access = productJSON.getTrustedExtensionAuthAccess(); | ||
if (access === undefined) { | ||
productJSON.setTrustedExtensionAuthAccess([...extensions]); | ||
productJSONChanged = true; | ||
} else if (Array.isArray(access)) { | ||
for (const extension of extensions) { | ||
if (!access.includes(extension)) { | ||
access.push(extension); | ||
productJSONChanged = true; | ||
} | ||
} | ||
} else { | ||
console.log(' > Unexpected type of trustedExtensionAuthAccess in product.json. Skip this step'); | ||
return; | ||
} | ||
|
||
if (productJSONChanged) { | ||
await productJSON.save(); | ||
} | ||
} catch (err) { | ||
console.error(`${err.message} Failure to configure trusted extensions in product.json.`); | ||
} | ||
} | ||
} |
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
Oops, something went wrong.