From 02f62882b8a9ecab98c20b6a3ffe0525f3d63caf Mon Sep 17 00:00:00 2001 From: Anmol Sethi Date: Tue, 11 Jun 2019 12:54:49 -0400 Subject: [PATCH] Propagate full env to browser (#756) * Propogate full env to browser * Add support for setting $ITEM_URL * Add serviceURL getter --- packages/ide/src/fill/os.ts | 4 ++ packages/protocol/package.json | 3 ++ packages/protocol/scripts/generate_proto.sh | 4 +- packages/protocol/src/browser/client.ts | 1 + packages/protocol/src/common/connection.ts | 3 ++ packages/protocol/src/node/server.ts | 5 +++ packages/protocol/src/proto/client.proto | 2 + packages/protocol/src/proto/client_pb.d.ts | 3 ++ packages/protocol/src/proto/client_pb.js | 40 ++++++++++++++++-- packages/protocol/src/proto/node_pb.js | 46 ++++++++++----------- packages/protocol/src/proto/vscode_pb.js | 2 +- packages/vscode/src/fill/product.ts | 17 +++++--- scripts/webpack.general.config.js | 2 - 13 files changed, 95 insertions(+), 37 deletions(-) diff --git a/packages/ide/src/fill/os.ts b/packages/ide/src/fill/os.ts index f9c8008c..ffb9394c 100644 --- a/packages/ide/src/fill/os.ts +++ b/packages/ide/src/fill/os.ts @@ -35,6 +35,10 @@ class OS { default: this._platform = "linux"; break; } process.platform = this._platform; + process.env = {}; + data.env.forEach((v, k) => { + process.env[k] = v; + }); } public release(): string { diff --git a/packages/protocol/package.json b/packages/protocol/package.json index 2f2a63b5..80d239e3 100644 --- a/packages/protocol/package.json +++ b/packages/protocol/package.json @@ -14,5 +14,8 @@ "rimraf": "^2.6.3", "text-encoding": "^0.7.0", "ts-protoc-gen": "^0.8.0" + }, + "scripts": { + "gen": "./scripts/generate_proto.sh" } } diff --git a/packages/protocol/scripts/generate_proto.sh b/packages/protocol/scripts/generate_proto.sh index fa014b0f..9cd471a2 100755 --- a/packages/protocol/scripts/generate_proto.sh +++ b/packages/protocol/scripts/generate_proto.sh @@ -1,3 +1,5 @@ #!/bin/bash -protoc --plugin="protoc-gen-ts=./node_modules/.bin/protoc-gen-ts" --js_out="import_style=commonjs,binary:./src/proto" --ts_out="./src/proto" ./src/proto/*.proto --proto_path="./src/proto" \ No newline at end of file +cd "$(dirname "$0")/.." + +protoc --plugin="protoc-gen-ts=./node_modules/.bin/protoc-gen-ts" --js_out="import_style=commonjs,binary:./src/proto" --ts_out="./src/proto" ./src/proto/*.proto --proto_path="./src/proto" diff --git a/packages/protocol/src/browser/client.ts b/packages/protocol/src/browser/client.ts index 3f2d35f6..cdbe9937 100644 --- a/packages/protocol/src/browser/client.ts +++ b/packages/protocol/src/browser/client.ts @@ -280,6 +280,7 @@ export class Client { builtInExtensionsDirectory: init.getBuiltinExtensionsDir(), extraExtensionDirectories: init.getExtraExtensionDirectoriesList(), extraBuiltinExtensionDirectories: init.getExtraBuiltinExtensionDirectoriesList(), + env: init.getEnvMap(), }; this.initDataEmitter.emit(this._initData); break; diff --git a/packages/protocol/src/common/connection.ts b/packages/protocol/src/common/connection.ts index 901bc3d5..395b9a4d 100644 --- a/packages/protocol/src/common/connection.ts +++ b/packages/protocol/src/common/connection.ts @@ -1,3 +1,5 @@ +import * as jspb from "google-protobuf"; + export interface SendableConnection { send(data: Buffer | Uint8Array): void; } @@ -27,6 +29,7 @@ export interface InitData { readonly builtInExtensionsDirectory: string; readonly extraExtensionDirectories: string[]; readonly extraBuiltinExtensionDirectories: string[]; + readonly env: jspb.Map; } export interface SharedProcessData { diff --git a/packages/protocol/src/node/server.ts b/packages/protocol/src/node/server.ts index 250f2d30..0ebaacb3 100644 --- a/packages/protocol/src/node/server.ts +++ b/packages/protocol/src/node/server.ts @@ -103,6 +103,11 @@ export class Server { initMsg.setShell(os.userInfo().shell || global.process.env.SHELL || ""); initMsg.setExtraExtensionDirectoriesList(this.options.extraExtensionDirectories || []); initMsg.setExtraBuiltinExtensionDirectoriesList(this.options.extraBuiltinExtensionDirectories || []); + + for (let key in process.env) { + initMsg.getEnvMap().set(key, process.env[key] as string); + } + const srvMsg = new ServerMessage(); srvMsg.setInit(initMsg); connection.send(srvMsg.serializeBinary()); diff --git a/packages/protocol/src/proto/client.proto b/packages/protocol/src/proto/client.proto index 33c5e342..994d6ac3 100644 --- a/packages/protocol/src/proto/client.proto +++ b/packages/protocol/src/proto/client.proto @@ -44,4 +44,6 @@ message WorkingInit { string extensions_directory = 8; repeated string extra_extension_directories = 9; repeated string extra_builtin_extension_directories = 10; + + map env = 11; } diff --git a/packages/protocol/src/proto/client_pb.d.ts b/packages/protocol/src/proto/client_pb.d.ts index 931f71c1..60bbdddf 100644 --- a/packages/protocol/src/proto/client_pb.d.ts +++ b/packages/protocol/src/proto/client_pb.d.ts @@ -145,6 +145,8 @@ export class WorkingInit extends jspb.Message { setExtraBuiltinExtensionDirectoriesList(value: Array): void; addExtraBuiltinExtensionDirectories(value: string, index?: number): string; + getEnvMap(): jspb.Map; + clearEnvMap(): void; serializeBinary(): Uint8Array; toObject(includeInstance?: boolean): WorkingInit.AsObject; static toObject(includeInstance: boolean, msg: WorkingInit): WorkingInit.AsObject; @@ -167,6 +169,7 @@ export namespace WorkingInit { extensionsDirectory: string, extraExtensionDirectoriesList: Array, extraBuiltinExtensionDirectoriesList: Array, + envMap: Array<[string, string]>, } export enum OperatingSystem { diff --git a/packages/protocol/src/proto/client_pb.js b/packages/protocol/src/proto/client_pb.js index 7dd7c8c2..3a1673e3 100644 --- a/packages/protocol/src/proto/client_pb.js +++ b/packages/protocol/src/proto/client_pb.js @@ -137,7 +137,7 @@ proto.ClientMessage.prototype.toObject = function(opt_includeInstance) { * @suppress {unusedLocalVariables} f is only used for nested messages */ proto.ClientMessage.toObject = function(includeInstance, msg) { - var obj = { + var f, obj = { method: (f = msg.getMethod()) && node_pb.Method.toObject(includeInstance, f), ping: (f = msg.getPing()) && node_pb.Ping.toObject(includeInstance, f) }; @@ -360,7 +360,7 @@ proto.ServerMessage.prototype.toObject = function(opt_includeInstance) { * @suppress {unusedLocalVariables} f is only used for nested messages */ proto.ServerMessage.toObject = function(includeInstance, msg) { - var obj = { + var f, obj = { fail: (f = msg.getFail()) && node_pb.Method.Fail.toObject(includeInstance, f), success: (f = msg.getSuccess()) && node_pb.Method.Success.toObject(includeInstance, f), event: (f = msg.getEvent()) && node_pb.Event.toObject(includeInstance, f), @@ -794,7 +794,7 @@ proto.WorkingInit.prototype.toObject = function(opt_includeInstance) { * @suppress {unusedLocalVariables} f is only used for nested messages */ proto.WorkingInit.toObject = function(includeInstance, msg) { - var obj = { + var f, obj = { homeDirectory: jspb.Message.getFieldWithDefault(msg, 1, ""), tmpDirectory: jspb.Message.getFieldWithDefault(msg, 2, ""), dataDirectory: jspb.Message.getFieldWithDefault(msg, 3, ""), @@ -804,7 +804,8 @@ proto.WorkingInit.toObject = function(includeInstance, msg) { builtinExtensionsDir: jspb.Message.getFieldWithDefault(msg, 7, ""), extensionsDirectory: jspb.Message.getFieldWithDefault(msg, 8, ""), extraExtensionDirectoriesList: jspb.Message.getRepeatedField(msg, 9), - extraBuiltinExtensionDirectoriesList: jspb.Message.getRepeatedField(msg, 10) + extraBuiltinExtensionDirectoriesList: jspb.Message.getRepeatedField(msg, 10), + envMap: (f = msg.getEnvMap()) ? f.toObject(includeInstance, undefined) : [] }; if (includeInstance) { @@ -881,6 +882,12 @@ proto.WorkingInit.deserializeBinaryFromReader = function(msg, reader) { var value = /** @type {string} */ (reader.readString()); msg.addExtraBuiltinExtensionDirectories(value); break; + case 11: + var value = msg.getEnvMap(); + reader.readMessage(value, function(message, reader) { + jspb.Map.deserializeBinary(message, reader, jspb.BinaryReader.prototype.readString, jspb.BinaryReader.prototype.readString, null, ""); + }); + break; default: reader.skipField(); break; @@ -980,6 +987,10 @@ proto.WorkingInit.serializeBinaryToWriter = function(message, writer) { f ); } + f = message.getEnvMap(true); + if (f && f.getLength() > 0) { + f.serializeBinary(11, writer, jspb.BinaryWriter.prototype.writeString, jspb.BinaryWriter.prototype.writeString); + } }; @@ -1176,4 +1187,25 @@ proto.WorkingInit.prototype.clearExtraBuiltinExtensionDirectoriesList = function }; +/** + * map env = 11; + * @param {boolean=} opt_noLazyCreate Do not create the map if + * empty, instead returning `undefined` + * @return {!jspb.Map} + */ +proto.WorkingInit.prototype.getEnvMap = function(opt_noLazyCreate) { + return /** @type {!jspb.Map} */ ( + jspb.Message.getMapField(this, 11, opt_noLazyCreate, + null)); +}; + + +/** + * Clears values from the map. The map will be non-null. + */ +proto.WorkingInit.prototype.clearEnvMap = function() { + this.getEnvMap().clear(); +}; + + goog.object.extend(exports, proto); diff --git a/packages/protocol/src/proto/node_pb.js b/packages/protocol/src/proto/node_pb.js index c3eed692..c7a90b5a 100644 --- a/packages/protocol/src/proto/node_pb.js +++ b/packages/protocol/src/proto/node_pb.js @@ -583,7 +583,7 @@ proto.Argument.prototype.toObject = function(opt_includeInstance) { * @suppress {unusedLocalVariables} f is only used for nested messages */ proto.Argument.toObject = function(includeInstance, msg) { - var obj = { + var f, obj = { error: (f = msg.getError()) && proto.Argument.ErrorValue.toObject(includeInstance, f), buffer: (f = msg.getBuffer()) && proto.Argument.BufferValue.toObject(includeInstance, f), object: (f = msg.getObject()) && proto.Argument.ObjectValue.toObject(includeInstance, f), @@ -843,7 +843,7 @@ proto.Argument.ErrorValue.prototype.toObject = function(opt_includeInstance) { * @suppress {unusedLocalVariables} f is only used for nested messages */ proto.Argument.ErrorValue.toObject = function(includeInstance, msg) { - var obj = { + var f, obj = { message: jspb.Message.getFieldWithDefault(msg, 1, ""), stack: jspb.Message.getFieldWithDefault(msg, 2, ""), code: jspb.Message.getFieldWithDefault(msg, 3, "") @@ -1022,7 +1022,7 @@ proto.Argument.BufferValue.prototype.toObject = function(opt_includeInstance) { * @suppress {unusedLocalVariables} f is only used for nested messages */ proto.Argument.BufferValue.toObject = function(includeInstance, msg) { - var obj = { + var f, obj = { data: msg.getData_asB64() }; @@ -1171,7 +1171,7 @@ proto.Argument.ObjectValue.prototype.toObject = function(opt_includeInstance) { * @suppress {unusedLocalVariables} f is only used for nested messages */ proto.Argument.ObjectValue.toObject = function(includeInstance, msg) { - var obj = { + var f, obj = { dataMap: (f = msg.getDataMap()) ? f.toObject(includeInstance, proto.Argument.toObject) : [] }; @@ -1308,7 +1308,7 @@ proto.Argument.ArrayValue.prototype.toObject = function(opt_includeInstance) { * @suppress {unusedLocalVariables} f is only used for nested messages */ proto.Argument.ArrayValue.toObject = function(includeInstance, msg) { - var obj = { + var f, obj = { dataList: jspb.Message.toObjectList(msg.getDataList(), proto.Argument.toObject, includeInstance) }; @@ -1455,7 +1455,7 @@ proto.Argument.ProxyValue.prototype.toObject = function(opt_includeInstance) { * @suppress {unusedLocalVariables} f is only used for nested messages */ proto.Argument.ProxyValue.toObject = function(includeInstance, msg) { - var obj = { + var f, obj = { id: jspb.Message.getFieldWithDefault(msg, 1, 0) }; @@ -1580,7 +1580,7 @@ proto.Argument.FunctionValue.prototype.toObject = function(opt_includeInstance) * @suppress {unusedLocalVariables} f is only used for nested messages */ proto.Argument.FunctionValue.toObject = function(includeInstance, msg) { - var obj = { + var f, obj = { id: jspb.Message.getFieldWithDefault(msg, 1, 0) }; @@ -1705,7 +1705,7 @@ proto.Argument.NullValue.prototype.toObject = function(opt_includeInstance) { * @suppress {unusedLocalVariables} f is only used for nested messages */ proto.Argument.NullValue.toObject = function(includeInstance, msg) { - var obj = { + var f, obj = { }; @@ -1804,7 +1804,7 @@ proto.Argument.UndefinedValue.prototype.toObject = function(opt_includeInstance) * @suppress {unusedLocalVariables} f is only used for nested messages */ proto.Argument.UndefinedValue.toObject = function(includeInstance, msg) { - var obj = { + var f, obj = { }; @@ -1903,7 +1903,7 @@ proto.Argument.DateValue.prototype.toObject = function(opt_includeInstance) { * @suppress {unusedLocalVariables} f is only used for nested messages */ proto.Argument.DateValue.toObject = function(includeInstance, msg) { - var obj = { + var f, obj = { date: jspb.Message.getFieldWithDefault(msg, 1, "") }; @@ -2449,7 +2449,7 @@ proto.Method.prototype.toObject = function(opt_includeInstance) { * @suppress {unusedLocalVariables} f is only used for nested messages */ proto.Method.toObject = function(includeInstance, msg) { - var obj = { + var f, obj = { namedProxy: (f = msg.getNamedProxy()) && proto.Method.Named.toObject(includeInstance, f), numberedProxy: (f = msg.getNumberedProxy()) && proto.Method.Numbered.toObject(includeInstance, f) }; @@ -2582,7 +2582,7 @@ proto.Method.Named.prototype.toObject = function(opt_includeInstance) { * @suppress {unusedLocalVariables} f is only used for nested messages */ proto.Method.Named.toObject = function(includeInstance, msg) { - var obj = { + var f, obj = { id: jspb.Message.getFieldWithDefault(msg, 1, 0), module: jspb.Message.getFieldWithDefault(msg, 2, 0), method: jspb.Message.getFieldWithDefault(msg, 3, ""), @@ -2817,7 +2817,7 @@ proto.Method.Numbered.prototype.toObject = function(opt_includeInstance) { * @suppress {unusedLocalVariables} f is only used for nested messages */ proto.Method.Numbered.toObject = function(includeInstance, msg) { - var obj = { + var f, obj = { id: jspb.Message.getFieldWithDefault(msg, 1, 0), proxyId: jspb.Message.getFieldWithDefault(msg, 2, 0), method: jspb.Message.getFieldWithDefault(msg, 3, ""), @@ -3045,7 +3045,7 @@ proto.Method.Fail.prototype.toObject = function(opt_includeInstance) { * @suppress {unusedLocalVariables} f is only used for nested messages */ proto.Method.Fail.toObject = function(includeInstance, msg) { - var obj = { + var f, obj = { id: jspb.Message.getFieldWithDefault(msg, 1, 0), response: (f = msg.getResponse()) && proto.Argument.toObject(includeInstance, f) }; @@ -3217,7 +3217,7 @@ proto.Method.Success.prototype.toObject = function(opt_includeInstance) { * @suppress {unusedLocalVariables} f is only used for nested messages */ proto.Method.Success.toObject = function(includeInstance, msg) { - var obj = { + var f, obj = { id: jspb.Message.getFieldWithDefault(msg, 1, 0), response: (f = msg.getResponse()) && proto.Argument.toObject(includeInstance, f) }; @@ -3481,7 +3481,7 @@ proto.Callback.prototype.toObject = function(opt_includeInstance) { * @suppress {unusedLocalVariables} f is only used for nested messages */ proto.Callback.toObject = function(includeInstance, msg) { - var obj = { + var f, obj = { namedCallback: (f = msg.getNamedCallback()) && proto.Callback.Named.toObject(includeInstance, f), numberedCallback: (f = msg.getNumberedCallback()) && proto.Callback.Numbered.toObject(includeInstance, f) }; @@ -3614,7 +3614,7 @@ proto.Callback.Named.prototype.toObject = function(opt_includeInstance) { * @suppress {unusedLocalVariables} f is only used for nested messages */ proto.Callback.Named.toObject = function(includeInstance, msg) { - var obj = { + var f, obj = { module: jspb.Message.getFieldWithDefault(msg, 1, 0), callbackId: jspb.Message.getFieldWithDefault(msg, 2, 0), argsList: jspb.Message.toObjectList(msg.getArgsList(), @@ -3822,7 +3822,7 @@ proto.Callback.Numbered.prototype.toObject = function(opt_includeInstance) { * @suppress {unusedLocalVariables} f is only used for nested messages */ proto.Callback.Numbered.toObject = function(includeInstance, msg) { - var obj = { + var f, obj = { proxyId: jspb.Message.getFieldWithDefault(msg, 1, 0), callbackId: jspb.Message.getFieldWithDefault(msg, 2, 0), argsList: jspb.Message.toObjectList(msg.getArgsList(), @@ -4115,7 +4115,7 @@ proto.Event.prototype.toObject = function(opt_includeInstance) { * @suppress {unusedLocalVariables} f is only used for nested messages */ proto.Event.toObject = function(includeInstance, msg) { - var obj = { + var f, obj = { namedEvent: (f = msg.getNamedEvent()) && proto.Event.Named.toObject(includeInstance, f), numberedEvent: (f = msg.getNumberedEvent()) && proto.Event.Numbered.toObject(includeInstance, f) }; @@ -4248,7 +4248,7 @@ proto.Event.Named.prototype.toObject = function(opt_includeInstance) { * @suppress {unusedLocalVariables} f is only used for nested messages */ proto.Event.Named.toObject = function(includeInstance, msg) { - var obj = { + var f, obj = { module: jspb.Message.getFieldWithDefault(msg, 1, 0), event: jspb.Message.getFieldWithDefault(msg, 2, ""), argsList: jspb.Message.toObjectList(msg.getArgsList(), @@ -4456,7 +4456,7 @@ proto.Event.Numbered.prototype.toObject = function(opt_includeInstance) { * @suppress {unusedLocalVariables} f is only used for nested messages */ proto.Event.Numbered.toObject = function(includeInstance, msg) { - var obj = { + var f, obj = { proxyId: jspb.Message.getFieldWithDefault(msg, 1, 0), event: jspb.Message.getFieldWithDefault(msg, 2, ""), argsList: jspb.Message.toObjectList(msg.getArgsList(), @@ -4723,7 +4723,7 @@ proto.Ping.prototype.toObject = function(opt_includeInstance) { * @suppress {unusedLocalVariables} f is only used for nested messages */ proto.Ping.toObject = function(includeInstance, msg) { - var obj = { + var f, obj = { }; @@ -4822,7 +4822,7 @@ proto.Pong.prototype.toObject = function(opt_includeInstance) { * @suppress {unusedLocalVariables} f is only used for nested messages */ proto.Pong.toObject = function(includeInstance, msg) { - var obj = { + var f, obj = { }; diff --git a/packages/protocol/src/proto/vscode_pb.js b/packages/protocol/src/proto/vscode_pb.js index e03af0fe..982bcf34 100644 --- a/packages/protocol/src/proto/vscode_pb.js +++ b/packages/protocol/src/proto/vscode_pb.js @@ -62,7 +62,7 @@ proto.SharedProcessActive.prototype.toObject = function(opt_includeInstance) { * @suppress {unusedLocalVariables} f is only used for nested messages */ proto.SharedProcessActive.toObject = function(includeInstance, msg) { - var obj = { + var f, obj = { socketPath: jspb.Message.getFieldWithDefault(msg, 1, ""), logPath: jspb.Message.getFieldWithDefault(msg, 2, "") }; diff --git a/packages/vscode/src/fill/product.ts b/packages/vscode/src/fill/product.ts index e58f8dc5..19460896 100644 --- a/packages/vscode/src/fill/product.ts +++ b/packages/vscode/src/fill/product.ts @@ -28,12 +28,17 @@ class Product implements IProductConfiguration { return this._dataFolderName; } - public extensionsGallery = { - serviceUrl: global && global.process && global.process.env.SERVICE_URL - || process.env.SERVICE_URL - || "https://v1.extapi.coder.com", - // tslint:disable-next-line:no-any - } as any; + // tslint:disable-next-line:no-any + public extensionsGallery: any = { + get serviceUrl(): string { + return process.env.SERVICE_URL || "https://v1.extapi.coder.com"; + }, + + get itemUrl(): string { + return process.env.ITEM_URL || ""; + }, + + }; public extensionExecutionEnvironments = { "wayou.vscode-todo-highlight": "worker", diff --git a/scripts/webpack.general.config.js b/scripts/webpack.general.config.js index 02addc21..4cfcb93a 100644 --- a/scripts/webpack.general.config.js +++ b/scripts/webpack.general.config.js @@ -90,8 +90,6 @@ module.exports = (options = {}) => ({ }), new webpack.DefinePlugin({ "process.env.NODE_ENV": `"${environment}"`, - "process.env.LOG_LEVEL": `"${process.env.LOG_LEVEL || ""}"`, - "process.env.SERVICE_URL": `"${process.env.SERVICE_URL || ""}"`, "process.env.VERSION": `"${process.env.VERSION || ""}"`, }), ],