@@ -6,6 +6,7 @@ import { assertExhaustive, partition } from "../../functional";
6
6
import * as secretManager from "../../gcp/secretManager" ;
7
7
import { listBuckets } from "../../gcp/storage" ;
8
8
import { isCelExpression , resolveExpression } from "./cel" ;
9
+ import { FirebaseConfig } from "./args" ;
9
10
10
11
// A convinience type containing options for Prompt's select
11
12
interface ListItem {
@@ -104,12 +105,21 @@ type ParamBase<T extends string | number | boolean> = {
104
105
input ?: ParamInput < T > ;
105
106
} ;
106
107
108
+ /**
109
+ * Determines whether an Input field value can be coerced to TextInput.
110
+ */
107
111
export function isTextInput < T > ( input : ParamInput < T > ) : input is TextInput < T > {
108
112
return { } . hasOwnProperty . call ( input , "text" ) ;
109
113
}
114
+ /**
115
+ * Determines whether an Input field value can be coerced to SelectInput.
116
+ */
110
117
export function isSelectInput < T > ( input : ParamInput < T > ) : input is SelectInput < T > {
111
118
return { } . hasOwnProperty . call ( input , "select" ) ;
112
119
}
120
+ /**
121
+ * Determines whether an Input field value can be coerced to ResourceInput.
122
+ */
113
123
export function isResourceInput < T > ( input : ParamInput < T > ) : input is ResourceInput {
114
124
return { } . hasOwnProperty . call ( input , "resource" ) ;
115
125
}
@@ -199,7 +209,7 @@ export class ParamValue {
199
209
200
210
constructor (
201
211
private readonly rawValue : string ,
202
- readonly secret : boolean ,
212
+ readonly internal : boolean ,
203
213
types : { string ?: boolean ; boolean ?: boolean ; number ?: boolean }
204
214
) {
205
215
this . legalString = types . string || false ;
@@ -236,8 +246,7 @@ function resolveDefaultCEL(
236
246
) : RawParamValue {
237
247
const deps = dependenciesCEL ( expr ) ;
238
248
const allDepsFound = deps . every ( ( dep ) => ! ! currentEnv [ dep ] ) ;
239
- const dependsOnSecret = deps . some ( ( dep ) => currentEnv [ dep ] . secret ) ;
240
- if ( ! allDepsFound || dependsOnSecret ) {
249
+ if ( ! allDepsFound ) {
241
250
throw new FirebaseError (
242
251
"Build specified parameter with un-resolvable default value " +
243
252
expr +
@@ -288,11 +297,11 @@ function canSatisfyParam(param: Param, value: RawParamValue): boolean {
288
297
*/
289
298
export async function resolveParams (
290
299
params : Param [ ] ,
291
- projectId : string ,
300
+ firebaseConfig : FirebaseConfig ,
292
301
userEnvs : Record < string , ParamValue > ,
293
302
nonInteractive ?: boolean
294
303
) : Promise < Record < string , ParamValue > > {
295
- const paramValues : Record < string , ParamValue > = { } ;
304
+ const paramValues : Record < string , ParamValue > = populateDefaultParams ( firebaseConfig ) ;
296
305
297
306
// TODO(vsfan@): should we ever reject param values from .env files based on the appearance of the string?
298
307
const [ resolved , outstanding ] = partition ( params , ( param ) => {
@@ -304,7 +313,7 @@ export async function resolveParams(
304
313
305
314
const [ needSecret , needPrompt ] = partition ( outstanding , ( param ) => param . type === "secret" ) ;
306
315
for ( const param of needSecret ) {
307
- await handleSecret ( param as SecretParam , projectId ) ;
316
+ await handleSecret ( param as SecretParam , firebaseConfig . projectId ) ;
308
317
}
309
318
310
319
if ( nonInteractive && needPrompt . length > 0 ) {
@@ -326,12 +335,41 @@ export async function resolveParams(
326
335
"Parameter " + param . name + " has default value " + paramDefault + " of wrong type"
327
336
) ;
328
337
}
329
- paramValues [ param . name ] = await promptParam ( param , projectId , paramDefault ) ;
338
+ paramValues [ param . name ] = await promptParam ( param , firebaseConfig . projectId , paramDefault ) ;
330
339
}
331
340
332
341
return paramValues ;
333
342
}
334
343
344
+ function populateDefaultParams ( config : FirebaseConfig ) : Record < string , ParamValue > {
345
+ const defaultParams : Record < string , ParamValue > = { } ;
346
+ if ( config . databaseURL !== "" ) {
347
+ defaultParams [ "DATABASE_URL" ] = new ParamValue ( config . databaseURL , true , {
348
+ string : true ,
349
+ boolean : false ,
350
+ number : false ,
351
+ } ) ;
352
+ }
353
+ defaultParams [ "PROJECT_ID" ] = new ParamValue ( config . projectId , true , {
354
+ string : true ,
355
+ boolean : false ,
356
+ number : false ,
357
+ } ) ;
358
+ defaultParams [ "GCLOUD_PROJECT" ] = new ParamValue ( config . projectId , true , {
359
+ string : true ,
360
+ boolean : false ,
361
+ number : false ,
362
+ } ) ;
363
+ if ( config . storageBucket !== "" ) {
364
+ defaultParams [ "STORAGE_BUCKET" ] = new ParamValue ( config . storageBucket , true , {
365
+ string : true ,
366
+ boolean : false ,
367
+ number : false ,
368
+ } ) ;
369
+ }
370
+ return defaultParams ;
371
+ }
372
+
335
373
/**
336
374
* Handles a SecretParam by checking for the presence of a corresponding secret
337
375
* in Cloud Secrets Manager. If not present, we currently ask the user to
0 commit comments