Python google.appengine.api.app_identity.get_application_id() Examples
The following are 30
code examples of google.appengine.api.app_identity.get_application_id().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
google.appengine.api.app_identity
, or try the search function
.
Example #1
Source File: app_engine.py From luci-py with Apache License 2.0 | 6 votes |
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()
Example #2
Source File: ui.py From luci-py with Apache License 2.0 | 6 votes |
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
Example #3
Source File: app_engine.py From luci-py with Apache License 2.0 | 6 votes |
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()
Example #4
Source File: handlers.py From luci-py with Apache License 2.0 | 6 votes |
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.')
Example #5
Source File: signature.py From luci-py with Apache License 2.0 | 6 votes |
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()), })
Example #6
Source File: ui.py From luci-py with Apache License 2.0 | 6 votes |
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
Example #7
Source File: signature.py From luci-py with Apache License 2.0 | 6 votes |
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()), })
Example #8
Source File: handlers.py From luci-py with Apache License 2.0 | 6 votes |
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.')
Example #9
Source File: app_engine.py From luci-py with Apache License 2.0 | 6 votes |
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()
Example #10
Source File: signature.py From luci-py with Apache License 2.0 | 6 votes |
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()), })
Example #11
Source File: signature.py From luci-py with Apache License 2.0 | 6 votes |
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()), })
Example #12
Source File: user_signup.py From python-docs-samples with Apache License 2.0 | 6 votes |
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))
Example #13
Source File: handlers.py From luci-py with Apache License 2.0 | 6 votes |
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.')
Example #14
Source File: main.py From python-docs-samples with Apache License 2.0 | 6 votes |
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))
Example #15
Source File: ui.py From luci-py with Apache License 2.0 | 6 votes |
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
Example #16
Source File: app_engine.py From luci-py with Apache License 2.0 | 6 votes |
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()
Example #17
Source File: ui.py From luci-py with Apache License 2.0 | 6 votes |
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
Example #18
Source File: ui.py From luci-py with Apache License 2.0 | 6 votes |
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
Example #19
Source File: handlers.py From luci-py with Apache License 2.0 | 6 votes |
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.')
Example #20
Source File: errorhandling.py From MyLife with MIT License | 6 votes |
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)
Example #21
Source File: signature.py From luci-py with Apache License 2.0 | 6 votes |
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()), })
Example #22
Source File: app_engine.py From aws-kube-codesuite with Apache License 2.0 | 6 votes |
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()
Example #23
Source File: env_utils.py From upvote with Apache License 2.0 | 5 votes |
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
Example #24
Source File: app_identity_test.py From python-compat-runtime with Apache License 2.0 | 5 votes |
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
Example #25
Source File: shared.py From cloud-playground with Apache License 2.0 | 5 votes |
def ThisIsPlaygroundApp(): """Determines whether this is the playground app id.""" if common.IsDevMode(): return not backends.get_backend() return app_identity.get_application_id() == appids.PLAYGROUND_APP_ID
Example #26
Source File: model.py From luci-py with Apache License 2.0 | 5 votes |
def bots_ip_whitelist(): """Returns a name of a special IP whitelist that controls IP-based auth. Requests without authentication headers coming from IPs in this whitelist are authenticated as coming from IP_WHITELISTED_BOT_ID ('bot:whitelisted-ip'). DEPRECATED. """ return '%s-bots' % app_identity.get_application_id()
Example #27
Source File: model.py From luci-py with Apache License 2.0 | 5 votes |
def get_service_self_identity(): """Returns Identity that correspond to the current GAE app itself.""" return Identity(IDENTITY_SERVICE, app_identity.get_application_id())
Example #28
Source File: storage.py From luci-py with Apache License 2.0 | 5 votes |
def get_self_config_set(): return 'services/%s' % app_identity.get_application_id()
Example #29
Source File: common.py From luci-py with Apache License 2.0 | 5 votes |
def self_config_set(): return 'services/%s' % _trim_app_id(app_identity.get_application_id())
Example #30
Source File: utils.py From personfinder with Apache License 2.0 | 5 votes |
def get_app_name(): """Canonical name of the app, without HR s~ nonsense. This only works in the context of the appserver (eg remote_api can't use it).""" from google.appengine.api import app_identity return app_identity.get_application_id()