8000 Merge branch 'master' into multitenancy · firebase/firebase-admin-python@a8bd2cf · GitHub
[go: up one dir, main page]

Skip to content

Commit a8bd2cf

Browse files
authored
Merge branch 'master' into multitenancy
2 parents 2e1d9ad + 43e246d commit a8bd2cf

File tree

8 files changed

+2478
-3
lines changed

8 files changed

+2478
-3
lines changed

.github/workflows/release.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ jobs:
5454
python -m pip install --upgrade pip
5555
pip install -r requirements.txt
5656
pip install setuptools wheel
57+
pip install tensorflow
58+
pip install keras
5759
5860
- name: Run unit tests
5961
run: pytest

CONTRIBUTING.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -183,14 +183,17 @@ Then set up your Firebase/GCP project as follows:
183183
Firebase Console. Select the "Sign-in method" tab, and enable the
184184
"Email/Password" sign-in method, including the Email link (passwordless
185185
sign-in) option.
186-
187-
3. Enable the IAM API: Go to the
186+
3. Enable the Firebase ML API: Go to the
187+
[Google Developers Console](
188+
https://console.developers.google.com/apis/api/firebaseml.googleapis.com/overview)
189+
and make sure your project is selected. If the API is not already enabled, click Enable.
190+
4. Enable the IAM API: Go to the
188191
[Google Cloud Platform Console](https://console.cloud.google.com) and make
189192
sure your Firebase/GCP project is selected. Select "APIs & Services >
190193
Dashboard" from the main menu, and click the "ENABLE APIS AND SERVICES"
191194
button. Search for and enable the "Identity and Access Management (IAM)
192195
API".
193-
4. Grant your service account the 'Firebase Authentication Admin' role. This is
196+
5. Grant your service account the 'Firebase Authentication Admin' role. This is
194197
required to ensure that exported user records contain the password hashes of
195198
the user accounts:
196199
1. Go to [Google Cloud Platform Console / IAM & admin](https://console.cloud.google.com/iam-admin).

firebase_admin/_utils.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,26 @@
5959
}
6060

6161

62+
# See https://github.com/googleapis/googleapis/blob/master/google/rpc/code.proto
63+
_RPC_CODE_TO_ERROR_CODE = {
64+
1: exceptions.CANCELLED,
65+
2: exceptions.UNKNOWN,
66+
3: exceptions.INVALID_ARGUMENT,
67+
4: exceptions.DEADLINE_EXCEEDED,
68+
5: exceptions.NOT_FOUND,
69+
6: exceptions.ALREADY_EXISTS,
70+
7: exceptions.PERMISSION_DENIED,
71+
8: exceptions.RESOURCE_EXHAUSTED,
72+
9: exceptions.FAILED_PRECONDITION,
73+
10: exceptions.ABORTED,
74+
11: exceptions.OUT_OF_RANGE,
75+
13: exceptions.INTERNAL,
76+
14: exceptions.UNAVAILABLE,
77+
15: exceptions.DATA_LOSS,
78+
16: exceptions.UNAUTHENTICATED,
79+
}
80+
81+
6282
def _get_initialized_app(app):
6383
"""Returns a reference to an initialized App instance."""
6484
if app is None:
@@ -75,6 +95,7 @@ def _get_initialized_app(app):
7595
' firebase_admin.App, but given "{0}".'.format(type(app)))
7696

7797

98+
7899
def get_app_service(app, name, initializer):
79100
app = _get_initialized_app(app)
80101
return app._get_service(name, initializer) # pylint: disable=protected-access
@@ -108,6 +129,27 @@ def handle_platform_error_from_requests(error, handle_func=None):
108129
return exc if exc else _handle_func_requests(error, message, error_dict)
109130

110131

132+
def handle_operation_error(error):
133+
"""Constructs a ``FirebaseError`` from the given operation error.
134+
135+
Args:
136+
error: An error returned by a long running operation.
137+
138+
Returns:
139+
FirebaseError: A ``FirebaseError`` that can be raised to the user code.
140+
"""
141+
if not isinstance(error, dict):
142+
return exceptions.UnknownError(
143+
message='Unknown error while making a remote service call: {0}'.format(error),
144+
cause=error)
145+
146+
rpc_code = error.get('code')
147+
message = error.get('message')
148+
error_code = _rpc_code_to_error_code(rpc_code)
149+
err_type = _error_code_to_exception_type(error_code)
150+
return err_type(message=message)
151+
152+
111153
def _handle_func_requests(error, message, error_dict):
112154
"""Constructs a ``FirebaseError`` from the given GCP error.
113155
@@ -264,6 +306,9 @@ def _http_status_to_error_code(status):
264306 63DA
"""Maps an HTTP status to a platform error code."""
265307
return _HTTP_STATUS_TO_ERROR_CODE.get(status, exceptions.UNKNOWN)
266308

309+
def _rpc_code_to_error_code(rpc_code):
310+
"""Maps an RPC code to a platform error code."""
311+
return _RPC_CODE_TO_ERROR_CODE.get(rpc_code, exceptions.UNKNOWN)
267312

268313
def _error_code_to_exception_type(code):
269314
"""Maps a platform error code to an exception type."""

0 commit comments

Comments
 (0)
0