def render(self, path, values=None, status=200): """Write HTML response.""" if values is None: values = {} values['menu_items'] = _MENU_ITEMS values['is_oss_fuzz'] = utils.is_oss_fuzz() values['is_development'] = ( environment.is_running_on_app_engine_development()) values['is_logged_in'] = bool(helpers.get_user_email()) # Only track analytics for non-admin users. values['ga_tracking_id'] = ( local_config.GAEConfig().get('ga_tracking_id') if not auth.is_current_user_admin() else None) if values['is_logged_in']: values['switch_account_url'] = make_login_url(self.request.url) values['logout_url'] = make_logout_url(dest_url=self.request.url) template = _JINJA_ENVIRONMENT.get_template(path) self._add_security_response_headers() self.response.headers['Content-Type'] = 'text/html' self.response.out.write(template.render(values)) self.response.set_status(status)
def get(self, tag=None): """Handle a get request.""" tag = 'google.' + tag + '.html' verification_tag = local_config.GAEConfig().get('domain_verification_tag') if verification_tag != tag: raise helpers.EarlyExitException('Not found.', 404) return 'google-site-verification: ' + verification_tag
def start_cloud_emulator(emulator, args=None, data_dir=None, store_on_disk=False): """Start a cloud emulator.""" ready_indicators = { 'datastore': b'is now running', 'pubsub': b'Server started', } store_on_disk_flag = ('--store-on-disk' if store_on_disk else '--no-store-on-disk') default_flags = { 'datastore': [store_on_disk_flag, '--consistency=1'], 'pubsub': [], } if emulator not in ready_indicators: raise RuntimeError('Unsupported emulator') if data_dir: cleanup_dir = None else: temp_dir = tempfile.mkdtemp() data_dir = temp_dir cleanup_dir = temp_dir port = _find_free_port() command = [ 'gcloud', 'beta', 'emulators', emulator, 'start', '--data-dir=' + data_dir, '--host-port=localhost:' + str(port), '--project=' + local_config.GAEConfig().get('application_id') ] if args: command.extend(args) command.extend(default_flags[emulator]) # Start emulator. proc = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) thread = wait_for_emulator_ready(proc, emulator, ready_indicators[emulator]) # Set env vars. env_vars = subprocess.check_output([ 'gcloud', 'beta', 'emulators', emulator, 'env-init', '--data-dir=' + data_dir ]) for line in env_vars.splitlines(): key, value = line.split()[1].split(b'=') os.environ[key.strip().decode('utf-8')] = value.strip().decode('utf-8') return EmulatorInstance(proc, port, thread, cleanup_dir)
def get(self, tag): """Handle a get request.""" verification_tag = local_config.GAEConfig().get( 'domain_verification_tag') if verification_tag != tag: raise helpers.EarlyExitException('Not found.', 404) self.response.headers['content-type'] = 'text/html' self.response.write('google-site-verification: ' + verification_tag)
def get(self): """Handle a GET request.""" # The task is supposed to be super reliable and never fail. If anything goes # wrong, we just fail with the exception going straight into StackDriver. logs.log('FuzzerCoverage task started.') config = local_config.GAEConfig() bucket = config.get('coverage.reports.bucket') collect_fuzzer_coverage(bucket) logs.log('FuzzerCoverage task finished successfully.')
def get_domain(): """Get current domain.""" default_domain = '{app_id}.appspot.com'.format( app_id=utils.get_application_id()) return local_config.GAEConfig().get('domains.main', default=default_domain)
('/testcase-detail/remove-issue', remove_issue.Handler), ('/testcase-detail/remove-group', remove_group.Handler), ('/testcase-detail/update-from-trunk', update_from_trunk.Handler), ('/testcase-detail/update-issue', update_issue.Handler), ('/testcases', testcase_list.Handler), ('/testcases/load', testcase_list.JsonHandler), ('/upload-testcase', upload_testcase.Handler), ('/upload-testcase/get-url-oauth', upload_testcase.UploadUrlHandlerOAuth), ('/upload-testcase/prepare', upload_testcase.PrepareUploadHandler), ('/upload-testcase/load', upload_testcase.JsonHandler), ('/upload-testcase/upload', upload_testcase.UploadHandler), ('/upload-testcase/upload-oauth', upload_testcase.UploadHandlerOAuth), ('/revisions', revisions_info.Handler), ('/report-bug', help_redirector.ReportBugHandler), ('/viewer', viewer.Handler), ] config = local_config.GAEConfig() main_domain = config.get('domains.main') redirect_domains = config.get('domains.redirects') _DOMAIN_ROUTES = [] if main_domain and redirect_domains: for redirect_domain in redirect_domains: _DOMAIN_ROUTES.append( routes.DomainRoute(redirect_domain, [ webapp2.Route('<:.*>', redirect_to(main_domain)), ])) app = webapp2.WSGIApplication(_CRON_ROUTES + _DOMAIN_ROUTES + _ROUTES, debug=True)
def start_cloud_emulator(emulator, args=None, data_dir=None): """Start a cloud emulator.""" ready_indicators = { 'datastore': 'is now running', 'pubsub': 'Server started', } default_flags = { 'datastore': ['--no-store-on-disk', '--consistency=1'], 'pubsub': [], } if emulator not in ready_indicators: raise RuntimeError('Unsupported emulator') if data_dir: cleanup_dir = None else: temp_dir = tempfile.mkdtemp() data_dir = temp_dir cleanup_dir = temp_dir port = _find_free_port() command = [ 'gcloud', 'beta', 'emulators', emulator, 'start', '--data-dir=' + data_dir, '--host-port=localhost:' + str(port), '--project=' + local_config.GAEConfig().get('application_id') ] if args: command.extend(args) command.extend(default_flags[emulator]) # Start emulator. proc = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) def _read_thread(proc, ready_event): """Thread to continuously read from the process stdout.""" ready = False while True: line = proc.stdout.readline() if not line: break if not ready and ready_indicators[emulator] in line: ready = True ready_event.set() # Wait for process to become ready. ready_event = threading.Event() thread = threading.Thread(target=_read_thread, args=(proc, ready_event)) thread.daemon = True thread.start() if not ready_event.wait(EMULATOR_TIMEOUT): raise RuntimeError( '{} emulator did not get ready in time.'.format(emulator)) # Set env vars. env_vars = subprocess.check_output([ 'gcloud', 'beta', 'emulators', emulator, 'env-init', '--data-dir=' + data_dir ]) for line in env_vars.splitlines(): key, value = line.split()[1].split('=') os.environ[key.strip()] = value.strip() return EmulatorInstance(proc, port, thread, cleanup_dir)