26
26
import firebase_functions .private .path_pattern as _path_pattern
27
27
from firebase_functions .params import SecretParam , Expression
28
28
29
- USE_DEFAULT = _util .Sentinel (
30
- "Value used to reset an option to factory defaults " )
31
- """Used to reset an option to its factory default."""
29
+ RESET_VALUE = _util .Sentinel (
30
+ "Special configuration value to reset configuration to platform default. " )
31
+ """Special configuration value to reset configuration to platform default."""
32
32
33
33
34
34
class VpcEgressSetting (str , _enum .Enum ):
@@ -115,14 +115,14 @@ class RuntimeOptions:
115
115
memory : int | MemoryOption | Expression [int ] | _util .Sentinel | None = None
116
116
"""
117
117
Amount of memory to allocate to a function.
118
- A value of USE_DEFAULT restores the defaults of 256MB.
118
+ A value of RESET_VALUE restores the defaults of 256MB.
119
119
"""
120
120
121
121
timeout_sec : int | Expression [int ] | _util .Sentinel | None = None
122
122
"""
123
123
Timeout for the function in sections, possible values are 0 to 540.
124
124
HTTPS functions can specify a higher timeout.
125
- A value of USE_DEFAULT restores the default of 60s
125
+ A value of RESET_VALUE restores the default of 60s
126
126
The minimum timeout for a gen 2 function is 1s. The maximum timeout for a
127
127
function depends on the type of function: Event handling functions have a
128
128
maximum timeout of 540s (9 minutes). HTTPS and callable functions have a
@@ -135,20 +135,20 @@ class RuntimeOptions:
135
135
Min number of actual instances to be running at a given time.
136
136
Instances will be billed for memory allocation and 10% of CPU allocation
137
137
while idle.
138
- A value of USE_DEFAULT restores the default min instances.
138
+ A value of RESET_VALUE restores the default min instances.
139
139
"""
140
140
141
141
max_instances : int | Expression [int ] | _util .Sentinel | None = None
142
142
"""
143
143
Max number of instances to be running in parallel.
144
- A value of USE_DEFAULT restores the default max instances.
144
+ A value of RESET_VALUE restores the default max instances.
145
145
"""
146
146
147
147
concurrency : int | Expression [int ] | _util .Sentinel | None = None
148
148
"""
149
149
Number of requests a function can serve at once.
150
150
Can only be applied to functions running on Cloud Functions v2.
151
- A value of USE_DEFAULT restores the default concurrency (80 when CPU >= 1, 1 otherwise).
151
+ A value of RESET_VALUE restores the default concurrency (80 when CPU >= 1, 1 otherwise).
152
152
Concurrency cannot be set to any value other than 1 if `cpu` is less than 1.
153
153
The maximum value for concurrency is 1,000.
154
154
"""
@@ -163,28 +163,28 @@ class RuntimeOptions:
163
163
to the value "gcf_gen1"
164
164
"""
165
165
166
- vpc_connector : str | None = None
166
+ vpc_connector : str | _util . Sentinel | None = None
167
167
"""
168
168
Connect cloud function to specified VPC connector.
169
- A value of USE_DEFAULT removes the VPC connector.
169
+ A value of RESET_VALUE removes the VPC connector.
170
170
"""
171
171
172
- vpc_connector_egress_settings : VpcEgressSetting | None = None
172
+ vpc_connector_egress_settings : VpcEgressSetting | _util . Sentinel | None = None
173
173
"""
174
174
Egress settings for VPC connector.
175
- A value of USE_DEFAULT turns off VPC connector egress settings.
175
+ A value of RESET_VALUE turns off VPC connector egress settings.
176
176
"""
177
177
178
178
service_account : str | _util .Sentinel | None = None
179
179
"""
180
180
Specific service account for the function to run as.
181
- A value of USE_DEFAULT restores the default service account.
181
+ A value of RESET_VALUE restores the default service account.
182
182
"""
183
183
184
184
ingress : IngressSetting | _util .Sentinel | None = None
185
185
"""
186
186
Ingress settings which control where this function can be called from.
187
- A value of USE_DEFAULT turns off ingress settings.
187
+ A value of RESET_VALUE turns off ingress settings.
188
188
"""
189
189
190
190
labels : dict [str , str ] | None = None
@@ -205,6 +205,18 @@ class RuntimeOptions:
205
205
When false, requests with invalid tokens set event.app to None.
206
206
"""
207
207
208
+ preserve_external_changes : bool | None = None
209
+ """
210
+ Controls whether function configuration modified outside of function source is preserved.
211
+ Internally defaults to false.
212
+
213
+ When setting configuration available in the underlying platform that is not yet available
214
+ in the Firebase Functions SDK, we highly recommend setting `preserve_external_changes` to
215
+ `True`. Otherwise, when the Firebase Functions SDK releases a new version of the SDK
216
+ with support for the missing configuration, your function's manually configured setting
217
+ may inadvertently be wiped out.
218
+ """
219
+
208
220
def _asdict_with_global_options (self ) -> dict :
209
221
"""
210
222
Returns the provider options merged with globally defined options.
@@ -222,7 +234,25 @@ def _asdict_with_global_options(self) -> dict:
222
234
merged_options ["labels" ] = {** _GLOBAL_OPTIONS .labels , ** self .labels }
223
235
if "labels" not in merged_options :
224
236
merged_options ["labels" ] = {}
225
-
237
+ preserve_external_changes : bool = merged_options .get (
238
+ "preserve_external_changes" ,
239
+ False ,
240
+ )
241
+ resettable_options = [
242
+ "memory" ,
243
+ "timeout_sec" ,
244
+ "min_instances" ,
245
+ "max_instances" ,
246
+ "ingress" ,
247
+ "concurrency" ,
248
+ "service_account" ,
249
+ "vpc_connector" ,
250
+ "vpc_connector_egress_settings" ,
251
+ ]
252
+ if not preserve_external_changes :
253
+ for option in resettable_options :
254
+ if option not in merged_options :
255
+ merged_options [option ] = RESET_VALUE
226
256
# _util.Sentinel values are converted to `None` in ManifestEndpoint generation
227
257
# after other None values are removed - so as to keep them in the generated
228
258
# YAML output as 'null' values.
@@ -257,10 +287,14 @@ def convert_secret(
257
287
region = [_typing .cast (str , options .region )]
258
288
259
289
vpc : _manifest .VpcSettings | None = None
260
- if options .vpc_connector is not None :
290
+ if isinstance ( options .vpc_connector , str ) :
261
291
vpc = ({
262
- "connector" : options .vpc_connector ,
263
- "egressSettings" : options .vpc_connector_egress_settings .value
292
+ "connector" :
293
+ options .vpc_connector ,
294
+ "egressSettings" :
295
+ options .vpc_connector_egress_settings .value if isinstance (
296
+ options .vpc_connector_egress_settings , VpcEgressSetting )
297
+ else options .vpc_connector_egress_settings
264
298
} if options .vpc_connector_egress_settings is not None else {
265
299
"connector" : options .vpc_connector
266
300
})
@@ -511,6 +545,7 @@ def set_global_options(
511
545
labels : dict [str , str ] | None = None ,
512
546
secrets : list [str ] | list [SecretParam ] | _util .Sentinel | None = None ,
513
547
enforce_app_check : bool | None = None ,
548
+ preserve_external_changes : bool | None = None ,
514
549
):
515
550
"""
516
551
Sets default options for all functions.
@@ -531,4 +566,5 @@ def set_global_options(
531
566
labels = labels ,
532
567
secrets = secrets ,
533
568
enforce_app_check = enforce_app_check ,
569
+ preserve_external_changes = preserve_external_changes ,
534
570
)
0 commit comments