Skip to content

Commit

Permalink
When setting or deleting value in specific region, list-keys for this…
Browse files Browse the repository at this point in the history
… region and not the default region.
  • Loading branch information
Shaharshaki2 committed Sep 9, 2024
1 parent 97247b5 commit 40c314b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
12 changes: 9 additions & 3 deletions src/commands/code/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -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,
});
Expand Down Expand Up @@ -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 });

Expand Down
16 changes: 9 additions & 7 deletions src/commands/code/secret.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -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,
});
Expand Down Expand Up @@ -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);

Expand Down

0 comments on commit 40c314b

Please sign in to comment.