File tree Expand file tree Collapse file tree 5 files changed +53
-16
lines changed Expand file tree Collapse file tree 5 files changed +53
-16
lines changed Original file line number Diff line number Diff line change 1+ import { filterEnvVariablesForDeploy } from '../../../src/config/utils/env' ;
2+ import { EnvironmentVariablesWithAuth } from '../../../src/types/generic' ;
3+
4+ describe ( 'filterEnvVariablesForDeploy' , ( ) => {
5+ const testVars : EnvironmentVariablesWithAuth = {
6+ ACCOUNT_SID : 'ACCOUNT_SID' ,
7+ AUTH_TOKEN : 'AUTH_TOKEN' ,
8+ empty : '' ,
9+ hello : 'world' ,
10+ } ;
11+
12+ it ( 'deletes ACCOUNT_SID and AUTH_TOKEN' , ( ) => {
13+ const deployVars = filterEnvVariablesForDeploy ( testVars ) ;
14+ expect ( deployVars [ 'ACCOUNT_SID' ] ) . toBeUndefined ( ) ;
15+ expect ( deployVars [ 'AUTH_TOKEN' ] ) . toBeUndefined ( ) ;
16+ } ) ;
17+
18+ it ( 'deletes empty env vars' , ( ) => {
19+ const deployVars = filterEnvVariablesForDeploy ( testVars ) ;
20+ expect ( deployVars [ 'empty' ] ) . toBeUndefined ( ) ;
21+ } ) ;
22+
23+ it ( 'leaves other variables as they were' , ( ) => {
24+ const deployVars = filterEnvVariablesForDeploy ( testVars ) ;
25+ expect ( deployVars [ 'hello' ] ) . toEqual ( 'world' ) ;
26+ } ) ;
27+ } ) ;
Original file line number Diff line number Diff line change 3838 "author" : " Dominik Kundel <dkundel@twilio.com>" ,
3939 "license" : " MIT" ,
4040 "dependencies" : {
41- "@twilio-labs/serverless-api" : " ^3.0 .0" ,
41+ "@twilio-labs/serverless-api" : " ^3.1 .0" ,
4242 "@twilio-labs/serverless-runtime-types" : " ^1.1.7" ,
4343 "@types/express" : " ^4.17.0" ,
4444 "@types/inquirer" : " ^6.0.3" ,
Original file line number Diff line number Diff line change 99} from '../commands/shared' ;
1010import { getFullCommand } from '../commands/utils' ;
1111import { readSpecializedConfig } from './global' ;
12- import { getCredentialsFromFlags } from './utils' ;
12+ import { getCredentialsFromFlags , readLocalEnvFile , filterEnvVariablesForDeploy } from './utils' ;
1313import { mergeFlagsAndConfig } from './utils/mergeFlagsAndConfig' ;
1414
1515type ActivateConfig = ApiActivateConfig & {
@@ -61,6 +61,8 @@ export async function getConfigFromFlags(
6161 flags ,
6262 externalCliOptions
6363 ) ;
64+ const { localEnv } = await readLocalEnvFile ( flags ) ;
65+ const env = filterEnvVariablesForDeploy ( localEnv ) ;
6466
6567 const command = getFullCommand ( flags ) ;
6668 const serviceSid = checkForValidServiceSid ( command , flags . serviceSid ) ;
@@ -79,5 +81,6 @@ export async function getConfigFromFlags(
7981 sourceEnvironment : flags . sourceEnvironment ,
8082 region,
8183 edge,
84+ env
8285 } ;
8386}
Original file line number Diff line number Diff line change @@ -14,6 +14,7 @@ import {
1414 getServiceNameFromFlags ,
1515 readLocalEnvFile ,
1616 readPackageJsonContent ,
17+ filterEnvVariablesForDeploy
1718} from './utils' ;
1819import { mergeFlagsAndConfig } from './utils/mergeFlagsAndConfig' ;
1920
@@ -69,6 +70,7 @@ export async function getConfigFromFlags(
6970 externalCliOptions
7071 ) ;
7172 const { localEnv, envPath } = await readLocalEnvFile ( flags ) ;
73+ const env = filterEnvVariablesForDeploy ( localEnv ) ;
7274
7375 const serviceSid =
7476 flags . serviceSid ||
@@ -83,20 +85,6 @@ export async function getConfigFromFlags(
8385
8486 const pkgJson = await readPackageJsonContent ( flags ) ;
8587
86- const env = {
87- ...localEnv ,
88- } ;
89-
90- for ( let key of Object . keys ( env ) ) {
91- const val = env [ key ] ;
92- if ( typeof val === 'string' && val . length === 0 ) {
93- delete env [ key ] ;
94- }
95- }
96-
97- delete env . ACCOUNT_SID ;
98- delete env . AUTH_TOKEN ;
99-
10088 let serviceName : string | undefined = await getServiceNameFromFlags ( flags ) ;
10189
10290 if ( ! serviceName ) {
Original file line number Diff line number Diff line change 11import dotenv from 'dotenv' ;
22import path from 'path' ;
33import { EnvironmentVariablesWithAuth } from '../../types/generic' ;
4+ import { EnvironmentVariables } from '@twilio-labs/serverless-api' ;
45import { fileExists , readFile } from '../../utils/fs' ;
56
67export async function readLocalEnvFile ( flags : {
@@ -25,3 +26,21 @@ export async function readLocalEnvFile(flags: {
2526 }
2627 return { envPath : '' , localEnv : { } } ;
2728}
29+
30+ export function filterEnvVariablesForDeploy ( localEnv : EnvironmentVariablesWithAuth ) : EnvironmentVariables {
31+ const env = {
32+ ...localEnv ,
33+ } ;
34+
35+ for ( let key of Object . keys ( env ) ) {
36+ const val = env [ key ] ;
37+ if ( typeof val === 'string' && val . length === 0 ) {
38+ delete env [ key ] ;
39+ }
40+ }
41+
42+ delete env . ACCOUNT_SID ;
43+ delete env . AUTH_TOKEN ;
44+
45+ return env ;
46+ }
You can’t perform that action at this time.
0 commit comments