当前位置: 首页>>代码示例>>Python>>正文


Python app_identity.get_default_version_hostname方法代码示例

本文整理汇总了Python中google.appengine.api.app_identity.get_default_version_hostname方法的典型用法代码示例。如果您正苦于以下问题:Python app_identity.get_default_version_hostname方法的具体用法?Python app_identity.get_default_version_hostname怎么用?Python app_identity.get_default_version_hostname使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在google.appengine.api.app_identity的用法示例。


在下文中一共展示了app_identity.get_default_version_hostname方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: create_invocation_async

# 需要导入模块: from google.appengine.api import app_identity [as 别名]
# 或者: from google.appengine.api.app_identity import get_default_version_hostname [as 别名]
def create_invocation_async(task_run_id, realm):
  """This is wrapper for CreateInvocation API.

  Returns:
    update-token for created invocation.
  """
  hostname = app_identity.get_default_version_hostname()
  response_headers = {}

  yield _call_resultdb_recorder_api_async(
      'CreateInvocation', {
          'requestId': str(uuid.uuid4()),
          'invocationId': _get_invocation_id(task_run_id),
          'invocation': {
              'producerResource': '//%s/tasks/%s' % (hostname, task_run_id),
              'realm': realm,
          }
      },
      project_id=realm.split(':')[0],
      response_headers=response_headers)
  update_token = response_headers.get('update-token')
  assert update_token, ("response_headers should have valid update-token: %s" %
                        response_headers)
  raise ndb.Return(update_token) 
开发者ID:luci,项目名称:luci-py,代码行数:26,代码来源:resultdb.py

示例2: get_versioned_hosturl

# 需要导入模块: from google.appengine.api import app_identity [as 别名]
# 或者: from google.appengine.api.app_identity import get_default_version_hostname [as 别名]
def get_versioned_hosturl():
  """Returns the url hostname of this instance locked to the currently running
  version.

  This function hides the fact that app_identity.get_default_version_hostname()
  returns None on the dev server and modules.get_hostname() returns incorrectly
  qualified hostname for HTTPS usage on the prod server. <3
  """
  if is_local_dev_server():
    # TODO(maruel): It'd be nice if it were easier to use a ephemeral SSL
    # certificate here and not assume unsecured connection.
    return 'http://' + modules.get_hostname()

  return 'https://%s-dot-%s' % (
      get_app_version(), app_identity.get_default_version_hostname()) 
开发者ID:luci,项目名称:luci-py,代码行数:17,代码来源:utils.py

示例3: get_urlfetch_service_id

# 需要导入模块: from google.appengine.api import app_identity [as 别名]
# 或者: from google.appengine.api.app_identity import get_default_version_hostname [as 别名]
def get_urlfetch_service_id():
  """Returns a value for X-URLFetch-Service-Id header for GAE <-> GAE calls.

  Usually it can be omitted. It is required in certain environments.
  """
  if is_local_dev_server():
    return 'LOCAL'
  hostname = app_identity.get_default_version_hostname().split('.')
  return hostname[-2].upper() if len(hostname) >= 3 else 'APPSPOT' 
开发者ID:luci,项目名称:luci-py,代码行数:11,代码来源:utils.py

示例4: _allowed_audience_re

# 需要导入模块: from google.appengine.api import app_identity [as 别名]
# 或者: from google.appengine.api.app_identity import get_default_version_hostname [as 别名]
def _allowed_audience_re():
  """Returns a regular expression for allowed 'aud' field."""
  return _audience_re(app_identity.get_default_version_hostname())


# Extracted into a separate function for simpler testing. 
开发者ID:luci,项目名称:luci-py,代码行数:8,代码来源:gce_vm_auth.py

示例5: post

