@@ -3,13 +3,13 @@ import * as poller from "../operation-poller";
3
3
import * as gcfV1 from "../gcp/cloudfunctions" ;
4
4
import * as gcfV2 from "../gcp/cloudfunctionsv2" ;
5
5
import * as backend from "../deploy/functions/backend" ;
6
- import * as ensureApiEnabled from "../ensureApiEnabled" ;
7
- import { functionsOrigin , functionsV2Origin , secretManagerOrigin } from "../api" ;
6
+ import { functionsOrigin , functionsV2Origin } from "../api" ;
8
7
import {
9
8
createSecret ,
10
9
destroySecretVersion ,
11
10
getSecret ,
12
11
getSecretVersion ,
12
+ isAppHostingManaged ,
13
13
listSecrets ,
14
14
listSecretVersions ,
15
15
parseSecretResourceName ,
@@ -24,9 +24,8 @@ import { promptOnce } from "../prompt";
24
24
import { validateKey } from "./env" ;
25
25
import { logger } from "../logger" ;
26
26
import { assertExhaustive } from "../functional" ;
27
- import { needProjectId } from "../projectUtils" ;
28
-
29
- const FIREBASE_MANAGED = "firebase-managed" ;
27
+ import { isFunctionsManaged , FIREBASE_MANAGED } from "../gcp/secretManager" ;
28
+ import { labels } from "../gcp/secretManager" ;
30
29
31
30
// For mysterious reasons, importing the poller option in fabricator.ts leads to some
32
31
// value of the poller option to be undefined at runtime. I can't figure out what's going on,
@@ -51,36 +50,13 @@ type ProjectInfo = {
51
50
projectNumber : string ;
52
51
} ;
53
52
54
- /**
55
- * Returns true if secret is managed by Firebase.
56
- */
57
- export function isFirebaseManaged ( secret : Secret ) : boolean {
58
- return Object . keys ( secret . labels || [ ] ) . includes ( FIREBASE_MANAGED ) ;
59
- }
60
-
61
- /**
62
- * Return labels to mark secret as managed by Firebase.
63
- * @internal
64
- */
65
- export function labels ( ) : Record < string , string > {
66
- return { [ FIREBASE_MANAGED ] : "true" } ;
67
- }
68
-
69
53
function toUpperSnakeCase ( key : string ) : string {
70
54
return key
71
55
. replace ( / [ . - ] / g, "_" )
72
56
. replace ( / ( [ a - z ] ) ( [ A - Z ] ) / g, "$1_$2" )
73
57
. toUpperCase ( ) ;
74
58
}
75
59
76
- /**
77
- * Utility used in the "before" command annotation to enable the API.
78
- */
79
- export function ensureApi ( options : any ) : Promise < void > {
80
- const projectId = needProjectId ( options ) ;
81
- return ensureApiEnabled . ensure ( projectId , secretManagerOrigin ( ) , "secretmanager" , true ) ;
82
- }
83
-
84
60
/**
85
61
* Validate and transform keys to match the convention recommended by Firebase.
86
62
*/
@@ -122,18 +98,39 @@ export async function ensureSecret(
122
98
) : Promise < Secret > {
123
99
try {
124
100
const secret = await getSecret ( projectId , name ) ;
125
- if ( ! isFirebaseManaged ( secret ) ) {
101
+ if ( isAppHostingManaged ( secret ) ) {
102
+ logWarning (
103
+ "Your secret is managed by Firebase App Hosting. Continuing will disable automatic deletion of old versions." ,
104
+ ) ;
105
+ const stopTracking = await promptOnce (
106
+ {
107
+ name : "doNotTrack" ,
108
+ type : "confirm" ,
109
+ default : false ,
110
+ message : "Do you wish to continue?" ,
111
+ } ,
112
+ options ,
113
+ ) ;
114
+ if ( stopTracking ) {
115
+ delete secret . labels [ FIREBASE_MANAGED ] ;
116
+ await patchSecret ( secret . projectId , secret . name , secret . labels ) ;
117
+ } else {
118
+ throw new Error (
119
+ "A secret cannot be managed by both Firebase App Hosting and Cloud Functions for Firebase" ,
120
+ ) ;
121
+ }
122
+ } else if ( ! isFunctionsManaged ( secret ) ) {
126
123
if ( ! options . force ) {
127
124
logWarning (
128
- "Your secret is not managed by Firebase. " +
125
+ "Your secret is not managed by Cloud Functions for Firebase. " +
129
126
"Firebase managed secrets are automatically pruned to reduce your monthly cost for using Secret Manager. " ,
130
127
) ;
131
128
const confirm = await promptOnce (
132
129
{
133
130
name : "updateLabels" ,
134
131
type : "confirm" ,
135
132
default : true ,
136
- message : `Would you like to have your secret ${ secret . name } managed by Firebase?` ,
133
+ message : `Would you like to have your secret ${ secret . name } managed by Cloud Functions for Firebase?` ,
137
134
} ,
138
135
options ,
139
136
) ;
0 commit comments