Skip to content

feat(flags): expose region/edge flags #137

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

Merged
merged 2 commits into from
May 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"author": "Dominik Kundel <[email protected]>",
"license": "MIT",
"dependencies": {
"@twilio-labs/serverless-api": "^2.0.1",
"@twilio-labs/serverless-api": "^3.0.0",
"@twilio-labs/serverless-runtime-types": "^1.1.7",
"@types/express": "^4.17.0",
"@types/inquirer": "^6.0.3",
Expand Down
18 changes: 6 additions & 12 deletions src/commands/activate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ import {
logger,
setLogLevelByName,
} from '../utils/logger';
import { ExternalCliOptions, sharedCliOptions } from './shared';
import {
ExternalCliOptions,
sharedApiRelatedCliOptions,
sharedCliOptions,
} from './shared';
import { CliInfo } from './types';

const debug = getDebugFunction('twilio-run:activate');
Expand Down Expand Up @@ -83,6 +87,7 @@ export async function handler(
export const cliInfo: CliInfo = {
options: {
...sharedCliOptions,
...sharedApiRelatedCliOptions,
'service-sid': {
type: 'string',
describe: 'SID of the Twilio Serverless Service to deploy to',
Expand All @@ -108,17 +113,6 @@ export const cliInfo: CliInfo = {
describe:
'Promote build to the production environment (no domain suffix). Overrides environment flag',
},
'account-sid': {
type: 'string',
alias: 'u',
describe:
'A specific account SID to be used for deployment. Uses fields in .env otherwise',
},
'auth-token': {
type: 'string',
describe:
'Use a specific auth token for deployment. Uses fields from .env otherwise',
},
'create-environment': {
type: 'boolean',
describe: "Creates environment if it couldn't find it.",
Expand Down
18 changes: 6 additions & 12 deletions src/commands/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ import {
logger,
setLogLevelByName,
} from '../utils/logger';
import { ExternalCliOptions, sharedCliOptions } from './shared';
import {
ExternalCliOptions,
sharedApiRelatedCliOptions,
sharedCliOptions,
} from './shared';
import { CliInfo } from './types';
import { constructCommandName, getFullCommand } from './utils';

Expand Down Expand Up @@ -125,6 +129,7 @@ export async function handler(
export const cliInfo: CliInfo = {
options: {
...sharedCliOptions,
...sharedApiRelatedCliOptions,
cwd: {
type: 'string',
describe: 'Sets the directory from which to deploy',
Expand Down Expand Up @@ -163,17 +168,6 @@ export const cliInfo: CliInfo = {
describe:
'DEPRECATED: Overrides the name of the project. Default: the name field in your package.json',
},
'account-sid': {
type: 'string',
alias: 'u',
describe:
'A specific account SID to be used for deployment. Uses fields in .env otherwise',
},
'auth-token': {
type: 'string',
describe:
'Use a specific auth token for deployment. Uses fields from .env otherwise',
},
env: {
type: 'string',
describe:
Expand Down
18 changes: 6 additions & 12 deletions src/commands/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ import {
logger,
setLogLevelByName,
} from '../utils/logger';
import { ExternalCliOptions, sharedCliOptions } from './shared';
import {
ExternalCliOptions,
sharedApiRelatedCliOptions,
sharedCliOptions,
} from './shared';
import { CliInfo } from './types';
import { getFullCommand } from './utils';

Expand Down Expand Up @@ -74,6 +78,7 @@ export const cliInfo: CliInfo = {
},
options: {
...sharedCliOptions,
...sharedApiRelatedCliOptions,
'service-name': {
type: 'string',
alias: 'n',
Expand Down Expand Up @@ -108,17 +113,6 @@ export const cliInfo: CliInfo = {
describe: 'The environment to list variables for',
default: 'dev',
},
'account-sid': {
type: 'string',
alias: 'u',
describe:
'A specific account SID to be used for deployment. Uses fields in .env otherwise',
},
'auth-token': {
type: 'string',
describe:
'Use a specific auth token for deployment. Uses fields from .env otherwise',
},
'service-sid': {
type: 'string',
describe: 'Specific Serverless Service SID to run list for',
Expand Down
18 changes: 6 additions & 12 deletions src/commands/logs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ import {
logger,
setLogLevelByName,
} from '../utils/logger';
import { ExternalCliOptions, sharedCliOptions } from './shared';
import {
ExternalCliOptions,
sharedApiRelatedCliOptions,
sharedCliOptions,
} from './shared';
import { CliInfo } from './types';
import { getFullCommand } from './utils';

Expand Down Expand Up @@ -78,6 +82,7 @@ export async function handler(
export const cliInfo: CliInfo = {
options: {
...sharedCliOptions,
...sharedApiRelatedCliOptions,
'service-sid': {
type: 'string',
describe: 'Specific Serverless Service SID to retrieve logs for',
Expand All @@ -102,17 +107,6 @@ export const cliInfo: CliInfo = {
describe: 'Output the log in a different format',
choices: ['', 'json'],
},
'account-sid': {
type: 'string',
alias: 'u',
describe:
'A specific account SID to be used for deployment. Uses fields in .env otherwise',
},
'auth-token': {
type: 'string',
describe:
'Use a specific auth token for deployment. Uses fields from .env otherwise',
},
env: {
type: 'string',
describe:
Expand Down
28 changes: 27 additions & 1 deletion src/commands/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@ export type SharedFlags = BaseFlags & {
cwd?: string;
};

export type SharedFlagsWithCrdentials = SharedFlags & {
export type SharedFlagsWithCredentials = SharedFlags & {
accountSid?: string;
authToken?: string;
env?: string;
region?: string;
edge?: string;
};

export type ExternalCliOptions = {
Expand All @@ -36,6 +38,30 @@ export const baseCliOptions: { [key: string]: Options } = {
},
};

export const sharedApiRelatedCliOptions: { [key: string]: Options } = {
region: {
type: 'string',
hidden: true,
describe: 'Twilio API Region',
},
edge: {
type: 'string',
hidden: true,
describe: 'Twilio API Region',
},
'account-sid': {
type: 'string',
alias: 'u',
describe:
'A specific account SID to be used for deployment. Uses fields in .env otherwise',
},
'auth-token': {
type: 'string',
describe:
'Use a specific auth token for deployment. Uses fields from .env otherwise',
},
};

export const sharedCliOptions: { [key: string]: Options } = {
...baseCliOptions,
config: {
Expand Down
8 changes: 6 additions & 2 deletions src/config/activate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import checkForValidServiceSid from '../checks/check-service-sid';
import { cliInfo } from '../commands/activate';
import {
ExternalCliOptions,
SharedFlagsWithCrdentials,
SharedFlagsWithCredentials,
} from '../commands/shared';
import { getFullCommand } from '../commands/utils';
import { readSpecializedConfig } from './global';
Expand All @@ -19,7 +19,7 @@ type ActivateConfig = ApiActivateConfig & {
};

export type ActivateCliFlags = Arguments<
SharedFlagsWithCrdentials & {
SharedFlagsWithCredentials & {
cwd?: string;
serviceSid?: string;
buildSid?: string;
Expand Down Expand Up @@ -64,6 +64,8 @@ export async function getConfigFromFlags(

const command = getFullCommand(flags);
const serviceSid = checkForValidServiceSid(command, flags.serviceSid);
const region = flags.region;
const edge = flags.edge;

return {
cwd,
Expand All @@ -75,5 +77,7 @@ export async function getConfigFromFlags(
buildSid: flags.buildSid,
targetEnvironment: flags.environment,
sourceEnvironment: flags.sourceEnvironment,
region,
edge,
};
}
9 changes: 7 additions & 2 deletions src/config/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Arguments } from 'yargs';
import { cliInfo } from '../commands/deploy';
import {
ExternalCliOptions,
SharedFlagsWithCrdentials,
SharedFlagsWithCredentials,
} from '../commands/shared';
import { deprecateFunctionsEnv } from '../commands/utils';
import { getFunctionServiceSid } from '../serverless-api/utils';
Expand All @@ -18,7 +18,7 @@ import {
import { mergeFlagsAndConfig } from './utils/mergeFlagsAndConfig';

export type DeployCliFlags = Arguments<
SharedFlagsWithCrdentials & {
SharedFlagsWithCredentials & {
serviceSid?: string;
functionsEnv?: string;
environment: string;
Expand Down Expand Up @@ -105,6 +105,9 @@ export async function getConfigFromFlags(
);
}

const region = flags.region;
const edge = flags.edge;

return {
cwd,
envPath,
Expand All @@ -121,5 +124,7 @@ export async function getConfigFromFlags(
assetsFolderName: flags.assetsFolder,
noAssets: !flags.assets,
noFunctions: !flags.functions,
region,
edge,
};
}
8 changes: 6 additions & 2 deletions src/config/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { Arguments } from 'yargs';
import { cliInfo } from '../commands/list';
import {
ExternalCliOptions,
SharedFlagsWithCrdentials,
SharedFlagsWithCredentials,
} from '../commands/shared';
import { getFunctionServiceSid } from '../serverless-api/utils';
import { readSpecializedConfig } from './global';
Expand All @@ -21,7 +21,7 @@ export type ListConfig = ApiListConfig & {
};

export type ListCliFlags = Arguments<
SharedFlagsWithCrdentials & {
SharedFlagsWithCredentials & {
types: string;
projectName?: string;
serviceName?: string;
Expand Down Expand Up @@ -67,6 +67,8 @@ export async function getConfigFromFlags(
let serviceName = await getServiceNameFromFlags(flags);

const types = flags.types.split(',').map(trim) as ListOptions[];
const region = flags.region;
const edge = flags.edge;

return {
cwd,
Expand All @@ -80,5 +82,7 @@ export async function getConfigFromFlags(
: undefined,
extendedOutput: flags.extendedOutput,
types,
region,
edge,
};
}
28 changes: 18 additions & 10 deletions src/config/logs.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,31 @@
import { LogsConfig as ApiLogsConfig } from '@twilio-labs/serverless-api';
import {
ClientConfig,
LogsConfig as ApiLogsConfig,
} from '@twilio-labs/serverless-api';
import path from 'path';
import { Arguments } from 'yargs';
import checkForValidServiceSid from '../checks/check-service-sid';
import { cliInfo } from '../commands/logs';
import {
ExternalCliOptions,
SharedFlagsWithCrdentials,
SharedFlagsWithCredentials,
} from '../commands/shared';
import { getFullCommand } from '../commands/utils';
import { readSpecializedConfig } from './global';
import { getCredentialsFromFlags } from './utils';
import { mergeFlagsAndConfig } from './utils/mergeFlagsAndConfig';

export type LogsConfig = ApiLogsConfig & {
cwd: string;
accountSid: string;
authToken: string;
properties?: string[];
outputFormat?: string;
};
export type LogsConfig = ClientConfig &
ApiLogsConfig & {
cwd: string;
accountSid: string;
authToken: string;
properties?: string[];
outputFormat?: string;
};

export type LogsCliFlags = Arguments<
SharedFlagsWithCrdentials & {
SharedFlagsWithCredentials & {
cwd?: string;
environment?: string;
serviceSid?: string;
Expand Down Expand Up @@ -61,6 +65,8 @@ export async function getConfigFromFlags(
const command = getFullCommand(flags);
const serviceSid = checkForValidServiceSid(command, flags.serviceSid);
const outputFormat = flags.outputFormat || externalCliOptions?.outputFormat;
const region = flags.region;
const edge = flags.edge;

return {
cwd,
Expand All @@ -71,5 +77,7 @@ export async function getConfigFromFlags(
outputFormat,
filterByFunction: flags.functionSid,
tail: flags.tail,
region,
edge,
};
}
4 changes: 2 additions & 2 deletions src/config/utils/credentials.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {
ExternalCliOptions,
SharedFlagsWithCrdentials,
SharedFlagsWithCredentials,
} from '../../commands/shared';
import { getDebugFunction } from '../../utils/logger';
import { readLocalEnvFile } from './env';
Expand All @@ -24,7 +24,7 @@ export type Credentials = {
* @param externalCliOptions Any external information for example passed by the Twilio CLI
*/
export async function getCredentialsFromFlags<
T extends SharedFlagsWithCrdentials
T extends SharedFlagsWithCredentials
>(flags: T, externalCliOptions?: ExternalCliOptions): Promise<Credentials> {
// default Twilio CLI credentials (4) or empty string (5)
let accountSid =
Expand Down