@@ -37,7 +37,8 @@ const FIRESTORE_ADDRESS_ENV: string = 'FIRESTORE_EMULATOR_HOST';
37
37
const FIRESTORE_ADDRESS_DEFAULT : string = 'localhost:8080' ;
38
38
39
39
/** If this environment variable is set, use it for the Storage emulator. */
40
- const STORAGE_ADDRESS_ENV : string = 'STORAGE_EMULATOR_HOST' ;
40
+ const FIREBASE_STORAGE_ADDRESS_ENV : string = 'FIREBASE_STORAGE_EMULATOR_HOST' ;
41
+ const CLOUD_STORAGE_ADDRESS_ENV : string = 'STORAGE_EMULATOR_HOST' ;
41
42
/** The default address for the local Firestore emulator. */
42
43
const STORAGE_ADDRESS_DEFAULT : string = 'localhost:9199' ;
43
44
@@ -378,12 +379,15 @@ function getFirestoreHost() {
378
379
379
380
function getStorageHost ( ) {
380
381
if ( ! _storageHost ) {
381
- const fromEnv = process . env [ STORAGE_ADDRESS_ENV ] ;
382
+ const fromEnv = process . env [ FIREBASE_STORAGE_ADDRESS_ENV ] || process . env [ CLOUD_STORAGE_ADDRESS_ENV ] ;
382
383
if ( fromEnv ) {
383
- _storageHost = fromEnv ;
384
+ // The STORAGE_EMULATOR_HOST env var is an older Cloud Standard which includes http:// while
385
+ // the FIREBASE_STORAGE_EMULATOR_HOST is a newer variable supported beginning in the Admin
386
+ // SDK v9.7.0 which does not have the protocol.
387
+ _storageHost = fromEnv . replace ( "http://" , "" ) ;
384
388
} else {
385
389
console . warn (
386
- `Warning: ${ STORAGE_ADDRESS_ENV } not set, using default value ${ STORAGE_ADDRESS_DEFAULT } `
390
+ `Warning: ${ FIREBASE_STORAGE_ADDRESS_ENV } not set, using default value ${ STORAGE_ADDRESS_DEFAULT } `
387
391
) ;
388
392
_storageHost = STORAGE_ADDRESS_DEFAULT ;
389
393
}
@@ -564,29 +568,21 @@ export async function loadFirestoreRules(
564
568
}
565
569
566
570
export type LoadStorageRulesOptions = {
567
- storageBucket : string ;
568
571
rules : string ;
569
572
} ;
570
573
export async function loadStorageRules (
571
574
options : LoadStorageRulesOptions
572
575
) : Promise < void > {
573
- if ( ! options . storageBucket ) {
574
- throw new Error ( 'storageBucket not specified' ) ;
575
- }
576
-
577
576
if ( ! options . rules ) {
578
577
throw new Error ( 'must provide rules to loadStorageRules' ) ;
579
578
}
580
579
581
- // TODO: This endpoint is not yet implemented! Will need a change in firebase-tools
582
- // to make this real.
583
580
const resp = await requestPromise ( request . put , {
584
581
method : 'PUT' ,
585
582
uri : `http://${ getStorageHost ( ) } /internal/setRules` ,
586
583
body : JSON . stringify ( {
587
- storageBucket : options . storageBucket ,
588
584
rules : {
589
- files : [ { content : options . rules } ]
585
+ files : [ { name : 'storage.rules' , content : options . rules } ]
590
586
}
591
587
} )
592
588
} ) ;
0 commit comments