Skip to content

Commit

Permalink
feature: add support for multi region param
Browse files Browse the repository at this point in the history
  • Loading branch information
ShayElkana committed May 20, 2024
1 parent bedf62b commit fd2a454
Show file tree
Hide file tree
Showing 18 changed files with 237 additions and 119 deletions.
36 changes: 18 additions & 18 deletions src/commands-base/base-command.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,24 @@
import { Command, Flags } from '@oclif/core';

import { regionFlag } from 'commands/utils/region';

Check failure on line 3 in src/commands-base/base-command.ts

View workflow job for this annotation

GitHub Actions / Run validations

'regionFlag' is defined but never used
import { PrintCommandContext } from 'types/commands/base-command';
import { printGeneratedCommand } from 'utils/command-printer';
import logger from 'utils/logger';

export const sharedFlags = {
verbose: Flags.boolean({
description: 'Print advanced logs (optional).',
default: false,
helpGroup: 'global',
}),

'print-command': Flags.boolean({
aliases: ['pc'],
description: 'Print the command that was executed (optional).',
default: false,
helpGroup: 'global',
}),
};
export abstract class BaseCommand extends Command {
protected static _withPrintCommand = true;
private _printCommandCalled = false;
Expand All @@ -30,28 +45,13 @@ export abstract class BaseCommand extends Command {
this._printContext = { command, flags, args };
}

public static serializeFlags<T>(flags: T): T & typeof this.sharedFlags {
public static serializeFlags<T>(flags: T): T & typeof sharedFlags {
return {
...this.sharedFlags,
...sharedFlags,
...flags,
} as typeof flags & typeof this.sharedFlags;
} as typeof flags & typeof sharedFlags;
}

static sharedFlags? = {
verbose: Flags.boolean({
description: 'Print advanced logs (optional).',
default: false,
helpGroup: 'global',
}),

'print-command': Flags.boolean({
aliases: ['pc'],
description: 'Print the command that was executed (optional).',
default: false,
helpGroup: 'global',
}),
};

protected catch(err: Error & { exitCode?: number }): any {
err?.message && logger.error((err as Error).message);
logger.debug(err);
Expand Down
49 changes: 27 additions & 22 deletions src/commands/code/env.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import { Flags } from '@oclif/core';
import { Relationship } from '@oclif/core/lib/interfaces/parser';

import { addToRegionToFlags } from 'commands/utils/region';
import { AuthenticatedCommand } from 'commands-base/authenticated-command';
import { APP_ENV_MANAGEMENT_MODES } from 'consts/manage-app-env';
import { DynamicChoicesService } from 'services/dynamic-choices-service';
import { handleEnvironmentRequest, listAppEnvKeys } from 'services/manage-app-env-service';
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';

const MODES_WITH_KEYS: Array<APP_ENV_MANAGEMENT_MODES> = [
Expand Down Expand Up @@ -68,34 +70,37 @@ export default class Env extends AuthenticatedCommand {

static examples = ['<%= config.bin %> <%= command.id %>'];

static flags = Env.serializeFlags({
appId: Flags.integer({
char: 'i',
aliases: ['a'],
description: 'The id of the app to manage environment variables for',
static flags = Env.serializeFlags(
addToRegionToFlags({
appId: Flags.integer({
char: 'i',
aliases: ['a'],
description: 'The id of the app to manage environment variables for',
}),
mode: Flags.string({
char: 'm',
description: 'management mode',
options: Object.values(APP_ENV_MANAGEMENT_MODES),
}),
key: Flags.string({
char: 'k',
description: 'variable key [required for set and delete]]',
relationships: [flagsWithModeRelationships],
}),
value: Flags.string({
char: 'v',
description: 'variable value [required for set]',
relationships: [flagsWithModeRelationships],
}),
}),
mode: Flags.string({
char: 'm',
description: 'management mode',
options: Object.values(APP_ENV_MANAGEMENT_MODES),
}),
key: Flags.string({
char: 'k',
description: 'variable key [required for set and delete]]',
relationships: [flagsWithModeRelationships],
}),
value: Flags.string({
char: 'v',
description: 'variable value [required for set]',
relationships: [flagsWithModeRelationships],
}),
});
);

static args = {};
DEBUG_TAG = 'env';
public async run(): Promise<void> {
try {
const { flags } = await this.parse(Env);
const { region } = flags;
let { mode, key, value, appId } = flags as ManageAppEnvFlags;

if (!appId) {
Expand All @@ -107,7 +112,7 @@ export default class Env extends AuthenticatedCommand {
value = await promptForValueIfNotProvided(mode, value);
this.preparePrintCommand(this, { appId, mode, key, value });

await handleEnvironmentRequest(appId, mode, key, value);
await handleEnvironmentRequest(appId, mode, key, value, region as Region);
} catch (error: any) {
logger.debug(error, this.DEBUG_TAG);

Expand Down
72 changes: 38 additions & 34 deletions src/commands/code/logs.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import { Flags } from '@oclif/core';
import { Relationship } from '@oclif/core/lib/interfaces/parser';

import { addToRegionToFlags } from 'commands/utils/region';
import { AuthenticatedCommand } from 'commands-base/authenticated-command';
import { APP_VERSION_ID_TO_ENTER } from 'consts/messages';
import { streamMessages } from 'services/client-channel-service';
import { DynamicChoicesService } from 'services/dynamic-choices-service';
import { logsStream } from 'services/notification-service';
import { PromptService } from 'services/prompt-service';
import { EventSource, LogType, LogsCommandArguments, LogsFilterCriteriaArguments } from 'types/commands/logs';
import { Region } from 'types/general/region';
import { isDefined } from 'utils/guards';
import logger from 'utils/logger';
import { TIME_IN_MILLISECONDS } from 'utils/time-enum';
Expand Down Expand Up @@ -46,53 +48,55 @@ export default class Logs extends AuthenticatedCommand {

static examples = ['<%= config.bin %> <%= command.id %> -i APP_VERSION_ID -t LOGS_TYPE'];

static flags = Logs.serializeFlags({
appVersionId: Flags.integer({
char: 'i',
aliases: ['v'],
description: APP_VERSION_ID_TO_ENTER,
static flags = Logs.serializeFlags(
addToRegionToFlags({
appVersionId: Flags.integer({
char: 'i',
aliases: ['v'],
description: APP_VERSION_ID_TO_ENTER,
}),
logsType: Flags.string({
char: 't',
description: LOGS_TYPE_TO_LISTEN_PROMPT_MESSAGE,
}),
eventSource: Flags.string({
char: 's',
description: EVENT_SOURCE,
}),
logsStartDate: Flags.string({
char: 'f',
description: 'Start date (MM/DD/YYYY HH:mm) e.g. "03/24/1983 15:45"' + SUPPORTED_HISTORY_FLAGS,
relationships,
}),
logsEndDate: Flags.string({
char: 'e',
description: 'End date (MM/DD/YYYY HH:mm) e.g. "03/25/1983 16:45"' + SUPPORTED_HISTORY_FLAGS,
relationships,
}),
logSearchFromText: Flags.string({
char: 'r',
description: EVENT_SEARCH_FOR_TEXT,
relationships,
}),
}),
logsType: Flags.string({
char: 't',
description: LOGS_TYPE_TO_LISTEN_PROMPT_MESSAGE,
}),
eventSource: Flags.string({
char: 's',
description: EVENT_SOURCE,
}),
logsStartDate: Flags.string({
char: 'f',
description: 'Start date (MM/DD/YYYY HH:mm) e.g. "03/24/1983 15:45"' + SUPPORTED_HISTORY_FLAGS,
relationships,
}),
logsEndDate: Flags.string({
char: 'e',
description: 'End date (MM/DD/YYYY HH:mm) e.g. "03/25/1983 16:45"' + SUPPORTED_HISTORY_FLAGS,
relationships,
}),
logSearchFromText: Flags.string({
char: 'r',
description: EVENT_SEARCH_FOR_TEXT,
relationships,
}),
});
);

static args = {};
DEBUG_TAG = 'logs';

public async run(): Promise<void> {
try {
const { flags } = await this.parse(Logs);

const { logsStartDate, logsEndDate, logSearchFromText, region } = flags;
const appVersionId = await this.getAppVersionId(flags.appVersionId);

const eventSource = (flags.eventSource || (await eventSourcePrompt())) as EventSource;
const logsType = await this.getLogType(eventSource, flags.logsType);
const logsFilterCriteria = await this.getLogsFilterCriteria(
eventSource,
flags.logsStartDate,
flags.logsEndDate,
flags.logSearchFromText,
logsStartDate,
logsEndDate,
logSearchFromText,
);

const args: LogsCommandArguments = {
Expand All @@ -110,7 +114,7 @@ export default class Logs extends AuthenticatedCommand {
logSearchFromText: logsFilterCriteria?.text,
});

const clientChannel = await logsStream(args.appVersionId, args.logsType, logsFilterCriteria);
const clientChannel = await logsStream(args.appVersionId, args.logsType, logsFilterCriteria, region as Region);
await streamMessages(clientChannel);
} catch (error: any) {
logger.debug(error, this.DEBUG_TAG);
Expand Down
45 changes: 25 additions & 20 deletions src/commands/code/push.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { Flags } from '@oclif/core';

import { addToRegionToFlags } from 'commands/utils/region';
import { AuthenticatedCommand } from 'commands-base/authenticated-command';
import { APP_ID_TO_ENTER, APP_VERSION_ID_TO_ENTER } from 'consts/messages';
import { DynamicChoicesService } from 'services/dynamic-choices-service';
import { getTasksForServerSide } from 'services/share/deploy';
import { Region } from 'types/general/region';
import logger from 'utils/logger';

const MESSAGES = {
Expand All @@ -21,31 +23,34 @@ export default class Push extends AuthenticatedCommand {
'<%= config.bin %> <%= command.id %> -a APP_ID_TO_PUSH',
];

static flags = Push.serializeFlags({
directoryPath: Flags.string({
char: 'd',
description: MESSAGES.directory,
static flags = Push.serializeFlags(
addToRegionToFlags({
directoryPath: Flags.string({
char: 'd',
description: MESSAGES.directory,
}),
appId: Flags.string({
char: 'a',
description: MESSAGES.appId,
}),
appVersionId: Flags.integer({
char: 'i',
aliases: ['v'],
description: MESSAGES.appVersionId,
}),
force: Flags.boolean({
char: 'f',
description: MESSAGES.force,
}),
}),
appId: Flags.string({
char: 'a',
description: MESSAGES.appId,
}),
appVersionId: Flags.integer({
char: 'i',
aliases: ['v'],
description: MESSAGES.appVersionId,
}),
force: Flags.boolean({
char: 'f',
description: MESSAGES.force,
}),
});
);

static args = {};
DEBUG_TAG = 'code_push';

public async run(): Promise<void> {
const { flags } = await this.parse(Push);
const { directoryPath, region } = flags;
let appVersionId = flags.appVersionId;

try {
Expand All @@ -61,9 +66,9 @@ export default class Push extends AuthenticatedCommand {
}

logger.debug(`push code to appVersionId: ${appVersionId}`, this.DEBUG_TAG);
this.preparePrintCommand(this, { appVersionId, directoryPath: flags.directoryPath });
this.preparePrintCommand(this, { appVersionId, directoryPath: directoryPath });

const tasks = getTasksForServerSide(appVersionId, flags.directoryPath);
const tasks = getTasksForServerSide(appVersionId, directoryPath, region as Region);

await tasks.run();
} catch (error: any) {
Expand Down
21 changes: 13 additions & 8 deletions src/commands/code/status.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import { Flags } from '@oclif/core';
import { StatusCodes } from 'http-status-codes';

import { addToRegionToFlags } from 'commands/utils/region';
import { AuthenticatedCommand } from 'commands-base/authenticated-command';
import { APP_VERSION_ID_TO_ENTER, VAR_UNKNOWN } from 'consts/messages';
import { DynamicChoicesService } from 'services/dynamic-choices-service';
import { getAppVersionDeploymentStatus } from 'services/push-service';
import { getMondayCodeBuild } from 'src/services/app-builds-service';
import { HttpError } from 'types/errors';
import { Region } from 'types/general/region';
import { AppVersionDeploymentStatus } from 'types/services/push-service';
import logger from 'utils/logger';

Expand Down Expand Up @@ -34,16 +36,19 @@ export default class Status extends AuthenticatedCommand {

static examples = ['<%= config.bin %> <%= command.id %> -i APP_VERSION_ID'];

static flags = Status.serializeFlags({
appVersionId: Flags.integer({
char: 'i',
aliases: ['v'],
description: APP_VERSION_ID_TO_ENTER,
static flags = Status.serializeFlags(
addToRegionToFlags({
appVersionId: Flags.integer({
char: 'i',
aliases: ['v'],
description: APP_VERSION_ID_TO_ENTER,
}),
}),
});
);

public async run(): Promise<void> {
const { flags } = await this.parse(Status);
const { region } = flags;
let appVersionId = flags.appVersionId;
try {
if (!appVersionId) {
Expand All @@ -52,8 +57,8 @@ export default class Status extends AuthenticatedCommand {
}

this.preparePrintCommand(this, { appVersionId });
const deploymentStatus = await getAppVersionDeploymentStatus(appVersionId);
const mondayCodeRelease = await getMondayCodeBuild(appVersionId);
const deploymentStatus = await getAppVersionDeploymentStatus(appVersionId, region as Region);
const mondayCodeRelease = await getMondayCodeBuild(appVersionId, region as Region);

if (deploymentStatus.deployment) {
deploymentStatus.deployment.liveUrl = mondayCodeRelease?.data?.liveUrl;
Expand Down
Loading

0 comments on commit fd2a454

Please sign in to comment.