Skip to content

Commit 8307c37

Browse files
authored
Merge pull request firebase#2 from carsongee/feature/setup_deps
Feature/setup deps
2 parents 347e8d0 + d8b5c6c commit 8307c37

File tree

17 files changed

+1029
-22
lines changed

17 files changed

+1029
-22
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,5 @@ dist/
99
*~
1010
scripts/cert.json
1111
scripts/apikey.txt
12+
htmlcov/
13+
.pytest_cache/

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Unreleased
22

3-
-
3+
- [changed] Improved error handling in FCM by mapping more server-side
4+
errors to client-side error codes.
45

56
# v2.9.0
67

firebase_admin/__about__.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Copyright 2017 Google Inc.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
"""About information (version, etc) for Firebase Admin SDK."""
16+
17+
__version__ = '2.9.0'
18+
__title__ = 'firebase_admin'
19+
__author__ = 'Firebase'
20+
__license__ = 'Apache License 2.0'
21+
__url__ = 'https://firebase.google.com/docs/admin/setup/'

firebase_admin/__init__.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,9 @@
2121
import six
2222

2323
from firebase_admin import credentials
24+
from firebase_admin.__about__ import __version__
2425

2526

26-
# Declaring module version as per https://www.python.org/dev/peps/pep-0396/#specification
27-
# Update this accordingly for each release.
28-
__version__ = '2.9.0'
29-
3027
_apps = {}
3128
_apps_lock = threading.RLock()
3229
_clock = datetime.datetime.utcnow

firebase_admin/messaging.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -716,11 +716,18 @@ class _MessagingService(object):
716716
INTERNAL_ERROR = 'internal-error'
717717
UNKNOWN_ERROR = 'unknown-error'
718718
FCM_ERROR_CODES = {
719-
'APNS_AUTH_ERROR': 'authentication-error',
719+
# FCM v1 canonical error codes
720+
'NOT_FOUND': 'registration-token-not-registered',
721+
'PERMISSION_DENIED': 'mismatched-credential',
722+
'RESOURCE_EXHAUSTED': 'message-rate-exceeded',
723+
'UNAUTHENTICATED': 'invalid-apns-credentials',
724+
725+
# FCM v1 new error codes
726+
'APNS_AUTH_ERROR': 'invalid-apns-credentials',
720727
'INTERNAL': INTERNAL_ERROR,
721728
'INVALID_ARGUMENT': 'invalid-argument',
722729
'QUOTA_EXCEEDED': 'message-rate-exceeded',
723-
'SENDER_ID_MISMATCH': 'authentication-error',
730+
'SENDER_ID_MISMATCH': 'mismatched-credential',
724731
'UNAVAILABLE': 'server-unavailable',
725732
'UNREGISTERED': 'registration-token-not-registered',
726733
}

lint.sh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,11 @@ set -o errexit
3232
set -o nounset
3333

3434
SKIP_FOR_TESTS="redefined-outer-name,protected-access,missing-docstring,too-many-lines"
35+
SKIP_FOR_SNIPPETS="${SKIP_FOR_TESTS},reimported,unused-variable"
3536

3637
if [[ "$#" -eq 1 && "$1" = "all" ]]
3738
then
38-
CHECK_ALL=true
39+
CHECK_ALL=true
3940
elif [[ "$#" -eq 0 ]]
4041
then
4142
CHECK_ALL=false
@@ -49,8 +50,10 @@ then
4950
lintAllFiles "firebase_admin" ""
5051
lintAllFiles "tests" "$SKIP_FOR_TESTS"
5152
lintAllFiles "integration" "$SKIP_FOR_TESTS"
53+
lintAllFiles "snippets" "$SKIP_FOR_SNIPPETS"
5254
else
5355
lintChangedFiles "firebase_admin" ""
5456
lintChangedFiles "tests" "$SKIP_FOR_TESTS"
5557
lintChangedFiles "integration" "$SKIP_FOR_TESTS"
58+
lintChangedFiles "snippets" "$SKIP_FOR_SNIPPETS"
5659
fi

scripts/prepare_release.sh

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,9 @@ if ! parseVersion "$VERSION"; then
5555
exit 1
5656
fi
5757

