Skip to content

Commit 1a19e4a

Browse files
committed
feat: add manifest module
1 parent 06d84b1 commit 1a19e4a

File tree

1 file changed

+111
-0
lines changed

1 file changed

+111
-0
lines changed

src/firebase_functions/manifest.py

+111
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
"""Specs for the served functions.yaml of the user's functions"""
2+
3+
# We're ignoring pylint's warning about names since we want
4+
# the manifest to match the container specification.
5+
6+
# pylint: disable=invalid-name
7+
8+
from dataclasses import dataclass
9+
from typing import TypedDict, Optional, Union
10+
from typing_extensions import NotRequired, Required
11+
12+
from firebase_functions.params import Expression, Param
13+
14+
15+
class SecretEnvironmentVariable(TypedDict):
16+
key: Required[str]
17+
secret: NotRequired[str]
18+
19+
20+
class HttpsTrigger(TypedDict):
21+
"""
22+
Trigger definition for arbitrary HTTPS endpoints.
23+
"""
24+
invoker: NotRequired[list[str]]
25+
"""
26+
Which service account should be able to trigger this function. No value means "make public"
27+
on create and don't do anything on update.
28+
"""
29+
30+
31+
class CallableTrigger(TypedDict):
32+
"""
33+
Trigger definitions for RPCs servers using the HTTP protocol defined at
34+
https://firebase.google.com/docs/functions/callable-reference
35+
"""
36+
37+
38+
class EventTrigger(TypedDict):
39+
"""
40+
Trigger definitions for endpoints that listen to CloudEvents emitted by
41+
other systems (or legacy Google events for GCF gen 1)
42+
"""
43+
eventFilters: NotRequired[dict[str, Union[str, Expression[str]]]]
44+
eventFilterPathPatterns: NotRequired[dict[str, Union[str, Expression[str]]]]
45+
channel: NotRequired[str]
46+
eventType: Required[str]
47+
retry: Required[Union[bool, Expression[bool]]]
48+
region: NotRequired[str]
49+
serviceAccountEmail: NotRequired[str]
50+
51+
52+
class RetryConfig(TypedDict):
53+
retryCount: NotRequired[Union[int, Expression[int]]]
54+
maxRetrySeconds: NotRequired[Union[str, Expression[str]]]
55+
minBackoffSeconds: NotRequired[Union[str, Expression[str]]]
56+
maxBackoffSeconds: NotRequired[Union[str, Expression[str]]]
57+
maxDoublings: NotRequired[Union[int, Expression[int]]]
58+
59+
60+
class ScheduleTrigger(TypedDict):
61+
schedule: NotRequired[Union[str, Expression[str]]]
62+
timeZone: NotRequired[Union[str, Expression[str]]]
63+
retryConfig: NotRequired[RetryConfig]
64+
65+
66+
class BlockingTrigger(TypedDict):
67+
eventType: Required[str]
68+
69+
70+
class VpcSettings(TypedDict):
71+
connector: Required[Union[str, Expression[str]]]
72+
egressSettings: NotRequired[str]
73+
74+
75+
@dataclass(frozen=True)
76+
class ManifestEndpoint:
77+
"""An definition of a function as appears in the Manifest."""
78+
79+
entryPoint: Optional[str] = None
80+
region: Optional[list[str]] = None
81+
platform: Optional[str] = "gcfv2"
82+
availableMemoryMb: Union[int, Expression[int], None] = None
83+
maxInstances: Union[int, Expression[int], None] = None
84+
minInstances: Union[int, Expression[int], None] = None
85+
concurrency: Union[int, Expression[int], None] = None
86+
serviceAccountEmail: Optional[str] = None
87+
timeoutSeconds: Union[int, Expression[int], None] = None
88+
cpu: Union[int, str] = "gcf_gen1"
89+
vpc: Optional[VpcSettings] = None
90+
labels: Optional[dict[str, str]] = None
91+
ingressSettings: Optional[str] = None
92+
environmentVariables: Optional[dict[str, str]] = None
93+
secretEnvironmentVariables: Optional[list[SecretEnvironmentVariable]] = None
94+
httpsTrigger: Optional[HttpsTrigger] = None
95+
callableTrigger: Optional[CallableTrigger] = None
96+
eventTrigger: Optional[EventTrigger] = None
97+
scheduleTrigger: Optional[ScheduleTrigger] = None
98+
blockingTrigger: Optional[BlockingTrigger] = None
99+
100+
101+
class ManifestRequiredApi(TypedDict):
102+
api: Required[str]
103+
reason: Required[str]
104+
105+
106+
@dataclass(frozen=True)
107+
class ManifestStack:
108+
endpoints: dict[str, ManifestEndpoint]
109+
specVersion: str = "v1alpha1"
110+
params: Optional[list[Param]] = None
111+
requiredApis: list[ManifestRequiredApi] = []

0 commit comments

Comments
 (0)