Example #1
0
def get_app_hostname():
  """Return hostname of a running Endpoints service.

  Returns hostname of an running Endpoints API. It can be 1) "localhost:PORT"
  if running on development server, or 2) "app_id.appspot.com" if running on
  external app engine prod, or "app_id.googleplex.com" if running as Google
  first-party Endpoints API, or 4) None if not running on App Engine
  (e.g. Tornado Endpoints API).

  Returns:
    A string representing the hostname of the service.
  """
  if not is_running_on_app_engine() or is_running_on_localhost():
    return None

  version = modules.get_current_version_name()
  app_id = app_identity.get_application_id()

  suffix = 'appspot.com'

  if ':' in app_id:
    tokens = app_id.split(':')
    api_name = tokens[1]
    if tokens[0] == 'google.com':
      suffix = 'googleplex.com'
  else:
    api_name = app_id

  # Check if this is the default version
  default_version = modules.get_default_version()
  if version == default_version:
    return '{0}.{1}'.format(app_id, suffix)
  else:
    return '{0}-dot-{1}.{2}'.format(version, api_name, suffix)
Example #2
0
def get_app_hostname():
  """Return hostname of a running Endpoints service.

  Returns hostname of an running Endpoints API. It can be 1) "localhost:PORT"
  if running on development server, or 2) "app_id.appspot.com" if running on
  external app engine prod, or "app_id.googleplex.com" if running as Google
  first-party Endpoints API, or 4) None if not running on App Engine
  (e.g. Tornado Endpoints API).

  Returns:
    A string representing the hostname of the service.
  """
  if not is_running_on_app_engine() or is_running_on_localhost():
    return None

  version = modules.get_current_version_name()
  app_id = app_identity.get_application_id()

  suffix = 'appspot.com'

  if ':' in app_id:
    tokens = app_id.split(':')
    api_name = tokens[1]
    if tokens[0] == 'google.com':
      suffix = 'googleplex.com'
  else:
    api_name = app_id

  # Check if this is the default version
  default_version = modules.get_default_version()
  if version == default_version:
    return '{0}.{1}'.format(app_id, suffix)
  else:
    return '{0}-dot-{1}.{2}'.format(version, api_name, suffix)
    def post(self):
        self.response.headers['Content-Type'] = 'application/json'

        namespace = DEFAULT_NAMESPACE
        data = json.loads(self.request.body)
        if "namespace" in data:
            namespace = data["namespace"]

        lead = Lead(parent=lead_key(namespace))

        errors = []
        for key, value in data.items():
            if key in LEAD_EDITABLE_PROPS:
                logging.debug(key)
                setattr(lead, key, value)

            else:
                logging.warn("Ignoring key: %s" % key)

        if errors:
            self.abort(400)
            json.dump({"status": "failure", "errors": errors}, self.response)

        else:
            lead.version = modules.get_current_version_name()
            lead.calc_token()
            lead.put()

            notify_admins(lead.to_dict(),
                          subject_template=EMAIL_SUBJECT_TEMPLATE,
                          body_template=EMAIL_TEMPLATE)

            json.dump({"status": "success"}, self.response)
Example #4
0
def get_hostname_prefix():
  """Returns the hostname prefix of a running Endpoints service.

  The prefix is the portion of the hostname that comes before the API name.
  For example, if a non-default version and a non-default service are in use,
  the returned result would be '{VERSION}-dot-{SERVICE}-'.

  Returns:
    str, the hostname prefix.
  """
  parts = []

  # Check if this is the default version
  version = modules.get_current_version_name()
  default_version = modules.get_default_version()
  if version != default_version:
    parts.append(version)

  # Check if this is the default module
  module = modules.get_current_module_name()
  if module != 'default':
    parts.append(module)

  # If there is anything to prepend, add an extra blank entry for the trailing
  # -dot-
  if parts:
    parts.append('')

  return '-dot-'.join(parts)
Example #5
0
def get_hostname_prefix():
    """Returns the hostname prefix of a running Endpoints service.

  The prefix is the portion of the hostname that comes before the API name.
  For example, if a non-default version and a non-default service are in use,
  the returned result would be '{VERSION}-dot-{SERVICE}-'.

  Returns:
    str, the hostname prefix.
  """
    parts = []

    # Check if this is the default version
    version = modules.get_current_version_name()
    default_version = modules.get_default_version()
    if version != default_version:
        parts.append(version)

    # Check if this is the default module
    module = modules.get_current_module_name()
    if module != 'default':
        parts.append(module)

    # If there is anything to prepend, add an extra blank entry for the trailing
    # -dot-
    if parts:
        parts.append('')

    return '-dot-'.join(parts)
    def get(self):
        if os.getenv('SERVER_SOFTWARE', '').startswith('Google App Engine/'):
            version = modules.get_current_version_name()

        else:
            version = "dev"

        self.response.headers['Content-Type'] = 'application/json'
        json.dump({"version": version}, self.response)
 def _findCurrent(self):
     
     if not getInTestHarness():
         from google.appengine.api.modules.modules import get_current_version_name
         ret = get_current_version_name()
     
     if ret:
         return ret
     
     return DEFAULTCURRENT
Example #8
0
 def _findCurrent(self):
     
     if not getInTestHarness():
         from google.appengine.api.modules.modules import get_current_version_name
         ret = get_current_version_name()
     
     if ret:
         return ret
     
     return DEFAULTCURRENT