58-
CUR_VERSION=$(grep "^__version__ =" ../firebase_admin/__init__.py | awk '{print $3}' | sed "s/'//g")
58+
CUR_VERSION=$(grep "^__version__ =" ../firebase_admin/__about__.py | awk '{print $3}' | sed "s/'//g")
5959
if [ -z "$CUR_VERSION" ]; then
60-
echo "[ERROR] Failed to find the current version. Check firebase_admin/__init__.py for version declaration."
60+
echo "[ERROR] Failed to find the current version. Check firebase_admin/__version__.py for version declaration."
6161
exit 1
6262
fi
6363
if ! parseVersion "$CUR_VERSION"; then
@@ -119,12 +119,12 @@ fi
119119
##################################
120120

121121
HOST=$(uname)
122-
echo "[INFO] Updating __init__.py and CHANGELOG.md"
122+
echo "[INFO] Updating __about__.py and CHANGELOG.md"
123123
if [ $HOST == "Darwin" ]; then
124-
sed -i "" -e "s/__version__ = '$CUR_VERSION'/__version__ = '$VERSION'/" "../firebase_admin/__init__.py"
124+
sed -i "" -e "s/__version__ = '$CUR_VERSION'/__version__ = '$VERSION'/" "../firebase_admin/__about__.py"
125125
sed -i "" -e "1 s/# Unreleased//" "../CHANGELOG.md"
126126
else
127-
sed -i -e "s/__version__ = '$CUR_VERSION'/__version__ = '$VERSION'/" "../firebase_admin/__init__.py"
127+
sed -i -e "s/__version__ = '$CUR_VERSION'/__version__ = '$VERSION'/" "../firebase_admin/__about__.py"
128128
sed -i -e "1 s/# Unreleased//" "../CHANGELOG.md"
129129
fi
130130

setup.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,18 @@
2121
from setuptools import find_packages
2222
from setuptools import setup
2323

24-
import firebase_admin
25-
2624

2725
if sys.version_info < (2, 7):
2826
print('firebase_admin requires python2 version >= 2.7 or python3.', file=sys.stderr)
2927
sys.exit(1)
3028

29+
# Read in the package meta data per recommendations from:
30+
# https://packaging.python.org/guides/single-sourcing-package-version/
31+
about_path = path.join(path.dirname(path.abspath(__file__)), 'firebase_admin', '__about__.py')
32+
about = {}
33+
with open(about_path) as fp:
34+
exec(fp.read(), about) # pylint: disable=exec-used
35+
3136

3237
long_description = ('The Firebase Admin Python SDK enables server-side (backend) Python developers '
3338
'to integrate Firebase into their services and applications.')
@@ -43,16 +48,14 @@
4348
':python_version<"3.4"': ('enum34>=1.0.4',),
4449
}
4550

46-
version = firebase_admin.__version__
47-
4851
setup(
49-
name='firebase_admin',
50-
version=version,
52+
name=about['__title__'],
53+
version=about['__version__'],
5154
description='Firebase Admin Python SDK',
5255
long_description=long_description,
53-
url='https://firebase.google.com/docs/admin/setup/',
54-
author='Firebase',
55-
license='Apache License 2.0',
56+
url=about['__url__'],
57+
author=about['__author__'],
58+
license=about['__license__'],
5659
keywords='firebase cloud development',
5760
extras_require=extras_require,
5861
install_requires=install_requires,

snippets/__init__.py

Whitespace-only changes.

snippets/auth/__init__.py

Whitespace-only changes.
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Copyright 2017 Google Inc. All Rights Reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
# [START get_service_account_tokens]
16+
from firebase_admin import credentials
17+
18+
cred = credentials.Certificate('path/to/serviceAccountKey.json')
19+
access_token_info = cred.get_access_token()
20+
21+
access_token = access_token_info.access_token
22+
expiration_time = access_token_info.expiry
23+
# Attach access_token to HTTPS request in the "Authorization: Bearer" header
24+
# After expiration_time, you must generate a new access token
25+
# [END get_service_account_tokens]
26+
27+
print 'The access token {} expires at {}'.format(access_token, expiration_time)

0 commit comments

Comments
 (0)