|
15 | 15 | """Firebase credentials module.""" |
16 | 16 | import collections |
17 | 17 | import json |
| 18 | +import pathlib |
18 | 19 |
|
19 | 20 | import google.auth |
20 | 21 | from google.auth.transport import requests |
@@ -78,7 +79,7 @@ def __init__(self, cert): |
78 | 79 | ValueError: If the specified certificate is invalid. |
79 | 80 | """ |
80 | 81 | super(Certificate, self).__init__() |
81 | | - if isinstance(cert, str): |
| 82 | + if _is_file_path(cert): |
82 | 83 | with open(cert) as json_file: |
83 | 84 | json_data = json.load(json_file) |
84 | 85 | elif isinstance(cert, dict): |
@@ -179,7 +180,7 @@ def __init__(self, refresh_token): |
179 | 180 | ValueError: If the refresh token configuration is invalid. |
180 | 181 | """ |
181 | 182 | super(RefreshToken, self).__init__() |
182 | | - if isinstance(refresh_token, str): |
| 183 | + if _is_file_path(refresh_token): |
183 | 184 | with open(refresh_token) as json_file: |
184 | 185 | json_data = json.load(json_file) |
185 | 186 | elif isinstance(refresh_token, dict): |
@@ -212,3 +213,11 @@ def get_credential(self): |
212 | 213 | Returns: |
213 | 214 | google.auth.credentials.Credentials: A Google Auth credential instance.""" |
214 | 215 | return self._g_credential |
| 216 | + |
| 217 | + |
| 218 | +def _is_file_path(path): |
| 219 | + try: |
| 220 | + pathlib.Path(path) |
| 221 | + return True |
| 222 | + except TypeError: |
| 223 | + return False |
0 commit comments