Example #9
0
    def get(self):
        if not self.user:
          self.redirect('https://www.trot.to'
                        if self.request.host == 'trot.to'
                        else '/_/auth/login')

        template = JINJA_ENVIRONMENT.get_template('index.html')

        self.response.write(template.render(
            {'app_version_id': modules.get_current_version_name(),
             'alreadyAcceptedTerms': self.session.get('already_accepted_terms', False),
             'csrf_token': self.session.get('csrf_token', '')}
        ))
Example #10
0
from google.appengine.api.modules import modules

# add all egg files to sys.path
# use egg files instead of plain directory for beautiful directory structure and faster upload
lib_path = os.path.normpath(os.path.join(os.path.dirname(__file__), "..", "vendor"))
for zip_file in os.listdir(lib_path):
    sys.path.insert(0, os.path.join(lib_path, zip_file))

import flask

app = flask.Flask("application")

# Config from os.environ are all strings, but here only accepts integer.
app.config["PERMANENT_SESSION_LIFETIME"] = 31536000  # one year

current_version_name = modules.get_current_version_name()

# import all configs from app.yaml
os_names = (
    "SITE_NAME",
    "SESSION_COOKIE_PATH",
    "CONSUMER_KEY",
    "CONSUMER_SECRET",
    "SECRET_KEY",
)
for name in os_names:
    name_with_version = name + "_V" + current_version_name
    if name_with_version not in os.environ:
        name_with_version = name
    logging.debug("load config %s from %s", name, name_with_version)
    app.config[name] = os.environ[name_with_version]
 * 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.
"""
from .base import *

from djangae.utils import find_project_root
from google.appengine.api.modules.modules import get_current_version_name

ANALYTICS_KEY = "UA-74361602-1"

########## CACHING CONFIGURATION
from google.appengine.api.modules.modules import get_current_version_name

try:
    CACHES["default"]["KEY_PREFIX"] = get_current_version_name()
except KeyError:  # get raised when running checksecure on localhost
    pass

CACHE_TIMEOUT = 61  # seconds

########## END CACHING CONFIGURATION

########## STORAGE CONFIGURATION
BUCKET_KEY = "udon-media-usa"
########## END STORAGE CONFIGURATION

########## DJANGO SECURE CONFIGURATION
SESSION_COOKIE_SECURE = True
SECURE_HSTS_SECONDS = 2592000  # 30 days
SECURE_HSTS_INCLUDE_SUBDOMAINS = True
Example #12
0
 def testGetCurrentVersionName_VersionIdContainsNone(self):
   """Test get_current_version_name when 'None' is in version id."""
   os.environ['CURRENT_MODULE_ID'] = 'module1'
   os.environ['CURRENT_VERSION_ID'] = 'None.123'
   self.assertEqual(None, modules.get_current_version_name())
Example #13
0
 def testGetCurrentVersionName_NonDefaultModule(self):
   """Test get_current_version_name for a non default engine."""
   os.environ['CURRENT_MODULE_ID'] = 'module1'
   os.environ['CURRENT_VERSION_ID'] = 'v1.123'
   self.assertEqual('v1', modules.get_current_version_name())
Example #14
0
 def get_auth_success(self):
     app_ver = modules.get_current_version_name()
     self.render("documentation.html", app_ver=app_ver)
Example #15
0
 * 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.
"""
from .base import *

from djangae.utils import find_project_root
from google.appengine.api.modules.modules import get_current_version_name

ANALYTICS_KEY = 'UA-74361602-1'

########## CACHING CONFIGURATION
from google.appengine.api.modules.modules import get_current_version_name

try:
    CACHES['default']['KEY_PREFIX'] = get_current_version_name()
except KeyError:  # get raised when running checksecure on localhost
    pass

CACHE_TIMEOUT = 61  # seconds

########## END CACHING CONFIGURATION

########## STORAGE CONFIGURATION
BUCKET_KEY = 'udon-media-usa'
########## END STORAGE CONFIGURATION

########## DJANGO SECURE CONFIGURATION
SESSION_COOKIE_SECURE = True
SECURE_HSTS_SECONDS = 2592000  # 30 days
SECURE_HSTS_INCLUDE_SUBDOMAINS = True
Example #16
0
# add all egg files to sys.path
# use egg files instead of plain directory for beautiful directory structure and faster upload
lib_path = os.path.normpath(
    os.path.join(os.path.dirname(__file__), "..", "vendor"))
for zip_file in os.listdir(lib_path):
    sys.path.insert(0, os.path.join(lib_path, zip_file))

import flask

app = flask.Flask("application")

# Config from os.environ are all strings, but here only accepts integer.
app.config["PERMANENT_SESSION_LIFETIME"] = 31536000  # one year

current_version_name = modules.get_current_version_name()

# import all configs from app.yaml
os_names = (
    "SITE_NAME",
    "SESSION_COOKIE_PATH",
    "CONSUMER_KEY",
    "CONSUMER_SECRET",
    "SECRET_KEY",
)
for name in os_names:
    name_with_version = name + "_V" + current_version_name
    if name_with_version not in os.environ:
        name_with_version = name
    logging.debug("load config %s from %s", name, name_with_version)
    app.config[name] = os.environ[name_with_version]