@forge/cli
13.4.0-next.5-experimental-016ed9d13.4.0-next.5-experimental-c575574
out/command-line/controller/settings-controller.js~
out/command-line/controller/settings-controller.jsModified+38−1
Index: package/out/command-line/controller/settings-controller.js
===================================================================
--- package/out/command-line/controller/settings-controller.js
+++ package/out/command-line/controller/settings-controller.js
@@ -3,9 +3,9 @@
exports.SettingsController = exports.DELETABLE_SETTINGS = exports.ALLOWED_SETTINGS = void 0;
const cli_shared_1 = require("@forge/cli-shared");
const manifest_1 = require("@forge/manifest");
const environment_1 = require("../environment");
-exports.ALLOWED_SETTINGS = ['usage-analytics', 'default-environment', 'seasonal-effects'];
+exports.ALLOWED_SETTINGS = ['usage-analytics', 'default-environment', 'seasonal-effects', 'proxy'];
exports.DELETABLE_SETTINGS = ['proxy'];
class SettingsController {
settingsView;
cachedConfigService;
@@ -62,8 +62,21 @@
set: async (value) => {
const parsedValue = this.parseBoolean(value);
this.cachedConfigService.setCustomEffects(parsedValue);
}
+ },
+ proxy: {
+ description: cli_shared_1.Text.settings.proxy.description,
+ get: async () => {
+ const proxy = this.cachedConfigService.getProxy();
+ return proxy ? this.redactUrlCredentials(proxy) : proxy;
+ },
+ set: async (value) => {
+ this.validateProxyUrl(value);
+ this.cachedConfigService.setProxy(value);
+ },
+ getDisplayValue: (value) => this.redactUrlCredentials(value),
+ delete: async () => this.cachedConfigService.deleteProxy()
}
};
parseBoolean(value) {
switch (value) {
@@ -80,8 +93,32 @@
}
isSettingDeleteAllowed(preference) {
return exports.DELETABLE_SETTINGS.includes(preference);
}
+ validateProxyUrl(value) {
+ try {
+ const proxyUrl = new URL(value);
+ if (proxyUrl.protocol === 'http:' || proxyUrl.protocol === 'https:') {
+ return;
+ }
+ }
+ catch (e) {
+ }
+ throw new cli_shared_1.ValidationError(cli_shared_1.Text.settings.proxy.invalidUrl);
+ }
+ redactUrlCredentials(value) {
+ try {
+ const url = new URL(value);
+ if (url.username || url.password) {
+ url.username = '***';
+ url.password = url.password ? '***' : '';
+ }
+ return url.toString();
+ }
+ catch (e) {
+ return value;
+ }
+ }
async showSettings(json) {
const settings = [];
for (const settingName of exports.ALLOWED_SETTINGS) {
const setting = this.SETTINGS_MAP[settingName];