| OLD | NEW |
| 1 # Copyright 2015 The Chromium Authors. All rights reserved. | 1 # Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 """This module is used to set up Remote API to use services on App Engine. | 5 """This module is used to set up Remote API to use services on App Engine. |
| 6 | 6 |
| 7 After setup, available services include datastore, task queue, etc. | 7 After setup, available services include datastore, task queue, etc. |
| 8 You may be prompted for credentials during the remote query or the like. | 8 You may be prompted for credentials during the remote query or the like. |
| 9 And you could use Remote API only when you are one of the project members. | 9 And you could use Remote API only when you are one of the project members. |
| 10 | 10 |
| 11 For detail on usage of Remote API, please refer to: | 11 For detail on usage of Remote API, please refer to: |
| 12 https://cloud.google.com/appengine/docs/python/tools/remoteapi | 12 https://cloud.google.com/appengine/docs/python/tools/remoteapi |
| 13 """ | 13 """ |
| 14 | 14 |
| 15 import socket | 15 import socket |
| 16 | 16 |
| 17 import script_util | 17 import script_util # pylint: disable=W |
| 18 script_util.SetUpSystemPaths() | 18 script_util.SetUpSystemPaths() |
| 19 | 19 |
| 20 from google.appengine.api import urlfetch | 20 from google.appengine.api import urlfetch |
| 21 from google.appengine.ext import ndb | 21 from google.appengine.ext import ndb |
| 22 from google.appengine.ext.remote_api import remote_api_stub | 22 from google.appengine.ext.remote_api import remote_api_stub |
| 23 | 23 |
| 24 | 24 |
| 25 def SetTimeoutForUrlOperations(url_blocking_operations_timeout=600): | 25 # TODO(crbug.com/662540): Add unittests. |
| 26 def SetTimeoutForUrlOperations( |
| 27 url_blocking_operations_timeout=600): # pragma: no cover |
| 26 """Set timeout for url operations (socket, appengine db).""" | 28 """Set timeout for url operations (socket, appengine db).""" |
| 27 socket.setdefaulttimeout(url_blocking_operations_timeout) | 29 socket.setdefaulttimeout(url_blocking_operations_timeout) |
| 28 urlfetch.set_default_fetch_deadline(url_blocking_operations_timeout) | 30 urlfetch.set_default_fetch_deadline(url_blocking_operations_timeout) |
| 29 | 31 |
| 30 | 32 |
| 31 def EnableRemoteApi(app_id='findit-for-me'): | 33 # TODO(crbug.com/662540): Add unittests. |
| 34 def EnableRemoteApi(app_id='findit-for-me'): # pragma: no cover |
| 32 """Enable appengine services through remote API. | 35 """Enable appengine services through remote API. |
| 33 | 36 |
| 34 Args: | 37 Args: |
| 35 app_id (str): The appengine ID without '.appspot.com', eg. findit-for-me. | 38 app_id (str): The appengine ID without '.appspot.com', eg. findit-for-me. |
| 36 """ | 39 """ |
| 37 if hasattr(EnableRemoteApi, app_id): | 40 if hasattr(EnableRemoteApi, app_id): |
| 38 return | 41 return |
| 39 | 42 |
| 40 SetTimeoutForUrlOperations() | 43 SetTimeoutForUrlOperations() |
| 41 | 44 |
| 42 remote_api_stub.ConfigureRemoteApiForOAuth( | 45 remote_api_stub.ConfigureRemoteApiForOAuth( |
| 43 '%s.appspot.com' % app_id, | 46 '%s.appspot.com' % app_id, |
| 44 '/_ah/remote_api', | 47 '/_ah/remote_api', |
| 45 secure=True, | 48 secure=True, |
| 46 save_cookies=True) | 49 save_cookies=True) |
| 47 setattr(EnableRemoteApi, app_id, True) | 50 setattr(EnableRemoteApi, app_id, True) |
| OLD | NEW |