def set_options(**kwargs): '''Sets configuration options for appstats. See /usr/local/google_appengine/ext/appstats/recording.py for possible keys. Example: tornado_tracing.config.set_options(RECORD_FRACTION=0.1, KEY_PREFIX='__appstats_myapp__') ''' lib_config.register('appstats', kwargs)
def get_config(cls, **kwargs): """ Registers and returns the `google.appengine.api.lib_config`_ ``ConfigHandle`` for the class. Keyword arguments will override default values defined in the :py:class:`~agar.config.Config` subclass (but, of course, will still defer to values in the ``appengine_config.py`` file). :param kwargs: Defaults to use for the config instance. Values in ``appengine_config.py`` will still override any values you specify. :return: The `google.appengine.api.lib_config`_ ``ConfigHandle`` for the class. """ return lib_config.register(cls._prefix, cls(**kwargs).defaults)
def get_config(cls, _cache=False, **kwargs): """ Registers and returns the `google.appengine.api.lib_config`_ ``ConfigHandle`` for the class. Keyword arguments will override default values defined in the :py:class:`~agar.config.Config` subclass (but, of course, will still defer to values in the ``appengine_config.py`` file). The ``ConfigHandle`` is cached on the class level after the first call to this method. :param _cache: If ``True``, get from and (if necessary) set the class-level cached config. Note that if you are passing in ``kwargs`` and the config comes out of the cache, your override values may not be applied (Default: ``False``). :param kwargs: Defaults to use for the config instance. Values in ``appengine_config.py`` will still override any values you specify. :return: The `google.appengine.api.lib_config`_ ``ConfigHandle`` for the class. """ if _cache: with cls._config_lock: if not cls._config: cls._config = lib_config.register(cls._prefix, cls(**kwargs).defaults) else: return lib_config.register(cls._prefix, cls(**kwargs).defaults) return cls._config
# and `*wildcard` values # * `dest` is the destination url, which can accept $param values REDIRECTS = tuple() # Whether to require authentication, even on Env.PROD. REQUIRE_AUTH = False # Whether to enforce https for all Env.PROD requests. REQUIRE_HTTPS = False # HTTP response headers to append to certain requests. Right now, only # supports headers for HTML files. RESPONSE_HEADERS = { 'html': { 'X-Frame-Options': 'deny', }, } config = lib_config.register('fileset', ConfigDefaults.__dict__) AUTHORIZED_ORGS = config.AUTHORIZED_ORGS AUTHORIZED_USERS = config.AUTHORIZED_USERS CANONICAL_DOMAIN = config.CANONICAL_DOMAIN DEFAULT_BRANCH = config.DEFAULT_BRANCH INTL_PATH_FORMAT = config.INTL_PATH_FORMAT REDIRECTS = config.REDIRECTS REQUIRE_AUTH = config.REQUIRE_AUTH REQUIRE_HTTPS = config.REQUIRE_HTTPS RESPONSE_HEADERS = config.RESPONSE_HEADERS
if os.getenv(django.conf.ENVIRONMENT_VARIABLE): logging.warning(e) try: django.conf.settings.configure( DEBUG=False, TEMPLATE_DEBUG=False, TEMPLATE_LOADERS=( 'django.template.loaders.filesystem.load_template_source', ), ) except (EnvironmentError, RuntimeError): pass _config_handle = lib_config.register( 'webapp', {'django_setup': _django_setup, 'django_version': None, 'add_wsgi_middleware': lambda app: app, })
* Fin. """ import threading from google.appengine.api import lib_config # Used in ensure_configured. _config_lock = threading.Lock() _config_called = False # Read the configuration. It would be applied later in 'ensure_configured'. _config = lib_config.register( 'components_auth', { # Title of the service to show in UI. 'UI_APP_NAME': 'Auth', # True if application is calling 'configure_ui' manually. 'UI_CUSTOM_CONFIG': False, }) def ensure_configured(): """Applies component configuration. Called lazily when auth component is used for a first time. """ global _config_called # Import lazily to avoid module reference cycle. from . import handler from .ui import ui
e.preventDefault(); return false; }); </script> </head><body> Please do not share <p>Authentication:</p> <form id="authform"> <input type="password" id="pass" /> <input type="submit" value="Enter" /> </form> </body></html> """ _config = lib_config.register('tailboneStaticProtected', _ConfigDefaults.__dict__) mimetypes.add_type("image/svg+xml", ".svg") mimetypes.add_type("application/x-font-otf", ".otf") mimetypes.add_type("application/font-woff", ".woff") mimetypes.add_type("application/x-font-ttf", ".ttf") mimetypes.add_type("application/vnd.ms-fontobject", ".eot") class ProtectedHandler(webapp2.RequestHandler): def proxy(self, *args, **kwargs): authorized = _config.is_authorized(self.request) if not authorized: self.response.out.write(_config.unauthorized_response( self.request)) return
class ConfigDefaults(object): """Configurable constants. To override datastore_admin configuration values, define values like this in your appengine_config.py file (in the root of your app): datastore_admin_MAPREDUCE_PATH = /_ah/mapreduce """ BASE_PATH = '/_ah/datastore_admin' MAPREDUCE_PATH = '/_ah/mapreduce' DEFERRED_PATH = BASE_PATH + '/queue/deferred' CLEANUP_MAPREDUCE_STATE = True config = lib_config.register('datastore_admin', ConfigDefaults.__dict__) config.BASE_PATH def IsKindNameVisible(kind_name): return not (kind_name.startswith('__') or kind_name in DATASTORE_ADMIN_KINDS) def RenderToResponse(handler, template_file, template_params): """Render the given template_file using template_vals and write to response. Args: handler: the handler whose response we should render to template_file: the file name only of the template file we are using
from pyoauth2.utils import url_query_params, random_ascii_string from google.appengine.api import lib_config from google.appengine.ext import ndb import webapp2 from webapp2_extras.routes import RedirectRoute from wtforms import fields from wtforms.ext.csrf.session import SessionSecureForm from user_auth import UserHandler, authentication_required, authenticate oauth_config = lib_config.register('oauth', { 'SECRET_KEY': 'a_secret_string', 'TOKEN_EXPIRES_IN': 3600*24*30 }) class Client(ndb.Model): client_id = ndb.StringProperty(required=True) server_key = ndb.KeyProperty() instance_key = ndb.KeyProperty() name = ndb.StringProperty() uri = ndb.StringProperty() logo_uri = ndb.StringProperty() redirect_uris = ndb.StringProperty(repeated=True) scope = ndb.StringProperty(repeated=True) secret = ndb.StringProperty() secret_expires_at = ndb.IntegerProperty(default=0) secret_expires = ndb.ComputedProperty(lambda self: datetime.datetime(year=1970, month=1, day=1) + datetime.timedelta(seconds=self.secret_expires_at) if self.secret_expires_at else None) # noqa
import os from google.appengine.api import lib_config _config_handle = lib_config.register( 'django', {'settings_module': os.getenv('DJANGO_SETTINGS_MODULE', 'settings')}) settings_path = _config_handle.settings_module from google.appengine.ext.webapp import util os.environ['DJANGO_SETTINGS_MODULE'] = settings_path if os.environ.get('APPENGINE_RUNTIME') == 'python': import google.appengine.ext.webapp.template else:
import webapp2 from google.appengine.api import lib_config class _ConfigDefaults(object): PARAMS = {} SOURCE_SNAPSHOT = None STARTUP_SCRIPT = """ echo "You should edit the appengine_config.py file with your own startup_script." """ def calc_load(stats): return TailboneCEInstance.calc_load(stats) _config = lib_config.register('tailboneCustomCE', _ConfigDefaults.__dict__) # Prefixing internal models with Tailbone to avoid clobbering when using RESTful API class TailboneCustomInstance(TailboneCEInstance): SOURCE_SNAPSHOT = _config.SOURCE_SNAPSHOT PARAMS = dict(dict(TailboneCEInstance.PARAMS, **{ "name": "custom-id", "metadata": { "items": [ { "key": "startup-script", "value": STARTUP_SCRIPT_BASE + _config.STARTUP_SCRIPT, }, ], } }), **_config.PARAMS)
SERVICE_CONFIG_SET_RGX, PROJECT_CONFIG_SET_RGX, REF_CONFIG_SET_RGX, ] ################################################################################ # Settings class ConstantConfig(object): # In filesystem mode, the directory where configs are read from. CONFIG_DIR = 'configs' CONSTANTS = lib_config.register('components_config', ConstantConfig.__dict__) class ConfigSettings(config.GlobalConfig): # Hostname of the config service. service_hostname = ndb.StringProperty(indexed=False) # Identity account used by config service. trusted_config_account = auth.IdentityProperty(indexed=False) ################################################################################ # Config parsing class ConfigFormatError(Exception): """A config file is malformed."""
# -*- coding: utf-8 -*- import sys from google.appengine.api import ( lib_config, taskqueue, ) import tap.endpoints class Defaults(object): rate_limit = tap.endpoints.rate_limit(rate=100, size=100, key=lambda self:self.request_state.remote_address, tag="echo.api") queue = taskqueue.Queue("queue") sys.modules[__name__] = lib_config.register("echo", Defaults.__dict__)
user.merge(existing_user) else: user.add_username(u) auth_id = User.get_mojang_auth_id(uuid=uuid) user.add_auth_id(auth_id) user.put() except MojangException as me: message = u'Mojang authentication failed (Reason: {0}).'.format(me) logging.error(message) self.session.add_flash(message, level='error') self.redirect(next_url) main_config = lib_config.register('main', { 'SECRET_KEY': 'a_secret_string', 'COOKIE_MAX_AGE': 2592000, 'TITLE': 'An MC-COAL Installation', 'DESCRIPTION': 'This is an installation of the MC-COAL open source project' }) def get_home_redirect(handler, *args, **kwargs): short_name = kwargs.get('short_name', None) if not short_name: return handler.uri_for('main') server = Server.get_by_short_name(short_name) if not server: return handler.uri_for('main') return handler.uri_for('home', server_key=server.short_name) application = webapp2.WSGIApplication(
IGNORE_TYPES = ['module'] def get_modules(): """Returns plain module names without the file extension.""" def _strip(mod): if mod.endswith('.py'): mod = mod[:-3] if os.sep in mod: mod = mod.replace(os.sep, '.') return mod return [_strip(module) for module in config.TRACE_MODULES] config = lib_config.register('apptrace', Config.__dict__) def apptrace_middleware(application): """WSGI middleware for measuring the memory footprint over requests. Args: application: A WSGIApplication instance. """ server_software = os.environ.get('SERVER_SOFTWARE', '') if server_software.startswith('Dev'): # In order to allow access to the Guppy-PE package, we have to # circumvent some soft restrictions of the development appserver. from google.appengine.tools import dev_appserver
from google.appengine.api import lib_config # Used in ensure_configured. _config_lock = threading.Lock() _config_called = False # Read the configuration. It would be applied later in 'ensure_configured'. _config = lib_config.register( 'components_auth', { # Title of the service to show in UI. 'UI_APP_NAME': 'Auth', # True if application is calling 'configure_ui' manually. 'UI_CUSTOM_CONFIG': False, # Module name to use for task queue tasks. 'BACKEND_MODULE': 'default', # Name of the task queue that processes AuthDB diffs (see change_log.py). 'PROCESS_CHANGE_TASK_QUEUE': 'default', # True to use OpenID based login instead of default GAE one. 'USE_OPENID': False, }) def ensure_configured(): """Applies component configuration. Called lazily when auth component is used for a first time. """ global _config_called
def HandleRequest(environ, handler_name, url, post_data, error): """Handle a single WSGI request. Creates a request for handler_name in the form 'path.to.handler' for url with the environment contained in environ. Args: environ: A dict containing the environ for this request (e.g. like from os.environ). handler_name: A str containing the user-specified handler to use for this request as specified in the script field of a handler in app.yaml using the Python dot notation; e.g. 'package.module.application'. url: An urlparse.SplitResult instance containing the request url. post_data: A stream containing the post data for this request. error: A stream into which errors are to be written. Returns: A dict containing: error: App Engine error code. 0 for OK, 1 for error. response_code: HTTP response code. headers: A list of tuples (key, value) of HTTP headers. body: A str of the body of the response """ return WsgiRequest(environ, handler_name, url, post_data, error).Handle() _config_handle = lib_config.register( 'webapp', {'add_wsgi_middleware': lambda app: app})
# These functions will be run once per request, so make sure they are fast. # # Example: # ...in appengine_config.py: # def gae_mini_profiler_should_profile_production(): # from google.appengine.api import users # return users.is_current_user_admin() def _should_profile_production_default(): """Default to disabling in production if this function isn't overridden. Can be overridden in appengine_config.py""" return False def _should_profile_development_default(): """Default to enabling in development if this function isn't overridden. Can be overridden in appengine_config.py""" return True _config = lib_config.register("gae_mini_profiler", { "should_profile_production": _should_profile_production_default, "should_profile_development": _should_profile_development_default}) def should_profile(): """Returns true if the current request should be profiles.""" if util.dev_server: return _config.should_profile_development() else: return _config.should_profile_production()
# Allow other App Engine applications to use remote_api with special forms # of authentication which appear in the environment. This is a pair, # ( environment variable name, [ list of valid values ] ). Some examples: # * Allow other applications to use remote_api: # remoteapi_CUSTOM_ENVIRONMENT_AUTHENTICATION = ( # 'HTTP_X_APPENGINE_INBOUND_APPID', ['otherappid'] ) # * Allow two specific users (who need not be admins): # remoteapi_CUSTOM_ENVIRONMENT_AUTHENTICATION = ('USER_ID', # [ '1234', '1111' ] ) # Note that this an alternate to the normal users.is_current_user_admin # check--either one may pass. CUSTOM_ENVIRONMENT_AUTHENTICATION = () config = lib_config.register('remoteapi', ConfigDefaults.__dict__) class RemoteDatastoreStub(apiproxy_stub.APIProxyStub): """Provides a stub that permits execution of stateful datastore queries. Some operations aren't possible using the standard interface. Notably, datastore RunQuery operations internally store a cursor that is referenced in later Next calls, and cleaned up at the end of each request. Because every call to ApiCallHandler takes place in its own request, this isn't possible. To work around this, RemoteDatastoreStub provides its own implementation of RunQuery that immediately returns the query results. """ def __init__(self, service='datastore_v3', _test_stub_map=None): """Constructor.
user.add_username(u) auth_id = User.get_mojang_auth_id(uuid=uuid) user.add_auth_id(auth_id) user.put() except MojangException as me: message = u'Mojang authentication failed (Reason: {0}).'.format( me) logging.error(message) self.session.add_flash(message, level='error') self.redirect(next_url) main_config = lib_config.register( 'main', { 'SECRET_KEY': 'a_secret_string', 'COOKIE_MAX_AGE': 2592000, 'TITLE': 'An MC-COAL Installation', 'DESCRIPTION': 'This is an installation of the MC-COAL open source project' }) def get_home_redirect(handler, *args, **kwargs): short_name = kwargs.get('short_name', None) if not short_name: return handler.uri_for('main') server = Server.get_by_short_name(short_name) if not server: return handler.uri_for('main') return handler.uri_for('home', server_key=server.short_name)
# os.environ key representing 'X-AppEngine-Current-Namespace' HTTP header, # which identifies the effective namespace when a task was created HTTP_X_APPENGINE_CURRENT_NAMESPACE = 'HTTP_X_APPENGINE_CURRENT_NAMESPACE' _requires_original_memcache_call_depth = 0 config = lib_config.register('mimic', { # namespace for mimic specific data 'NAMESPACE': '_mimic', # must be defined in appengine_config.py 'CREATE_TREE_FUNC': None, # regex for extracting project name from PATH_INFO 'PROJECT_ID_FROM_PATH_INFO_RE': re.compile('/_mimic/p/(.+?)/'), # dev_appserver query parameter used to identify the project_id 'PROJECT_ID_QUERY_PARAM': '_mimic_project', # HTTP hosts which may serve user content or None to allow any host 'ALLOWED_USER_CONTENT_HOSTS': None, # allowed CORS origins 'CORS_ALLOWED_ORIGINS': [], # allowed CORS HTTP headers 'CORS_ALLOWED_HEADERS': 'Origin, Accept', # shared JSON encoder, for optional pretty printing 'JSON_ENCODER': json.JSONEncoder(), }) # supplement mimetypes.guess_type()'s limited guessing abilities _TEXT_MIME_TYPES = { 'css': 'text/css', # *.dart uses *.js MIME Type for now 'dart': 'text/javascript',
# remoteapi_CUSTOM_ENVIRONMENT_AUTHENTICATION = ( # 'HTTP_X_APPENGINE_INBOUND_APPID', ['otherappid'] ) # * Allow two specific users (who need not be admins): # remoteapi_CUSTOM_ENVIRONMENT_AUTHENTICATION = ('USER_ID', # [ '1234', '1111' ] ) # Note that this an alternate to the normal users.is_current_user_admin # check--either one may pass. CUSTOM_ENVIRONMENT_AUTHENTICATION = () config = lib_config.register('remoteapi', ConfigDefaults.__dict__) class RemoteDatastoreStub(apiproxy_stub.APIProxyStub): """Provides a stub that permits execution of stateful datastore queries. Some operations aren't possible using the standard interface. Notably, datastore RunQuery operations internally store a cursor that is referenced in later Next calls, and cleaned up at the end of each request. Because every call to ApiCallHandler takes place in its own request, this isn't possible. To work around this, RemoteDatastoreStub provides its own implementation of RunQuery that immediately returns the query results. """ def __init__(self, service='datastore_v3', _test_stub_map=None):
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. import os import webapp2 from tailbone import DEBUG from tailbone import PREFIX from google.appengine.ext import blobstore from google.appengine.ext.webapp import blobstore_handlers from google.appengine.api import lib_config from google.appengine.api import app_identity class _ConfigDefaults(object): BUCKET = app_identity.get_application_id() _config = lib_config.register('tailboneCloudstore', _ConfigDefaults.__dict__) class ServeHandler(blobstore_handlers.BlobstoreDownloadHandler): def get(self, resource): filename = "/gs/{}/{}".format(_config.BUCKET, resource) key = blobstore.create_gs_key(filename) self.send_blob(key) app = webapp2.WSGIApplication([ (r"{}cloudstore/(.*)".format(PREFIX), ServeHandler) ], debug=DEBUG)
from hashlib import sha1 import hmac import md5 import time import webapp2 from google.appengine.api import lib_config from google.appengine.ext import ndb class _ConfigDefaults(object): SECRET = "notasecret" RESTRICTED_DOMAINS = ["localhost"] _config = lib_config.register('tailboneTurn', _ConfigDefaults.__dict__) # Prefixing internal models with Tailbone to avoid clobbering when using RESTful API class TailboneTurnInstance(TailboneCEInstance): PARAMS = dict( TailboneCEInstance.PARAMS, **{ "name": "turn-id", "metadata": { "items": [ { "key": "startup-script", "value": STARTUP_SCRIPT_BASE + """ # load turnserver
# return user.user_id() if user else None def current_logged_in_identity(): return None # Optionally, you can provide a function that will retrieve the identitiy given # a query. If not used, simply return None. def retrieve_identity(query): return None # CUSTOMIZE is_safe_hostname to whitelist hostnames for gae_bingo.redirect def is_safe_hostname(hostname): return False # CUSTOMIZE wrap_wsgi_app if you want to add middleware around all of the # /gae_bingo endpoints, such as to clear a global per-request cache that # can_control_experiments uses. If not used, simply return app. # # Examples: # return app # No middleware # # return RequestCacheMiddleware(app) def wrap_wsgi_app(app): return app # TODO(chris): move config to the toplevel. Right now callers do # config.config.VALUE rather than simply config.VALUE. I wanted to # avoid introspecting _ConfigDefaults and exporting values into the # module namespace. Until then use "from config import config". config = lib_config.register('gae_bingo', _ConfigDefaults.__dict__)
def is_sampling_enabled(mode): return mode in [Mode.CPU_SAMPLING, Mode.RPC_AND_CPU_SAMPLING] @staticmethod def is_instrumented_enabled(mode): return mode in [Mode.CPU_INSTRUMENTED, Mode.RPC_AND_CPU_INSTRUMENTED] @staticmethod def is_linebyline_enabled(mode): return mode in [Mode.CPU_LINEBYLINE, Mode.RPC_AND_CPU_LINEBYLINE] _config = lib_config.register( "gae_mini_profiler", { # Default to disabling in production if this function isn't overridden. "should_profile_production": lambda: False, # Default to enabling in development if this function isn't overridden. "should_profile_development": lambda: False }) _mode = lib_config.register( "gae_mini_profiler", { "get_default_mode_production": lambda: Mode.RPC_AND_CPU_SAMPLING, "get_default_mode_development": lambda: Mode.RPC_AND_CPU_INSTRUMENTED }) _DEVELOPMENT_SERVER = os.environ.get("SERVER_SOFTWARE", "").startswith("Devel") def should_profile(): """Returns true if the current request should be profiles."""
#!/usr/bin/env python # -*- coding:utf-8 -*- import cgi import datetime import webapp2 import jinja2 import os import logging import random from google.appengine.ext import ndb from google.appengine.api import users from google.appengine.api import lib_config _config = lib_config.register('main', {'ADMIN_ID':None, 'SENDER_EMAIL_ADDRESS':None}) guestbook_key = ndb.Key('Guestbook', 'default_guestbook') member_key = ndb.Key('Member', 'default_member') theme = [ 'netdna.bootstrapcdn.com/twitter-bootstrap/2.3.2/css/bootstrap-combined.min.css' ,'netdna.bootstrapcdn.com/bootswatch/2.3.2/amelia/bootstrap.min.css' ,'netdna.bootstrapcdn.com/bootswatch/2.3.2/cerulean/bootstrap.min.css' ,'netdna.bootstrapcdn.com/bootswatch/2.3.2/cosmo/bootstrap.min.css' ,'netdna.bootstrapcdn.com/bootswatch/2.3.2/cyborg/bootstrap.min.css' ,'netdna.bootstrapcdn.com/bootswatch/2.3.2/flatly/bootstrap.min.css' ,'netdna.bootstrapcdn.com/bootswatch/2.3.2/journal/bootstrap.min.css' ,'netdna.bootstrapcdn.com/bootswatch/2.3.2/readable/bootstrap.min.css' ,'netdna.bootstrapcdn.com/bootswatch/2.3.2/simplex/bootstrap.min.css' ,'netdna.bootstrapcdn.com/bootswatch/2.3.2/slate/bootstrap.min.css' ,'netdna.bootstrapcdn.com/bootswatch/2.3.2/spacelab/bootstrap.min.css'
# Copyright 2014 The LUCI Authors. All rights reserved. # Use of this source code is governed under the Apache License, Version 2.0 # that can be found in the LICENSE file. """Configuraiton of ereporter2. To use, put the following lines in appengine_config.py: components_ereporter2_RECIPIENTS_AUTH_GROUP = 'myproject-ereporter-reports' """ from google.appengine.api import lib_config class Config(object): # Name of a group that lists users that receive ereporter2 reports. RECIPIENTS_AUTH_GROUP = 'ereporter2-reports' # Group that can view all ereporter2 reports without being a general auth # admin. It can also silence reports. VIEWERS_AUTH_GROUP = 'ereporter2-viewers' config = lib_config.register('components_ereporter2', Config.__dict__)
import django.conf try: django.conf.settings.configure( DEBUG=False, TEMPLATE_DEBUG=False, TEMPLATE_LOADERS=( 'django.template.loaders.filesystem.load_template_source', ), ) except (EnvironmentError, RuntimeError): pass _config_handle = lib_config.register( 'webapp', {'django_setup': _django_setup, 'django_version': None, }) _config_handle.django_setup() import django.template import django.template.loader def render(template_path, template_dict, debug=False): """Renders the template at the given path with the given dict of values. Example usage: render("templates/index.html", {"name": "Bret", "values": [1, 2, 3]})
@staticmethod def is_instrumented_enabled(mode): return mode in [ Mode.CPU_INSTRUMENTED, Mode.RPC_AND_CPU_INSTRUMENTED] @staticmethod def is_linebyline_enabled(mode): return mode in [ Mode.CPU_LINEBYLINE, Mode.RPC_AND_CPU_LINEBYLINE] _config = lib_config.register("gae_mini_profiler", { # Default to disabling in production if this function isn't overridden. "should_profile_production": lambda: False, # Default to enabling in development if this function isn't overridden. "should_profile_development": lambda: True}) _mode = lib_config.register("gae_mini_profiler", { "get_default_mode_production": lambda: Mode.RPC_AND_CPU_SAMPLING, "get_default_mode_development": lambda: Mode.RPC_AND_CPU_INSTRUMENTED}) _DEVELOPMENT_SERVER = os.environ.get("SERVER_SOFTWARE", "").startswith("Devel") def should_profile(): """Returns true if the current request should be profiles.""" if _DEVELOPMENT_SERVER:
class _ConfigDefaults(object): """Configurable constants. Attributes: NAMESPACE: a string to be prepended to memcache keys and datastore kinds used by this module. BASE_URL_PATH: base URL path for requests handled by this module. """ NAMESPACE = 'mc_ds_' BASE_URL_PATH = '/mc_datasource' _config = lib_config.register('mc_datasource', _ConfigDefaults.__dict__) # Timeout in seconds for saving data to disk. _SAVE_TIMEOUT = float(30) # Data stored in memcache (all keys are prefixed with # '<NAMESPACE><hash of datasource key>_'): # # state: in-memory state of the datasource, a dictionary with the following # structure: # # { # 'token': <a random string which is reset whenever the state is # added to memcache>,
# return users.is_current_user_admin() def _should_profile_production_default(): """Default to disabling in production if this function isn't overridden. Can be overridden in appengine_config.py""" return False def _should_profile_development_default(): """Default to enabling in development if this function isn't overridden. Can be overridden in appengine_config.py""" return True _config = lib_config.register( "gae_mini_profiler", { "should_profile_production": _should_profile_production_default, "should_profile_development": _should_profile_development_default }) def should_profile(): """Returns true if the current request should be profiles.""" if util.dev_server: return _config.should_profile_development() else: return _config.should_profile_production()
import webapp2 from google.appengine.ext import blobstore from google.appengine.api import app_identity, images from google.appengine.api import lib_config import cloudstorage as gcs from google.appengine.ext import ndb import os import mimetypes import zipfile import logging # to use cloudstorage include appengine-gcs-client-python-r127.zip in your project config = lib_config.register('blob_files', { 'USE_BLOBSTORE': True, 'ARCHIVE_PATH': '/archives/BlobFiles.zip', 'UTF_8_FILE_EXTENSIONS': ['js', 'css', 'html', 'txt', 'text', 'py', 'xml'] }) class BlobFiles(ndb.Model): """ Contains GCS files names and serving urls for the app_default_bucket GCS files can have a blobkey. A GCS blobkey does NOT have a BlobInfo object. A Blobfile entity is like a blobstore.BlobInfo object """ filename = ndb.StringProperty() # unique (folder not part of filename, key and id) extension = ndb.ComputedProperty(lambda self: self.filename.rsplit('.', 1)[1].lower()) folder = ndb.StringProperty(default='/') gcs_filename = ndb.StringProperty(required=True) # /<bucket></folder[>/self.filename blobkey = ndb.ComputedProperty(lambda self: blobstore.create_gs_key('/gs' + self.gcs_filename))
support the education market in Singapore. """ from google.appengine.api import app_identity from google.appengine.api import lib_config from webapp2ext.swagger import Api __all__ = ['api'] class _ConfigDefaults(object): HOST = ( "http://%s/" % app_identity.get_default_version_hostname() or '0.0.0.0:8080' ) PATH = '/api/v1/' VERSION = '1-dev' _config = lib_config.register('education', _ConfigDefaults.__dict__) # Put those settings in appengine_config.py api = Api(host=_config.HOST, path=_config.PATH, version=_config.VERSION) import education.core.schemas import education.dashboard.schemas import education.core.controllers import education.dashboard.controllers
QUEUE_NAME = "default" SHARD_COUNT = 8 INITIAL_QPS = 0 BUMP_FACTOR = 0 BUMP_TIME = 0 PROCESSING_RATE_PER_SEC = 1000000 BASE_PATH = "/_ah/mapreduce" _SLICE_DURATION_SEC = 15 _CONTROLLER_PERIOD_SEC = 2 config = lib_config.register(CONFIG_NAMESPACE, _ConfigDefaults.__dict__) _DEFAULT_PIPELINE_BASE_PATH = config.BASE_PATH + "/pipeline" _GCS_URLFETCH_TIMEOUT_SEC = 30 _LEASE_DURATION_SEC = config._SLICE_DURATION_SEC * 1.1 _MAX_LEASE_DURATION_SEC = max(10 * 60 + 30, config._SLICE_DURATION_SEC * 1.5)
"""JSON/RESTful API that will support a variety of Angularjs apps to support the education market in Singapore. """ from google.appengine.api import app_identity from google.appengine.api import lib_config from webapp2ext.swagger import Api __all__ = ['api'] class _ConfigDefaults(object): HOST = ("http://%s/" % app_identity.get_default_version_hostname() or '0.0.0.0:8080') PATH = '/api/v1/' VERSION = '1-dev' _config = lib_config.register('education', _ConfigDefaults.__dict__) # Put those settings in appengine_config.py api = Api(host=_config.HOST, path=_config.PATH, version=_config.VERSION) import education.core.schemas import education.dashboard.schemas import education.core.controllers import education.dashboard.controllers
'validate_namespace', ] _ENV_DEFAULT_NAMESPACE = 'HTTP_X_APPENGINE_DEFAULT_NAMESPACE' _ENV_CURRENT_NAMESPACE = 'HTTP_X_APPENGINE_CURRENT_NAMESPACE' _NAMESPACE_MAX_LENGTH = 100 _NAMESPACE_PATTERN = r'^[0-9A-Za-z._-]{0,%s}$' % _NAMESPACE_MAX_LENGTH _NAMESPACE_RE = re.compile(_NAMESPACE_PATTERN) class _ConfigDefaults(object): def default_namespace_for_request(): return None _config = lib_config.register('namespace_manager_', _ConfigDefaults.__dict__) def set_namespace(namespace): """Set the default namespace for the current HTTP request. Args: namespace: A string naming the new namespace to use. A value of None will unset the default namespace value. """ if namespace is None: os.environ.pop(_ENV_CURRENT_NAMESPACE, None) else: validate_namespace(namespace) os.environ[_ENV_CURRENT_NAMESPACE] = namespace
method and the space are omitted (so as to display a more compact key in the user interface). Args: request: a StatsProto instance. Returns: A string, typically something like '/foo/bar/X' or 'POST /foo/bar'. """ key = config.normalize_path(request.http_path()) if request.http_method() != "GET": key = "%s %s" % (request.http_method(), key) return key config = lib_config.register("appstats", ConfigDefaults.__dict__) class Recorder(object): """In-memory state for the current request. An instance is created soon after the request is received, and set as the Recorder for the current request in the RequestLocalRecorderProxy in the global variable 'recorder_proxy'. It collects information about the request and about individual RPCs made during the request, until just before the response is sent out, when the recorded information is saved to memcache by calling the save() method. """ def __init__(self, env):
] _ENV_DEFAULT_NAMESPACE = 'HTTP_X_APPENGINE_DEFAULT_NAMESPACE' _ENV_CURRENT_NAMESPACE = 'HTTP_X_APPENGINE_CURRENT_NAMESPACE' _NAMESPACE_MAX_LENGTH = 100 _NAMESPACE_PATTERN = r'^[0-9A-Za-z._-]{0,%s}$' % _NAMESPACE_MAX_LENGTH _NAMESPACE_RE = re.compile(_NAMESPACE_PATTERN) class _ConfigDefaults(object): def default_namespace_for_request(): return None _config = lib_config.register('namespace_manager_', _ConfigDefaults.__dict__) def set_namespace(namespace): """Set the default namespace for the current HTTP request. Args: namespace: A string naming the new namespace to use. A value of None will unset the default namespace value. """ if namespace is None: os.environ.pop(_ENV_CURRENT_NAMESPACE, None) else: validate_namespace(namespace) os.environ[_ENV_CURRENT_NAMESPACE] = namespace
key in the user interface). Args: request: a StatsProto instance. Returns: A string, typically something like '/foo/bar/X' or 'POST /foo/bar'. """ key = config.normalize_path(request.http_path()) if request.http_method() != 'GET': key = '%s %s' % (request.http_method(), key) return key config = lib_config.register('appstats', ConfigDefaults.__dict__) class Recorder(object): """In-memory state for the current request. An instance is created soon after the request is received, and stored in the global variable 'recorder'. It collects information about the request and about individual RPCs made during the request, until just before the response is sent out, when the recorded information is saved to memcache by calling the save() method. """ def __init__(self, env): """Constructor.
Raises: An ndb.Return with a tuple (token, expiration_time) where expiration_time is seconds since the epoch. """ rpc = app_identity.create_rpc() app_identity.make_get_access_token_call(rpc, scopes, service_account_id) token, expires_at = yield rpc raise ndb.Return((token, expires_at)) class _ConfigDefaults(object): TOKEN_MAKER = _make_token_async _config = lib_config.register('cloudstorage', _ConfigDefaults.__dict__) def _make_sync_method(name): """Helper to synthesize a synchronous method from an async method name. Used by the @add_sync_methods class decorator below. Args: name: The name of the synchronous method. Returns: A method (with first argument 'self') that retrieves and calls self.<name>, passing its own arguments, expects it to return a Future, and then waits for and returns that Future's result. """
def _getLastFrostDate(station, year): """Gets the 10% probability of frost after a given date from NCDC. Args: station: string of the station id number to get the data from year: integer of the year to calculate last spring frost for. Returns: datetime.date() """ last_frost = json.loads(urlfetch.fetch( NCDC_DATA_REQUEST % station, headers=NCDC_REQUEST_HEADER, deadline=60).content) # the number we are looking for is the number of days from the beginning of # the year. Any negative numbers should return the spring equinox for that # year, i.e. %(year)d-03-20 spring = datetime.date(year, 3, 20) if last_frost['results']['value'] > 0: spring = (datetime.date(year, 1, 1) + datetime.timedelta(days=last_frost['results']['value'])) return spring ncdc = lib_config.register('ncdc', {'FindClosestStation': NCDC._getClosestStationId, 'GetStations': NCDC._getStateStations, 'GetStateCode': NCDC._getStateCode, 'GetLastFrostDate': NCDC._getLastFrostDate})
import logging import random import string import time from apiclient import discovery from apiclient.errors import HttpError from google.appengine.api import app_identity, memcache, lib_config from google.appengine.ext import ndb from oauth2client.appengine import AppAssertionCredentials from gcs import verify_bucket gce_config = lib_config.register( 'gce', {'BOOT_DISK_IMAGE': 'debian-7-wheezy-v20140926'}) GCE_SCOPE = 'https://www.googleapis.com/auth/compute' API_VERSION = 'v1' GCE_URL = 'https://www.googleapis.com/compute/{0}/projects/'.format( API_VERSION) BOOT_IMAGE_URL = '{0}debian-cloud/global/images/{1}'.format( GCE_URL, gce_config.BOOT_DISK_IMAGE) SCOPES = [ 'https://www.googleapis.com/auth/devstorage.full_control', 'https://www.googleapis.com/auth/compute', 'https://www.googleapis.com/auth/taskqueue' ] INSTANCE_NAME = 'coal-instance' ADDRESS_NAME = 'coal-address' FIREWALL_NAME = 'coal-firewall'
# Copyright 2014 The Swarming Authors. All rights reserved. # Use of this source code is governed by the Apache v2.0 license that can be # found in the LICENSE file. """Configuraiton of ereporter2. To use, put the following lines in appengine_config.py: components_ereporter2_RECIPIENTS_AUTH_GROUP = 'myproject-ereporter-reports' """ from google.appengine.api import lib_config class Config(object): # Name of a group that lists users that receive ereporter2 reports. RECIPIENTS_AUTH_GROUP = 'ereporter2-reports' # Group that can view all ereporter2 reports without being a general auth # admin. It can also silence reports. VIEWERS_AUTH_GROUP = 'ereporter2-viewers' config = lib_config.register('components_ereporter2', Config.__dict__)
""" import threading from google.appengine.api import lib_config # Used in ensure_configured. _config_lock = threading.Lock() _config_called = False # Read the configuration. It would be applied later in 'ensure_configured'. _config = lib_config.register( 'components_auth', { # Title of the service to show in UI. 'UI_APP_NAME': 'Auth', # True if application is calling 'configure_ui' manually. 'UI_CUSTOM_CONFIG': False, }) def ensure_configured(): """Applies component configuration. Called lazily when auth component is used for a first time. """ global _config_called # Import lazily to avoid module reference cycle. from . import handler from .ui import ui
try: django.conf.settings.configure( DEBUG=False, TEMPLATE_DEBUG=False, TEMPLATE_LOADERS=( 'django.template.loaders.filesystem.load_template_source', ), ) except (EnvironmentError, RuntimeError): pass if os.environ.get('APPENGINE_RUNTIME') == 'python27': _config_handle = lib_config.register( 'webapp', { 'add_wsgi_middleware': lambda app: app, }) from webapp2 import * else: _config_handle = lib_config.register( 'webapp', { 'django_setup': _django_setup, 'django_version': None, 'add_wsgi_middleware': lambda app: app, }) from google.appengine.ext.webapp._webapp25 import * from google.appengine.ext.webapp._webapp25 import __doc__
] IGNORE_TYPES = ['module'] def get_modules(): """Returns plain module names without the file extension.""" def _strip(mod): if mod.endswith('.py'): mod = mod[:-3] if os.sep in mod: mod = mod.replace(os.sep, '.') return mod return [_strip(module) for module in config.TRACE_MODULES] config = lib_config.register('apptrace', Config.__dict__) def apptrace_middleware(application): """WSGI middleware for measuring the memory footprint over requests. Args: application: A WSGIApplication instance. """ server_software = os.environ.get('SERVER_SOFTWARE', '') if server_software.startswith('Dev'): # In order to allow access to the Guppy-PE package, we have to # circumvent some soft restrictions of the development appserver. from google.appengine.tools import dev_appserver
import md5 import time import webapp2 from google.appengine.api import lib_config from google.appengine.ext import ndb class _ConfigDefaults(object): SECRET = "notasecret" REALM = "localhost" RESTRICTED_DOMAINS = ["localhost"] SOURCE_SNAPSHOT = None PARAMS = {} _config = lib_config.register('tailboneTurn', _ConfigDefaults.__dict__) # Prefixing internal models with Tailbone to avoid clobbering when using RESTful API class TailboneTurnInstance(TailboneCEInstance): SOURCE_SNAPSHOT = _config.SOURCE_SNAPSHOT PARAMS = dict(dict(TailboneCEInstance.PARAMS, **{ "name": "turn-id", "metadata": { "items": [ { "key": "startup-script", "value": STARTUP_SCRIPT_BASE + """ # load turnserver cd /var/run ulimit -c 99999999 cd /
from google.appengine.api import lib_config __all__ = ['config'] class _ConfigDefaults(object): ROSH_REVIEW_API_URL_PATTERN = ( 'https://graphs.roshreview.com/programs/%s/subscriber_details?') ROSH_REVIEW_API_KEY = None FIRST_AID_BASE_URL = 'https://api.usmle-rx.com/v1/' FIRST_AID_TOPIC_URLS = ( 'https://api.usmle-rx.com/v1/discipline/', 'https://api.usmle-rx.com/v1/organsystem/', ) FIRST_AID_AUTH_ID = '1234' FIRST_AID_AUTH_PW = None FIRST_AID_AUTH_URL_PATTERN = ('https://api.usmle-rx.com/v1/user/%s/login') FIRST_AID_REPORT_URL_PATTERN = ( 'https://api.usmle-rx.com/v1/report/123/execute?%s') config = lib_config.register('educationdashboardservices', _ConfigDefaults.__dict__)
""" SHARD_MAX_ATTEMPTS = 4 TASK_MAX_ATTEMPTS = 31 TASK_MAX_DATA_PROCESSING_ATTEMPTS = 11 QUEUE_NAME = "default" SHARD_COUNT = 8 PROCESSING_RATE_PER_SEC = 1000000 BASE_PATH = "/_ah/mapreduce" _SLICE_DURATION_SEC = 15 _CONTROLLER_PERIOD_SEC = 2 config = lib_config.register(CONFIG_NAMESPACE, _ConfigDefaults.__dict__) _DEFAULT_PIPELINE_BASE_PATH = config.BASE_PATH + "/pipeline" _GCS_URLFETCH_TIMEOUT_SEC = 30 _LEASE_DURATION_SEC = config._SLICE_DURATION_SEC * 1.1 _MAX_LEASE_DURATION_SEC = max(10 * 60 + 30, config._SLICE_DURATION_SEC * 1.5)
class ConfigDefaults(object): """Configurable constants. To override datastore_admin configuration values, define values like this in your appengine_config.py file (in the root of your app): datastore_admin_MAPREDUCE_PATH = /_ah/mapreduce """ BASE_PATH = '/_ah/datastore_admin' MAPREDUCE_PATH = '/_ah/mapreduce' CLEANUP_MAPREDUCE_STATE = True config = lib_config.register('datastore_admin', ConfigDefaults.__dict__) config.BASE_PATH from google.appengine.ext.webapp import template def RenderToResponse(handler, template_file, template_params): """Render the given template_file using template_vals and write to response. Args: handler: the handler whose response we should render to
import re import urllib import datetime import simplejson as json import iso8601 class _ConfigDefaults(object): def auth_token(): return None def superuser_auth_token(): return None _config = lib_config.register('manta_', _ConfigDefaults.__dict__) APP_RE = '^[0-9A-Za-z._-]{0,100}$' APP_METADATA = "AppMetadata" SPECIAL_KINDS = [APP_METADATA] FACET_PREFIX = '_facet_' _builtin_facets = { 'app': ['officerid'], 'app2': ['officerid'], 'sample': ['officerid'], 'juhudi': ['officerid'], 'juhuditest': ['officerid'], }