From 3e8fd7072cb4b429a46ec605c2ca919eb49f56ff Mon Sep 17 00:00:00 2001 From: Anisa Oshafi Date: Sun, 7 Sep 2025 00:30:17 +0200 Subject: [PATCH 1/5] Style: override -> Override --- src/utils/configure-aws.ts | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/utils/configure-aws.ts b/src/utils/configure-aws.ts index e51671c..1e392a4 100644 --- a/src/utils/configure-aws.ts +++ b/src/utils/configure-aws.ts @@ -40,12 +40,12 @@ async function overrideSelection( override: boolean = false, ): Promise { if (override === true) { - return "override"; + return "Override"; } const fileList = filesToModify.join(" and "); const selection = await window.showWarningMessage( `The "localstack" AWS profile in ${fileList} exists, but does not match the expected properties. Do you want to override it?`, - "override", + "Override", ); return selection; } @@ -93,7 +93,7 @@ async function dnsResolveCheck(): Promise { } } -type OverrideDecision = "override" | "do_not_override"; +type OverrideDecision = "Override" | "do_not_override"; async function configureAwsConfigProfile( awsConfigFilename: string, @@ -110,7 +110,7 @@ async function configureAwsConfigProfile( try { if (section) { // LocalStack profile exists, but does not match the expected properties - if (overrideDecision === "override") { + if (overrideDecision === "Override") { // User chose to override the existing profile. // check if dnsResolveCheck is successful @@ -186,7 +186,7 @@ async function configureCredentialsProfile( try { // LocalStack profile exists, but does not match the expected properties if (section) { - if (overrideDecision === "override") { + if (overrideDecision === "Override") { // User chose to override the existing profile. const updatedIniFile = updateIniSection( iniFile, @@ -321,7 +321,7 @@ export async function configureAwsProfiles(options: { // profiles are there but need adjustment // in testing, we always override if (options?.forceOverride) { - overrideDecision = "override"; + overrideDecision = "Override"; } else { // check which files need override const filesToModify = []; @@ -333,7 +333,7 @@ export async function configureAwsProfiles(options: { } } else { // if any of the profiles don't exist, we need to create it - overrideDecision = "override"; + overrideDecision = "Override"; } if (overrideDecision === undefined) { @@ -350,7 +350,7 @@ export async function configureAwsProfiles(options: { }, }); return; - } else if (overrideDecision === "override") { + } else if (overrideDecision === "Override") { if (configNeedsOverride && credentialsNeedsOverride) { [configModified, credentialsModified] = await Promise.all([ configureAwsConfigProfile( From 1cd146c6ed7ab4fa74e36f0ae4c72400f7fcb8c9 Mon Sep 17 00:00:00 2001 From: Anisa Oshafi Date: Sun, 7 Sep 2025 00:33:32 +0200 Subject: [PATCH 2/5] Handle https protocol for endpoint_url --- src/utils/configure-aws.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/utils/configure-aws.ts b/src/utils/configure-aws.ts index 1e392a4..8b04b99 100644 --- a/src/utils/configure-aws.ts +++ b/src/utils/configure-aws.ts @@ -15,9 +15,12 @@ import type { Telemetry } from "./telemetry.ts"; const LOCALSTACK_CONFIG_PROFILE_NAME = "profile localstack"; const VALID_ENDPOINT_URLS = [ - "http://localhost.localstack.cloud:4566", // default + "http://localhost.localstack.cloud:4566", + "https://localhost.localstack.cloud:4566", "http://127.0.0.1:4566", + "https://127.0.0.1:4566", "http://localhost:4566", + "https://localhost:4566", ]; const LOCALSTACK_CONFIG_PROPERTIES = { region: "us-east-1", @@ -143,8 +146,8 @@ async function configureAwsConfigProfile( // check if dnsResolveCheck is successful const isDnsResolved = await dnsResolveCheck(); const endpointUrl = isDnsResolved - ? "http://localhost.localstack.cloud:4566" - : VALID_ENDPOINT_URLS[1]; + ? "https://localhost.localstack.cloud:4566" + : "https://127.0.0.1:4566"; const updatedIniFile = updateIniSection( iniFile, From 8ceae9b6455026e62ca4c66bcab09d2c6b8c9778 Mon Sep 17 00:00:00 2001 From: Anisa Oshafi Date: Sun, 7 Sep 2025 00:42:32 +0200 Subject: [PATCH 3/5] Refactor aws profile code --- src/utils/configure-aws.ts | 38 +++++++++++++++++++++++++------------- 1 file changed, 25 insertions(+), 13 deletions(-) diff --git a/src/utils/configure-aws.ts b/src/utils/configure-aws.ts index 8b04b99..e8df973 100644 --- a/src/utils/configure-aws.ts +++ b/src/utils/configure-aws.ts @@ -14,18 +14,15 @@ import type { Telemetry } from "./telemetry.ts"; // TODO: add a test for this. const LOCALSTACK_CONFIG_PROFILE_NAME = "profile localstack"; -const VALID_ENDPOINT_URLS = [ - "http://localhost.localstack.cloud:4566", - "https://localhost.localstack.cloud:4566", - "http://127.0.0.1:4566", - "https://127.0.0.1:4566", - "http://localhost:4566", - "https://localhost:4566", +const VALID_HOSTNAMES = [ + "localhost.localstack.cloud", + "127.0.0.1", + "localhost", ]; +const DEFAULT_PORT = "4566"; const LOCALSTACK_CONFIG_PROPERTIES = { region: "us-east-1", output: "json", - endpoint_url: VALID_ENDPOINT_URLS, }; // https://docs.aws.amazon.com/cli/v1/userguide/cli-configure-files.html @@ -53,6 +50,21 @@ async function overrideSelection( return selection; } +function isValidEndpointUrl(url: string | undefined): boolean { + if (!url) return false; + try { + const parsed = new URL(url); + return ( + (parsed.protocol === "http:" || parsed.protocol === "https:") && + VALID_HOSTNAMES.includes(parsed.hostname) && + parsed.port !== "" && // port must be present + (parsed.port === DEFAULT_PORT || /^\d+$/.test(parsed.port)) + ); + } catch { + return false; + } +} + function checkIfConfigNeedsOverride(section: IniSection | undefined): boolean { if (!section) { return true; // profile doesn't exist @@ -61,7 +73,7 @@ function checkIfConfigNeedsOverride(section: IniSection | undefined): boolean { return !( section.properties.region && section.properties.endpoint_url && - VALID_ENDPOINT_URLS.includes(section.properties.endpoint_url) + isValidEndpointUrl(section.properties.endpoint_url) ); } @@ -119,8 +131,8 @@ async function configureAwsConfigProfile( // check if dnsResolveCheck is successful const isDnsResolved = await dnsResolveCheck(); const endpointUrl = isDnsResolved - ? "http://localhost.localstack.cloud:4566" - : VALID_ENDPOINT_URLS[1]; + ? `http://localhost.localstack.cloud:${DEFAULT_PORT}` + : `http://127.0.0.1:${DEFAULT_PORT}`; const updatedIniFile = updateIniSection( iniFile, @@ -146,8 +158,8 @@ async function configureAwsConfigProfile( // check if dnsResolveCheck is successful const isDnsResolved = await dnsResolveCheck(); const endpointUrl = isDnsResolved - ? "https://localhost.localstack.cloud:4566" - : "https://127.0.0.1:4566"; + ? `http://localhost.localstack.cloud:${DEFAULT_PORT}` + : `http://127.0.0.1:${DEFAULT_PORT}`; const updatedIniFile = updateIniSection( iniFile, From 6677c0aa3069b2360fd0ac3fc701f9b53e3e14e0 Mon Sep 17 00:00:00 2001 From: Anisa Oshafi Date: Mon, 8 Sep 2025 12:51:08 +0200 Subject: [PATCH 4/5] Update src/utils/configure-aws.ts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Cristian Pallarés --- src/utils/configure-aws.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/utils/configure-aws.ts b/src/utils/configure-aws.ts index e8df973..48eef9d 100644 --- a/src/utils/configure-aws.ts +++ b/src/utils/configure-aws.ts @@ -57,8 +57,7 @@ function isValidEndpointUrl(url: string | undefined): boolean { return ( (parsed.protocol === "http:" || parsed.protocol === "https:") && VALID_HOSTNAMES.includes(parsed.hostname) && - parsed.port !== "" && // port must be present - (parsed.port === DEFAULT_PORT || /^\d+$/.test(parsed.port)) + parsed.port // port must be present ); } catch { return false; From f0444b14e837823d2c8d235792b681d366cef45c Mon Sep 17 00:00:00 2001 From: Anisa Oshafi Date: Mon, 8 Sep 2025 12:54:03 +0200 Subject: [PATCH 5/5] Update src/utils/configure-aws.ts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Cristian Pallarés --- src/utils/configure-aws.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utils/configure-aws.ts b/src/utils/configure-aws.ts index 48eef9d..d12c117 100644 --- a/src/utils/configure-aws.ts +++ b/src/utils/configure-aws.ts @@ -57,7 +57,7 @@ function isValidEndpointUrl(url: string | undefined): boolean { return ( (parsed.protocol === "http:" || parsed.protocol === "https:") && VALID_HOSTNAMES.includes(parsed.hostname) && - parsed.port // port must be present + parsed.port !== "" // port must be present ); } catch { return false;