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


Python app_identity.get_application_id方法代码示例

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


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

示例1: log_error

# 需要导入模块: from google.appengine.api import app_identity [as 别名]
# 或者: from google.appengine.api.app_identity import get_application_id [as 别名]
def log_error(subject, message, *args):
	if args:
		try:
			message = message % args
		except:
			pass

	logging.error(subject + ' : ' + message)

	subject = 'MyLife Error: ' + subject
	app_id = app_identity.get_application_id()
	sender = "MyLife Errors <errors@%s.appspotmail.com>" % app_id
	try:
		to = Settings.get().email_address
		mail.check_email_valid(to, 'To')
		mail.send_mail(sender, to, subject, message)
	except:
		mail.send_mail_to_admins(sender, subject, message) 
开发者ID:einaregilsson,项目名称:MyLife,代码行数:20,代码来源:errorhandling.py

示例2: get

# 需要导入模块: from google.appengine.api import app_identity [as 别名]
# 或者: from google.appengine.api.app_identity import get_application_id [as 别名]
def get(self):
        auth_token, _ = app_identity.get_access_token(
            'https://www.googleapis.com/auth/cloud-platform')
        logging.info(
            'Using token {} to represent identity {}'.format(
                auth_token, app_identity.get_service_account_name()))

        response = urlfetch.fetch(
            'https://www.googleapis.com/storage/v1/b?project={}'.format(
                app_identity.get_application_id()),
            method=urlfetch.GET,
            headers={
                'Authorization': 'Bearer {}'.format(auth_token)
            }
        )

        if response.status_code != 200:
            raise Exception(
                'Call failed. Status code {}. Body {}'.format(
                    response.status_code, response.content))

        result = json.loads(response.content)
        self.response.headers['Content-Type'] = 'application/json'
        self.response.write(json.dumps(result, indent=2)) 
开发者ID:GoogleCloudPlatform,项目名称:python-docs-samples,代码行数:26,代码来源:main.py

示例3: post

# 需要导入模块: from google.appengine.api import app_identity [as 别名]
# 或者: from google.appengine.api.app_identity import get_application_id [as 别名]
def post(self):
        user_address = self.request.get('email_address')

        if not mail.is_email_valid(user_address):
            self.get()  # Show the form again.
        else:
            confirmation_url = create_new_user_confirmation(user_address)
            sender_address = (
                'Example.com Support <example@{}.appspotmail.com>'.format(
                    app_identity.get_application_id()))
            subject = 'Confirm your registration'
            body = """Thank you for creating an account!
Please confirm your email address by clicking on the link below:

{}
""".format(confirmation_url)
            mail.send_mail(sender_address, user_address, subject, body)
# [END send-confirm-email]
            self.response.content_type = 'text/plain'
            self.response.write('An email has been sent to {}.'.format(
                user_address)) 
开发者ID:GoogleCloudPlatform,项目名称:python-docs-samples,代码行数:23,代码来源:user_signup.py

示例4: get_project_id

# 需要导入模块: from google.appengine.api import app_identity [as 别名]
# 或者: from google.appengine.api.app_identity import get_application_id [as 别名]
def get_project_id():
    """Gets the project ID for the current App Engine application.

    Returns:
        str: The project ID

    Raises:
        EnvironmentError: If the App Engine APIs are unavailable.
    """
    # pylint: disable=missing-raises-doc
    # Pylint rightfully thinks EnvironmentError is OSError, but doesn't
    # realize it's a valid alias.
    if app_identity is None:
        raise EnvironmentError(
            'The App Engine APIs are not available.')
    return app_identity.get_application_id() 
开发者ID:fniephaus,项目名称:alfred-gmail,代码行数:18,代码来源:app_engine.py

示例5: _get_settings_with_defaults

# 需要导入模块: from google.appengine.api import app_identity [as 别名]
# 或者: from google.appengine.api.app_identity import get_application_id [as 别名]
def _get_settings_with_defaults():
  """Returns (rev, cfg) where cfg is a parsed SettingsCfg message.

  If config does not exists, returns (None, <cfg with defaults>).

  The config is cached in the datastore.
  """
  rev, cfg = _get_settings()
  cfg = cfg or config_pb2.SettingsCfg()
  cfg.default_expiration = cfg.default_expiration or 30*24*60*60
  cfg.sharding_letters = cfg.sharding_letters or 4
  cfg.gs_bucket = cfg.gs_bucket or app_identity.get_application_id()
  cfg.auth.full_access_group = cfg.auth.full_access_group or 'administrators'
  cfg.auth.readonly_access_group = \
      cfg.auth.readonly_access_group or 'administrators'
  return rev, cfg 
开发者ID:luci,项目名称:luci-py,代码行数:18,代码来源:config.py

示例6: get_own_public_certificates

# 需要导入模块: from google.appengine.api import app_identity [as 别名]
# 或者: from google.appengine.api.app_identity import get_application_id [as 别名]
def get_own_public_certificates():
  """Returns CertificateBundle with certificates of the current service."""
  attempt = 0
  while True:
    attempt += 1
    try:
      certs = app_identity.get_public_certificates(deadline=1.5)
      break
    except apiproxy_errors.DeadlineExceededError as e:
      logging.warning('%s', e)
      if attempt == 3:
        raise
  return CertificateBundle({
    'app_id': app_identity.get_application_id(),
    'service_account_name': utils.get_service_account_name(),
    'certificates': [
      {
        'key_name': cert.key_name,
        'x509_certificate_pem': cert.x509_certificate_pem,
      }
      for cert in certs
    ],
    'timestamp': utils.datetime_to_timestamp(utils.utcnow()),
  }) 