# 需要导入模块: from google.appengine.api import app_identity [as 别名]
# 或者: from google.appengine.api.app_identity import get_default_version_hostname [as 别名]
def post(self):
    res = self._process()
    event = res.request.get('event')
    if event not in self.ALLOWED_EVENTS:
      logging.error('Unexpected event type')
      self.abort_with_error(400, error='Unsupported event type')
    message = res.request.get('message')
    # Record the event in a BotEvent entity so it can be listed on the bot's
    # page. The dimensions won't be applied to BotInfo since they may not be
    # valid, but will be applied to BotEvent for analysis purpose.
    bot_management.bot_event(
        event_type=event,
        bot_id=res.bot_id,
        external_ip=self.request.remote_addr,
        authenticated_as=auth.get_peer_identity().to_bytes(),
        dimensions=res.dimensions,
        state=res.state,
        version=res.version,
        quarantined=bool(res.quarantined_msg),
        maintenance_msg=res.maintenance_msg,
        task_id=None,
        task_name=None,
        message=message,
        register_dimensions=False)

    if event == 'bot_error':
      # Also logs this to ereporter2, so it will be listed in the server's
      # hourly ereporter2 report. THIS IS NOISY so it should only be done with
      # issues requiring action. In this case, include again the bot's URL since
      # there's no context in the report. Redundantly include the bot id so
      # messages are bucketted by bot.
      line = ('%s\n'
              '\nhttps://%s/restricted/bot/%s') % (
                  message, app_identity.get_default_version_hostname(),
                  res.bot_id)
      ereporter2.log_request(self.request, source='bot', message=line)
    self.send_response({})


### Bot Security API RPC handlers 
开发者ID:luci,项目名称:luci-py,代码行数:42,代码来源:handlers_bot.py

示例6: bootstrap_templates

# 需要导入模块: from google.appengine.api import app_identity [as 别名]
# 或者: from google.appengine.api.app_identity import get_default_version_hostname [as 别名]
def bootstrap_templates():
  TEMPLATES_DIR = os.path.join(
    os.path.dirname(os.path.abspath(__file__)), 'templates')
  template.bootstrap(
      {'templates': TEMPLATES_DIR},
      global_env={
        'hostname': app_identity.get_default_version_hostname()
      }) 
开发者ID:luci,项目名称:luci-py,代码行数:10,代码来源:main.py

示例7: default

# 需要导入模块: from google.appengine.api import app_identity [as 别名]
# 或者: from google.appengine.api.app_identity import get_default_version_hostname [as 别名]
def default(self, obj):
        if isinstance(obj, ndb.Model):
            obj_dict = obj.to_dict()

            # Each BlobKeyProperty is represented as a dict of upload_url/download_url
            for (name, prop) in obj._properties.iteritems():
                if isinstance(prop, ndb.BlobKeyProperty):
                    server_host = app_identity.get_default_version_hostname()
                    blob_property_url = 'http://%s%s/%s/%s' % (server_host, obj.RESTMeta.base_url, self._decode_key(obj.key), name) # e.g. /api/my_model/<SOME_KEY>/blob_prop
                    obj_dict[name] = {
                            'upload_url': blob_property_url,
                            'download_url': blob_property_url if getattr(obj, name) else None # Display as null if the blob property is not set
                            }



            # Filter the properties that will be returned to user
            included_properties = get_included_properties(obj, 'output')
            obj_dict = dict((k,v) for k,v in obj_dict.iteritems() if k in included_properties)
            # Translate the property names
            obj_dict = translate_property_names(obj_dict, obj, 'output')
            obj_dict['id'] = self._decode_key(obj.key)

            return obj_dict

        elif isinstance(obj, datetime) or isinstance(obj, date) or isinstance(obj, time):
            return obj.isoformat()

        elif isinstance(obj, ndb.Key):
            return self._decode_key(obj)

        elif isinstance(obj, ndb.GeoPt):
            return str(obj)

        else:
            return json.JSONEncoder.default(self, obj) 
开发者ID:budowski,项目名称:rest_gae,代码行数:38,代码来源:rest_gae.py

示例8: test_get_default_version_hostname

# 需要导入模块: from google.appengine.api import app_identity [as 别名]
# 或者: from google.appengine.api.app_identity import get_default_version_hostname [as 别名]
def test_get_default_version_hostname():
    app_id = app_identity.get_application_id()
    hostname = app_identity.get_default_version_hostname()
    assert hostname
    assert app_id in hostname 
开发者ID:GoogleCloudPlatform,项目名称:python-compat-runtime,代码行数:7,代码来源:app_identity_test.py

