From 40c314b95a6242b1a35ca7bc26b71892423f7388 Mon Sep 17 00:00:00 2001 From: Shahar Shaki Date: Mon, 9 Sep 2024 11:52:52 +0300 Subject: [PATCH] When setting or deleting value in specific region, list-keys for this region and not the default region. --- src/commands/code/env.ts | 12 +++++++++--- src/commands/code/secret.ts | 16 +++++++++------- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/src/commands/code/env.ts b/src/commands/code/env.ts index 43a16f3..8e852ac 100644 --- a/src/commands/code/env.ts +++ b/src/commands/code/env.ts @@ -8,6 +8,7 @@ import { handleEnvironmentRequest, listAppEnvKeys } from 'services/manage-app-en import { PromptService } from 'services/prompt-service'; import { ManageAppEnvFlags } from 'types/commands/manage-app-env'; import { AppId } from 'types/general'; +import { Region } from 'types/general/region'; import logger from 'utils/logger'; import { addRegionToFlags, chooseRegionIfNeeded, getRegionFromString } from 'utils/region'; @@ -30,9 +31,14 @@ const promptForModeIfNotProvided = async (mode?: APP_ENV_MANAGEMENT_MODES) => { return mode; }; -const promptForKeyIfNotProvided = async (mode: APP_ENV_MANAGEMENT_MODES, appId: AppId, key?: string) => { +const promptForKeyIfNotProvided = async ( + mode: APP_ENV_MANAGEMENT_MODES, + appId: AppId, + key?: string, + region?: Region, +) => { if (!key && isKeyRequired(mode)) { - const existingKeys = await listAppEnvKeys(appId); + const existingKeys = await listAppEnvKeys(appId, region); key = await PromptService.promptSelectionWithAutoComplete('Enter key for environment variable', existingKeys, { includeInputInSelection: true, }); @@ -110,7 +116,7 @@ export default class Env extends AuthenticatedCommand { const selectedRegion = await chooseRegionIfNeeded(region, { appId }); mode = await promptForModeIfNotProvided(mode); - key = await promptForKeyIfNotProvided(mode, appId, key); + key = await promptForKeyIfNotProvided(mode, appId, key, selectedRegion); value = await promptForValueIfNotProvided(mode, value); this.preparePrintCommand(this, { appId, mode, key, value, region: selectedRegion }); diff --git a/src/commands/code/secret.ts b/src/commands/code/secret.ts index 40ce0c5..0a96502 100644 --- a/src/commands/code/secret.ts +++ b/src/commands/code/secret.ts @@ -8,6 +8,7 @@ import { handleSecretRequest, listAppSecretKeys } from 'services/manage-app-secr import { PromptService } from 'services/prompt-service'; import { ManageAppSecretFlags } from 'types/commands/manage-app-secret'; import { AppId } from 'types/general'; +import { Region } from 'types/general/region'; import logger from 'utils/logger'; import { addRegionToFlags, chooseRegionIfNeeded, getRegionFromString } from 'utils/region'; @@ -30,9 +31,14 @@ const promptForModeIfNotProvided = async (mode?: APP_SECRET_MANAGEMENT_MODES) => return mode; }; -const promptForKeyIfNotProvided = async (mode: APP_SECRET_MANAGEMENT_MODES, appId: AppId, key?: string) => { +const promptForKeyIfNotProvided = async ( + mode: APP_SECRET_MANAGEMENT_MODES, + appId: AppId, + key?: string, + region?: Region, +) => { if (!key && isKeyRequired(mode)) { - const existingKeys = await listAppSecretKeys(appId); + const existingKeys = await listAppSecretKeys(appId, region); key = await PromptService.promptSelectionWithAutoComplete('Enter key for secret variable', existingKeys, { includeInputInSelection: true, }); @@ -108,15 +114,11 @@ export default class Secret extends AuthenticatedCommand { } const selectedRegion = await chooseRegionIfNeeded(region, { appId }); - mode = await promptForModeIfNotProvided(mode); - key = await promptForKeyIfNotProvided(mode, appId, key); + key = await promptForKeyIfNotProvided(mode, appId, key, selectedRegion); value = await promptForValueIfNotProvided(mode, value); this.preparePrintCommand(this, { appId, mode, key, value, region: selectedRegion }); - console.log("1") - await handleSecretRequest(appId, mode, key, value, selectedRegion); - console.log("4") } catch (error: any) { logger.debug(error, this.DEBUG_TAG);