@forge/cli

13.3.0-next.20-experimental-cf2ad4c13.3.0-next.12-experimental-4b981ef-experimental-5b8eb3c
out/command-line/controller/settings-controller.js
~out/command-line/controller/settings-controller.jsModified
+39−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,10 +3,11 @@
 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'];
+const INVALID_PROXY_URL = 'Invalid proxy URL specified. Valid proxy URLs must start with http:// or https://';
 class SettingsController {
     settingsView;
     cachedConfigService;
     getAppConfig;
@@ -62,8 +63,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 +94,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(INVALID_PROXY_URL);
+    }
+    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];