开发者ID:luci,项目名称:luci-py,代码行数:26,代码来源:signature.py

示例7: _email_html

# 需要导入模块: from google.appengine.api import app_identity [as 别名]
# 或者: from google.appengine.api.app_identity import get_application_id [as 别名]
def _email_html(to, subject, body):
  """Sends an email including a textual representation of the HTML body.

  The body must not contain <html> or <body> tags.
  """
  mail_args = {
    'body': saxutils.unescape(re.sub(r'<[^>]+>', r'', body)),
    'html': '<html><body>%s</body></html>' % body,
    'sender': 'no_reply@%s.appspotmail.com' % app_identity.get_application_id(),
    'subject': subject,
  }
  try:
    if to:
      mail_args['to'] = to
      mail.send_mail(**mail_args)
    else:
      mail.send_mail_to_admins(**mail_args)
    return True
  except mail_errors.BadRequestError:
    return False 
开发者ID:luci,项目名称:luci-py,代码行数:22,代码来源:ui.py

示例8: get

# 需要导入模块: from google.appengine.api import app_identity [as 别名]
# 或者: from google.appengine.api.app_identity import get_application_id [as 别名]
def get(self):
    """Sends email(s) containing the errors logged."""
    # Do not use self.request.host_url because it will be http:// and will point
    # to the backend, with an host format that breaks the SSL certificate.
    # TODO(maruel): On the other hand, Google Apps instances are not hosted on
    # appspot.com.
    host_url = 'https://%s.appspot.com' % app_identity.get_application_id()
    request_id_url = host_url + '/restricted/ereporter2/request/'
    report_url = host_url + '/restricted/ereporter2/report'
    recipients = self.request.get('recipients', acl.get_ereporter2_recipients())
    result = ui._generate_and_email_report(
        utils.get_module_version_list(None, False),
        recipients,
        request_id_url,
        report_url,
        {})
    self.response.headers['Content-Type'] = 'text/plain; charset=utf-8'
    if result:
      self.response.write('Success.')
    else:
      # Do not HTTP 500 since we do not want it to be retried.
      self.response.write('Failed.') 
开发者ID:luci,项目名称:luci-py,代码行数:24,代码来源:handlers.py

示例9: get_project_id

# 需要导入模块: from google.appengine.api import app_identity [as 别名]
# 或者: from google.appengine.api.app_identity import get_application_id [as 别名]
def get_project_id():
    """
    Return the real or local project id.

    :return: project_id
    """
    if detect_gae():
        project = app_identity.get_application_id()
    else:
        project = _get_project_id()
    return project 
开发者ID:doitintl,项目名称:iris,代码行数:13,代码来源:utils.py

示例10: get_host_name

# 需要导入模块: from google.appengine.api import app_identity [as 别名]
# 或者: from google.appengine.api.app_identity import get_application_id [as 别名]
def get_host_name():
    """
    Return the real or local hostname.

    :return: hostname
    """
    if detect_gae():
        hostname = '{}.appspot.com'.format(app_identity.get_application_id())
    else:
        hostname = '{}.appspot.com'.format(_get_project_id())
    return hostname 
开发者ID:doitintl,项目名称:iris,代码行数:13,代码来源:utils.py

示例11: get_app_hostname

# 需要导入模块: from google.appengine.api import app_identity [as 别名]
# 或者: from google.appengine.api.app_identity import get_application_id [as 别名]
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

  app_id = app_identity.get_application_id()

  prefix = get_hostname_prefix()
  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

  return '{0}{1}.{2}'.format(prefix, api_name, suffix) 
开发者ID:cloudendpoints,项目名称:endpoints-python,代码行数:31,代码来源:util.py

示例12: get_project_id

# 需要导入模块: from google.appengine.api import app_identity [as 别名]
# 或者: from google.appengine.api.app_identity import get_application_id [as 别名]
def get_project_id():
        return os.getenv('BQ_STORAGE_PROJECT_ID',
                         app_identity.get_application_id()) 
开发者ID:ocadotechnology,项目名称:gcp-census,代码行数:5,代码来源:config.py

示例13: test_default

# 需要导入模块: from google.appengine.api import app_identity [as 别名]
# 或者: from google.appengine.api.app_identity import get_application_id [as 别名]
def test_default():
    credentials, project_id = google.auth.default()

    assert isinstance(credentials, app_engine.Credentials)
    assert project_id == app_identity.get_application_id() 
开发者ID:googleapis,项目名称:google-auth-library-python,代码行数:7,代码来源:main.py

示例14: get_project_id

# 需要导入模块: from google.appengine.api import app_identity [as 别名]
# 或者: from google.appengine.api.app_identity import get_application_id [as 别名]
def get_project_id():
    """Gets the project ID for the current App Engine application.

    Returns:
        str: The project ID

    Raises:
        EnvironmentError: If the App Engine APIs are unavailable.
    """
    # pylint: disable=missing-raises-doc
    # Pylint rightfully thinks EnvironmentError is OSError, but doesn't
    # realize it's a valid alias.
    if app_identity is None:
        raise EnvironmentError("The App Engine APIs are not available.")
    return app_identity.get_application_id() 
开发者ID:googleapis,项目名称:google-auth-library-python,代码行数:17,代码来源:app_engine.py


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