示例9: test_get_default_gcs_bucket_name

# 需要导入模块: from google.appengine.api import app_identity [as 别名]
# 或者: from google.appengine.api.app_identity import get_default_version_hostname [as 别名]
def test_get_default_gcs_bucket_name():
    assert app_identity.get_default_version_hostname() 
开发者ID:GoogleCloudPlatform,项目名称:python-compat-runtime,代码行数:4,代码来源:app_identity_test.py

示例10: __target_from_host

# 需要导入模块: from google.appengine.api import app_identity [as 别名]
# 或者: from google.appengine.api.app_identity import get_default_version_hostname [as 别名]
def __target_from_host(host):
    """Calculate the value of the target parameter from a host header.

    Args:
      host: A string representing the hostname for this task.

    Returns:
      A string containing the target of this task, or the constant
      `DEFAULT_APP_VERSION` if it is the default version.

      If this code is running in a unit-test where the environment variable
      `DEFAULT_VERSION_HOSTNAME` is not set then the constant
      `_UNKNOWN_APP_VERSION` is returned.
    """
    default_hostname = app_identity.get_default_version_hostname()
    if default_hostname is None:



      return _UNKNOWN_APP_VERSION

    if host.endswith(default_hostname):

      version_name = host[:-(len(default_hostname) + 1)]
      if version_name:
        return version_name





    return DEFAULT_APP_VERSION 
开发者ID:GoogleCloudPlatform,项目名称:python-compat-runtime,代码行数:34,代码来源:taskqueue.py

示例11: __host_from_target

# 需要导入模块: from google.appengine.api import app_identity [as 别名]
# 或者: from google.appengine.api.app_identity import get_default_version_hostname [as 别名]
def __host_from_target(target):
    """Calculate the value of the host header from a target.

    Args:
      target: A string representing the target hostname or the constant
          `DEFAULT_APP_VERSION`.

    Returns:
      The string to be used as the host header, or None if it can not be
      determined.
    """
    default_hostname = app_identity.get_default_version_hostname()
    if default_hostname is None:



      return None

    server_software = os.environ.get('SERVER_SOFTWARE', '')
    if target is DEFAULT_APP_VERSION:
      return default_hostname
    elif server_software.startswith(
        'Dev') and server_software != 'Development/1.0 (testbed)':

      target_components = target.rsplit('.', 3)
      module = target_components[-1]
      version = len(target_components) > 1 and target_components[-2] or None
      instance = len(target_components) > 2 and target_components[-3] or None
      try:
        return modules.get_hostname(module=module, version=version,
                                    instance=instance)
      except modules.InvalidModuleError, e:


        if not version:
          return modules.get_hostname(module='default', version=module,
                                      instance=instance)
        else:
          raise e 
开发者ID:GoogleCloudPlatform,项目名称:python-compat-runtime,代码行数:41,代码来源:taskqueue.py

示例12: CurrentEnvironment

# 需要导入模块: from google.appengine.api import app_identity [as 别名]
# 或者: from google.appengine.api.app_identity import get_default_version_hostname [as 别名]
def CurrentEnvironment():
  """Returns the current environment the app is running in.

  Returns:
    The DefaultEnv subclass associated with the current environment.

  Raises:
    UnknownEnvironmentError: if the environment cannot be determined.
  """
  logging.info('Attempting to determine current environment')

  # Check the DEFAULT_VERSION_HOSTNAME first.
  logging.info('Checking DEFAULT_VERSION_HOSTNAME')
  if 'DEFAULT_VERSION_HOSTNAME' in os.environ:
    hostname = app_identity.get_default_version_hostname()
    logging.info('DEFAULT_VERSION_HOSTNAME is %s', hostname)
    for env in _ALL_ENVS:
      if env.HOSTNAME == hostname:
        return env
  else:
    logging.info('DEFAULT_VERSION_HOSTNAME not present')

  # Fall back to APPLICATION_ID.
  logging.info('Checking APPLICATION_ID')
  if 'APPLICATION_ID' in os.environ:
    app_id = app_identity.get_application_id()
    logging.info('APPLICATION_ID is %s', app_id)
    for env in _ALL_ENVS:
      if env.PROJECT_ID == app_id:
        return env
  else:
    logging.info('APPLICATION_ID not present')

  # Well shit...
  logging.warning('Unable to determine the current environment')
  raise UnknownEnvironmentError 
