Skip to content
This repository has been archived by the owner on Jan 12, 2022. It is now read-only.

Commit

Permalink
Merge pull request #15 from andrewsg/login-routes
Browse files Browse the repository at this point in the history
block login and admin-required routes temporarily and update README
  • Loading branch information
andrewsg committed Jun 17, 2015
2 parents 510405f + cec7986 commit 7460fda
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 9 deletions.
31 changes: 24 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
Google Managed VMs Python Runtime
=================================

Warning
=======

-------
The instructions here are for a multi-process version of the Python 2.7 runtime
**currently in alpha**. Please do not use this version for production workloads.
To use the stable version of the runtime, follow the documentation at
https://cloud.google.com/appengine/docs/managed-vms/ instead.

Contents
========

--------
* Using the multi-process runtime
* Configuration
* Building your own version
* Caveats

Using the multi-process runtime
===============================
-------------------------------
*These instructions assume you have a working Python application that has
already been deployed successfully to Managed VMs using the default runtime
version.*
Expand Down Expand Up @@ -45,7 +45,7 @@ section.
prebuilt Docker image with no manual Dockerfile modification required.*

Configuration
=============
-------------
By default the multi-process version of the runtime is launched via the Gunicorn
webserver and is configured to use a fixed number of processes and gevent-based
concurrency.
Expand All @@ -62,7 +62,7 @@ the number of processes in the Dockerfile to between 1 and 2 times the number of
CPU cores available.

Building your own version
=========================
-------------------------
If you would like to make modifications to the runtime (either for personal use
or to debug or resolve an outstanding issue), you can build and deploy a custom
version with the following steps:
Expand All @@ -77,3 +77,20 @@ directory as the Dockerfile.
- Replace the URL in that line with the filename of your generated tar.gz file.
- Deploy your application. A warning during deployment where your tar.gz file is
rejected for addition because it is too large can be ignored.

Caveats
-------
As this is an alpha product, some functionality has not yet been implemented.

- Logging is via stderr only. The default logging view in Google Developers
Console is "Request". Click on the dropdown showing "Request" and select
"stderr" to view the logs. stderr-only logging is temporary and will change
in a future version.
- Log entries are not automatically associated with a specific request.
- Handlers that are flagged as `login: required` or `login: admin` are not
supported. Attemping to access these handlers will result in a 404 as the
handlers will not be registered.

There may be other features that work on the current Python runtime and are not
implemented or not functional in this version. Please open an issue on Github
for any you encounter.
7 changes: 6 additions & 1 deletion multicore_runtime/wsgi_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

from static_files import static_app_for_regex_and_files

from google.appengine.api import appinfo
from google.appengine.api import appinfo_includes
from google.appengine.runtime import wsgi

Expand Down Expand Up @@ -139,11 +140,15 @@ def load_user_scripts_into_handlers(handlers):
- script: The script to serve for this handler, as a string.
- app: The fully loaded app corresponding to the script.
"""
# `if x.login == appinfo.LOGIN_OPTIONAL` disables loading handlers
# that require login or admin status entirely. This is a temporary
# measure until handling of login-required handlers is implemented
# securely.
loaded_handlers = [
(x.url if x.script or x.static_files else static_dir_url(x),
x.script.replace('$PYTHON_LIB/', '') if x.script else x.script,
app_for_script(x.script) if x.script else static_app_for_handler(x))
for x in handlers]
for x in handlers if x.login == appinfo.LOGIN_OPTIONAL]
logging.info('Parsed handlers: %s',
[(url, script) for (url, script, _) in loaded_handlers])
return loaded_handlers
Expand Down
14 changes: 14 additions & 0 deletions multicore_runtime/wsgi_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@
appinfo.URLMap(url='/env', script='wsgi_test.dump_os_environ'),
appinfo.URLMap(url='/setenv', script='wsgi_test.add_to_os_environ'),
appinfo.URLMap(url='/wait', script='wsgi_test.wait_on_global_event'),
appinfo.URLMap(url='/login', script='wsgi_test.hello_world',
login=appinfo.LOGIN_REQUIRED),
appinfo.URLMap(url='/admin', script='wsgi_test.hello_world',
login=appinfo.LOGIN_ADMIN),
appinfo.URLMap(url='/favicon.ico', static_files='test_statics/favicon.ico'),
appinfo.URLMap(url='/faketype.ico', static_files='test_statics/favicon.ico',
mime_type='application/fake_type'),
Expand Down Expand Up @@ -138,6 +142,16 @@ def test_basic_env(self):
# Assumes PATH will be present in the env in all cases, including tests!
self.assertIn('PATH', json.loads(response.data))

def test_login_required(self):
# Login routes are temporarily disabled.
response = self.client.get('/login')
self.assertEqual(response.status_code, 404)

def test_login_admin(self):
# Login routes are temporarily disabled.
response = self.client.get('/admin')
self.assertEqual(response.status_code, 404)

def test_static_file(self):
response = self.client.get('/favicon.ico')
self.assertEqual(response.status_code, 200)
Expand Down
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@
package_dir={'': 'python_vm_runtime',
'google.appengine.vmruntime': 'multicore_runtime',},
include_package_data=True,
packages=find_packages('python_vm_runtime') + ['google.appengine.vmruntime'], # pylint: disable=line-too-long
packages=find_packages('python_vm_runtime',
exclude=['lib.*'])+['google.appengine.vmruntime'],
# namespace_packages=['google'], # This skips google/__init__.py
install_requires=['requests>=2.5.0',
'webapp2>=2.5.2',
Expand Down

0 comments on commit 7460fda

Please sign in to comment.