Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: add support for multi-region param #93

Merged
merged 24 commits into from
Jun 3, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
fd2a454
feature: add support for multi region param
ShayElkana May 20, 2024
45eae8d
feature: add support for multi region param
ShayElkana May 21, 2024
2eea75e
feature: add support for multi region param
ShayElkana May 21, 2024
7484ca2
feature: add support for multi region param
ShayElkana May 21, 2024
d4162b4
feature: add support for multi region param
ShayElkana May 23, 2024
35c5318
feature: add support for multi region param
ShayElkana May 23, 2024
ad8dd32
feature: add support for multi region param
ShayElkana May 23, 2024
88f2843
feature: add support for multi region param
ShayElkana May 23, 2024
86ece06
feature: add support for multi region param
ShayElkana May 26, 2024
c8bf7af
feature: add support for multi region param
ShayElkana May 27, 2024
f5bd864
feature: add support for multi region param
ShayElkana May 27, 2024
89d2e2d
feature: add support for multi region param
ShayElkana May 27, 2024
0ff9f83
feature: add support for multi region param
ShayElkana May 28, 2024
6249024
feature: add support for multi region param
ShayElkana May 28, 2024
b411639
feature: add support for multi region param
ShayElkana May 28, 2024
dcec6c4
feature: update version
ShayElkana May 29, 2024
211d0a8
Merge branch 'refs/heads/master' into feature/shayel/add_support_for_…
ShayElkana May 29, 2024
ebbec67
feature: remove specific error
ShayElkana May 29, 2024
d7a0e40
feature: version#
ShayElkana May 29, 2024
dd75910
Merge branch 'refs/heads/master' into feature/shayel/add_support_for_…
ShayElkana May 29, 2024
38f5c81
feature: [beta] mutli-region support basic cli flags
ShayElkana May 29, 2024
7bae5a0
feature: [beta] mutli-region support basic cli flags
ShayElkana May 29, 2024
a8e737e
feature: [beta] fix imports
ShayElkana May 29, 2024
ac5e8ce
Feature/shayel/add support for multi region param interactive (#96)
ShayElkana Jun 3, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 18 additions & 17 deletions src/commands-base/base-command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,6 @@ 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 @@ -44,13 +30,28 @@ export abstract class BaseCommand extends Command {
this._printContext = { command, flags, args };
}

public static serializeFlags<T>(flags: T): T & typeof sharedFlags {
public static serializeFlags<T>(flags: T): T & typeof this.sharedFlags {
return {
...sharedFlags,
...this.sharedFlags,
...flags,
} as typeof flags & typeof sharedFlags;
} as typeof flags & typeof this.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
17 changes: 11 additions & 6 deletions src/commands/app/deploy.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { Flags } from '@oclif/core';

import { addToRegionToFlags } from 'commands/utils/region';
import { addRegionToFlags } from 'commands/utils/region';
import { AuthenticatedCommand } from 'commands-base/authenticated-command';
import { DynamicChoicesService } from 'services/dynamic-choices-service';
import { getCurrentWorkingDirectory } from 'services/env-service';
import { getManifestAssetPath, readManifestFile } from 'services/manifest-service';
import { getTasksForClientSide, getTasksForServerSide } from 'services/share/deploy';
import { Region } from 'types/general/region';
import { ManifestHostingType } from 'types/services/manifest-service';
import logger from 'utils/logger';
import { getRegionFromString } from 'utils/region';

const MESSAGES = {
directory: 'Directory path of you project in your machine. If not included will use the current working directory.',
Expand All @@ -22,7 +22,7 @@ export default class AppDeploy extends AuthenticatedCommand {
static withPrintCommand = false;
static examples = ['<%= config.bin %> <%= command.id %>'];
static flags = AppDeploy.serializeFlags(
addToRegionToFlags({
addRegionToFlags({
directoryPath: Flags.string({
char: 'd',
description: MESSAGES.directory,
Expand Down Expand Up @@ -61,7 +61,8 @@ export default class AppDeploy extends AuthenticatedCommand {
public async run(): Promise<void> {
try {
const { flags } = await this.parse(AppDeploy);
const { directoryPath, appId, appVersionId, region, force } = flags;
const { directoryPath, appId, appVersionId, region: strRegion, force } = flags;
const region = getRegionFromString(strRegion);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can also simplify things by getting rid of redundant const regionStr

Suggested change
const { directoryPath, appId, appVersionId, region: strRegion, force } = flags;
const region = getRegionFromString(strRegion);
const { directoryPath, appId, appVersionId, force } = flags;
const region = getRegionFromString(flags?.region);

const manifestFileDir = directoryPath || getCurrentWorkingDirectory();
const manifestFileData = readManifestFile(manifestFileDir);
flags.appId = appId || manifestFileData.app.id;
Expand All @@ -73,15 +74,19 @@ export default class AppDeploy extends AuthenticatedCommand {
const { cdn, server } = manifestFileData.app?.hosting || {};
if (cdn && cdn.type === ManifestHostingType.Upload) {
logger.info('Deploying files to cdn...');
await getTasksForClientSide(Number(appVersionId), getManifestAssetPath(manifestFileDir, cdn.path)).run();
await getTasksForClientSide(
Number(appVersionId),
getManifestAssetPath(manifestFileDir, cdn.path),
region,
).run();
}

if (server && server.type === ManifestHostingType.Upload) {
logger.info('Deploying server side files...');
await getTasksForServerSide(
Number(appVersionId),
getManifestAssetPath(manifestFileDir, server.path),
region as Region,
region,
).run();
}
} catch (error) {
Expand Down
11 changes: 6 additions & 5 deletions src/commands/code/env.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { Flags } from '@oclif/core';
import { Relationship } from '@oclif/core/lib/interfaces/parser';

import { addToRegionToFlags } from 'commands/utils/region';
import { addRegionToFlags } 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';
import { getRegionFromString } from 'utils/region';

const MODES_WITH_KEYS: Array<APP_ENV_MANAGEMENT_MODES> = [
APP_ENV_MANAGEMENT_MODES.SET,
Expand Down Expand Up @@ -71,7 +71,7 @@ export default class Env extends AuthenticatedCommand {
static examples = ['<%= config.bin %> <%= command.id %>'];

static flags = Env.serializeFlags(
addToRegionToFlags({
addRegionToFlags({
appId: Flags.integer({
char: 'i',
aliases: ['a'],
Expand Down Expand Up @@ -100,7 +100,8 @@ export default class Env extends AuthenticatedCommand {
public async run(): Promise<void> {
try {
const { flags } = await this.parse(Env);
const { region } = flags;
const { region: strRegion } = flags;
const region = getRegionFromString(strRegion);
let { mode, key, value, appId } = flags as ManageAppEnvFlags;

if (!appId) {
Expand All @@ -112,7 +113,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, region as Region);
await handleEnvironmentRequest(appId, mode, key, value, region);
} catch (error: any) {
logger.debug(error, this.DEBUG_TAG);

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

import { addToRegionToFlags } from 'commands/utils/region';
import { addRegionToFlags } 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 { getRegionFromString } from 'utils/region';
import { TIME_IN_MILLISECONDS } from 'utils/time-enum';
import { getDayDiff, isDate } from 'utils/validations';

Expand Down Expand Up @@ -49,7 +49,7 @@ export default class Logs extends AuthenticatedCommand {
static examples = ['<%= config.bin %> <%= command.id %> -i APP_VERSION_ID -t LOGS_TYPE'];

static flags = Logs.serializeFlags(
addToRegionToFlags({
addRegionToFlags({
appVersionId: Flags.integer({
char: 'i',
aliases: ['v'],
Expand Down Expand Up @@ -87,7 +87,8 @@ export default class Logs extends AuthenticatedCommand {
public async run(): Promise<void> {
try {
const { flags } = await this.parse(Logs);
const { logsStartDate, logsEndDate, logSearchFromText, region } = flags;
const { logsStartDate, logsEndDate, logSearchFromText, region: strRegion } = flags;
const region = getRegionFromString(strRegion);
const appVersionId = await this.getAppVersionId(flags.appVersionId);

const eventSource = (flags.eventSource || (await eventSourcePrompt())) as EventSource;
Expand All @@ -114,7 +115,7 @@ export default class Logs extends AuthenticatedCommand {
logSearchFromText: logsFilterCriteria?.text,
});

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

import { addToRegionToFlags } from 'commands/utils/region';
import { addRegionToFlags } 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';
import { getRegionFromString } from 'utils/region';

const MESSAGES = {
directory: 'Directory path of you project in your machine. If not included will use the current working directory.',
Expand All @@ -24,7 +24,7 @@ export default class Push extends AuthenticatedCommand {
];

static flags = Push.serializeFlags(
addToRegionToFlags({
addRegionToFlags({
directoryPath: Flags.string({
char: 'd',
description: MESSAGES.directory,
Expand All @@ -50,7 +50,8 @@ export default class Push extends AuthenticatedCommand {

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

try {
Expand All @@ -68,7 +69,7 @@ export default class Push extends AuthenticatedCommand {
logger.debug(`push code to appVersionId: ${appVersionId}`, this.DEBUG_TAG);
this.preparePrintCommand(this, { appVersionId, directoryPath: directoryPath });

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

await tasks.run();
} catch (error: any) {
Expand Down
13 changes: 7 additions & 6 deletions src/commands/code/status.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { Flags } from '@oclif/core';
maorb-dev marked this conversation as resolved.
Show resolved Hide resolved
import { StatusCodes } from 'http-status-codes';

import { addToRegionToFlags } from 'commands/utils/region';
import { addRegionToFlags } 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';
import { getRegionFromString } from 'utils/region';

const printDeploymentStatus = (
appVersionId: number,
Expand All @@ -37,7 +37,7 @@ export default class Status extends AuthenticatedCommand {
static examples = ['<%= config.bin %> <%= command.id %> -i APP_VERSION_ID'];

static flags = Status.serializeFlags(
addToRegionToFlags({
addRegionToFlags({
appVersionId: Flags.integer({
char: 'i',
aliases: ['v'],
Expand All @@ -48,7 +48,8 @@ export default class Status extends AuthenticatedCommand {

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

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

if (deploymentStatus.deployment) {
deploymentStatus.deployment.liveUrl = mondayCodeRelease?.data?.liveUrl;
Expand Down
4 changes: 2 additions & 2 deletions src/commands/utils/region.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ export const regionFlag = {
}),
};

export function addToRegionToFlags<T>(flags: T): T {
if (isPermitted(Permissions.MULTI_REGION)) {
export function addRegionToFlags<T>(flags: T): T {
if (isPermitted(Permissions.MCODE_MULTI_REGION)) {
return {
...flags,
...regionFlag,
Expand Down
8 changes: 4 additions & 4 deletions src/services/manage-app-env-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import { HttpMethodTypes } from 'types/services/api-service';
import { ListAppEnvironmentKeysResponse } from 'types/services/manage-app-env-service';
import logger from 'utils/logger';
import { queryBuilderAddRegion } from 'utils/region';
import { addRegionToQuery } from 'utils/region';
import { appsUrlBuilder } from 'utils/urls-builder';

const handleHttpErrors = (error: HttpError) => {
Expand All @@ -33,7 +33,7 @@
try {
const path = appEnvironmentKeysUrl(appId);
const url = appsUrlBuilder(path);
const query = queryBuilderAddRegion({}, region);
const query = addRegionToQuery({}, region);

const response = await execute<ListAppEnvironmentKeysResponse>(
{
Expand All @@ -59,7 +59,7 @@
try {
const path = appEnvironmentUrl(appId, key);
const url = appsUrlBuilder(path);
const query = queryBuilderAddRegion({}, region);
const query = addRegionToQuery({}, region);

await execute({
query,
Expand All @@ -81,7 +81,7 @@
try {
const path = appEnvironmentUrl(appId, key);
const url = appsUrlBuilder(path);
const query = queryBuilderAddRegion({}, region);
const query = addRegionToQuery({}, region);

await execute({
query,
Expand Down Expand Up @@ -144,7 +144,7 @@
key?: string,
value?: string,
region?: Region,
) => {

Check warning on line 147 in src/services/manage-app-env-service.ts

View workflow job for this annotation

GitHub Actions / Run validations

Async arrow function has too many parameters (5). Maximum allowed is 4
if (!appId || !mode) {
throw new Error('appId and mode are required');
}
Expand Down
4 changes: 2 additions & 2 deletions src/services/notification-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { Region } from 'types/general/region';
import { HttpMethodTypes } from 'types/services/api-service';
import { ClientChannel } from 'types/services/notification-service';
import logger from 'utils/logger';
import { queryBuilderAddRegion } from 'utils/region';
import { addRegionToQuery } from 'utils/region';
import { appsUrlBuilder } from 'utils/urls-builder';

export const logsStream = async (
Expand All @@ -22,7 +22,7 @@ export const logsStream = async (
const logsStreamForUrl = getLogsStreamForAppVersionIdUrl(appVersionId, logsType, logsFilterCriteria);
const url = appsUrlBuilder(logsStreamForUrl);
logger.debug(`fetching logs url: ${url}`);
const query = queryBuilderAddRegion({}, region);
const query = addRegionToQuery({}, region);
const response = await execute<ClientChannel>(
{
query,
Expand Down
6 changes: 3 additions & 3 deletions src/services/push-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@ import {
} from 'types/services/push-service';
import logger from 'utils/logger';
import { createProgressBarString } from 'utils/progress-bar';
import { queryBuilderAddRegion } from 'utils/region';
import { addRegionToQuery } from 'utils/region';
import { appsUrlBuilder } from 'utils/urls-builder';

export const getSignedStorageUrl = async (appVersionId: number, region?: Region): Promise<string> => {
const DEBUG_TAG = 'get_signed_storage_url';
try {
const baseSignUrl = getDeploymentSignedUrl(appVersionId);
const url = appsUrlBuilder(baseSignUrl);
const query = queryBuilderAddRegion({}, region);
const query = addRegionToQuery({}, region);

const response = await execute<SignedUrl>(
{
Expand Down Expand Up @@ -77,7 +77,7 @@ export const getAppVersionDeploymentStatus = async (appVersionId: number, region
try {
const baseAppVersionIdStatusUrl = getAppVersionDeploymentStatusUrl(appVersionId);
const url = appsUrlBuilder(baseAppVersionIdStatusUrl);
const query = queryBuilderAddRegion({}, region);
const query = addRegionToQuery({}, region);

const response = await execute<AppVersionDeploymentStatus>(
{
Expand Down
Loading
Loading