开发者ID:google,项目名称:upvote,代码行数:38,代码来源:env_utils.py

示例13: log

# 需要导入模块: from google.appengine.api import app_identity [as 别名]
# 或者: from google.appengine.api.app_identity import get_default_version_hostname [as 别名]
def log(**kwargs):
  """Adds an error. This will indirectly notify the admins.

  Returns the entity id for the report.
  """
  identity = None
  if not auth.get_current_identity().is_anonymous:
    identity = auth.get_current_identity().to_bytes()
  try:
    # Trim all the messages to 4kb to reduce spam.
    LIMIT = 4096
    for key, value in kwargs.items():
      if key not in VALID_ERROR_KEYS:
        logging.error('Dropping unknown detail %s: %s', key, value)
        kwargs.pop(key)
      elif isinstance(value, basestring) and len(value) > LIMIT:
        value = value[:LIMIT-1] + u'\u2026'
        kwargs[key] = value

    if kwargs.get('source') == 'server':
      # Automatically use the version of the server code.
      kwargs.setdefault('version', utils.get_app_version())
      kwargs.setdefault('python_version', platform.python_version())

    error = models.Error(identity=identity, **kwargs)
    error.put()
    key_id = error.key.integer_id()
    # The format of the message is important here. The first line is used to
    # generate a signature, so it must be unique for each category of errors.
    logging.error(
        '%s\n%s\n\nSource: %s\nhttps://%s/restricted/ereporter2/errors/%s',
        error.message, error.stack, error.source,
        app_identity.get_default_version_hostname(), key_id)
    return key_id
  except (datastore_errors.BadValueError, TypeError) as e:
    stack = formatter._reformat_stack(traceback.format_exc())
    # That's the error about the error.
    error = models.Error(
        source='server',
        category='exception',
        message='log(%s) caused: %s' % (kwargs, str(e)),
        exception_type=str(type(e)),
        stack=stack)
    error.put()
    key_id = error.key.integer_id()
    logging.error(
        'Failed to log a %s error\n%s\n%s', error.source, key_id, error.message)
    return key_id 
开发者ID:luci,项目名称:luci-py,代码行数:50,代码来源:on_error.py

示例14: get_hostname

# 需要导入模块: from google.appengine.api import app_identity [as 别名]
# 或者: from google.appengine.api.app_identity import get_default_version_hostname [as 别名]
def get_hostname(backend=None, instance=None):
  """DEPRECATED: Returns the hostname for a backend or backend instance.

  Warning: This API is deprecated and will be removed in a future
  release. Please migrate to the Modules API as soon as possible.

  Args:
    backend: The name of the backend. If None, the current backend will be used.

    instance: An optoinal instance number. If provided, the hostname will
      represent the specific instance. If absent, the hostname will represent
      the backend as a whole.

  Raises:
    InvalidBackendError
    InvalidInstanceError

  Returns:
    The hostname of the backend or backend instance.
  """
  if backend is None:
    backend = get_backend()


  if not isinstance(backend, (str, unicode)):
    raise InvalidBackendError('Invalid backend: %s' % backend)

  if not re.match('^[a-zA-Z0-9\-]+$', backend):
    raise InvalidBackendError('Invalid backend: %s' % backend)


  if instance is not None:
    try:
      instance = int(instance)
    except ValueError:
      raise InvalidInstanceError('instance must be an integer.')


  if _is_dev2_environment():
    return _get_dev2_hostname(backend, instance)
  elif _is_dev_environment():
    return _get_dev_hostname(backend, instance)

  hostname = app_identity.get_default_version_hostname()
  if hostname is None:
    raise DefaultHostnameError

  hostname = '%s.%s' % (backend, hostname)
  if instance is not None:
    hostname = '%d.%s' % (instance, hostname)
  return hostname 
开发者ID:GoogleCloudPlatform,项目名称:python-compat-runtime,代码行数:53,代码来源:backends.py


注:本文中的google.appengine.api.app_identity.get_default_version_hostname方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。