def ReportError(err, is_crash): """Report the anonymous crash information to the Error Reporting service. Args: err: Exception, the error that caused the crash. is_crash: bool, True if this is a crash, False if it is a user error. """ if properties.VALUES.core.disable_usage_reporting.GetBool(): return stacktrace = traceback.format_exc(err) stacktrace = error_reporting_util.RemovePrivateInformationFromTraceback( stacktrace) command = properties.VALUES.metrics.command_name.Get() cid = metrics.GetCIDIfMetricsEnabled() client = _GetReportingClient(is_crash) reporter = util.ErrorReporting(client) try: method_config = client.projects_events.GetMethodConfig('Report') request = reporter.GenerateReportRequest( error_message=stacktrace, service=SERVICE, version=config.CLOUD_SDK_VERSION, project=CRASH_PROJECT if is_crash else ERROR_PROJECT, request_url=command, user=cid) http_request = client.projects_events.PrepareHttpRequest( method_config, request) metrics.CustomBeacon(http_request.url, http_request.http_method, http_request.body, http_request.headers) except apitools_exceptions.Error as e: log.file_only_logger.error( 'Unable to report crash stacktrace:\n{0}'.format( console_attr.SafeText(e)))
def main(): """Launches dev_appserver.py.""" runtimes = wrapper_util.GetRuntimes(sys.argv[1:]) components = wrapper_util.GetComponents(runtimes) options = wrapper_util.ParseDevAppserverFlags(sys.argv[1:]) if options.support_datastore_emulator: components.append('cloud-datastore-emulator') update_manager.UpdateManager.EnsureInstalledAndRestart(components, command=__file__) args = ['--skip_sdk_update_check=True'] google_analytics_client_id = metrics.GetCIDIfMetricsEnabled() google_analytics_user_agent = metrics.GetUserAgentIfMetricsEnabled() if google_analytics_client_id: args.extend([ '--google_analytics_client_id={}'.format( google_analytics_client_id), '--google_analytics_user_agent={}'.format( google_analytics_user_agent) ]) # Pass the path to cloud datastore emulator to dev_appserver. sdk_root = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) emulator_dir = os.path.join(sdk_root, 'platform', 'cloud-datastore-emulator') emulator_script = ('cloud_datastore_emulator.cmd' if platforms.OperatingSystem.IsWindows() else 'cloud_datastore_emulator') args.append('--datastore_emulator_cmd={}'.format( os.path.join(emulator_dir, emulator_script))) bootstrapping.ExecutePythonTool( os.path.join('platform', 'google_appengine'), 'dev_appserver.py', *args)
def _ReportCrash(err): """Report the anonymous crash information to the Error Reporting service. Args: err: Exception, the error that caused the crash. """ stacktrace = traceback.format_exc(err) stacktrace = error_reporting_util.RemovePrivateInformationFromTraceback( stacktrace) command = properties.VALUES.metrics.command_name.Get() cid = metrics.GetCIDIfMetricsEnabled() client = _GetReportingClient() reporter = util.ErrorReporting(client) try: reporter.ReportEvent(error_message=stacktrace, service=CRASH_SERVICE, version=config.CLOUD_SDK_VERSION, project=CRASH_PROJECT, request_url=command, user=cid) except apitools_exceptions.HttpError as http_err: log.file_only_logger.error( 'Unable to report crash stacktrace:\n{0}'.format( console_attr.EncodeForConsole(http_err)))
def main(): """Launches dev_appserver.py.""" runtimes = wrapper_util.GetRuntimes(sys.argv[1:]) components = wrapper_util.GetComponents(runtimes) options = wrapper_util.ParseDevAppserverFlags(sys.argv[1:]) if options.support_datastore_emulator: components.append('cloud-datastore-emulator') update_manager.UpdateManager.EnsureInstalledAndRestart( components, command=__file__) args = [ '--skip_sdk_update_check=True' ] google_analytics_client_id = metrics.GetCIDIfMetricsEnabled() google_analytics_user_agent = metrics.GetUserAgentIfMetricsEnabled() if google_analytics_client_id: args.extend([ '--google_analytics_client_id={}'.format(google_analytics_client_id), '--google_analytics_user_agent={}'.format(google_analytics_user_agent) ]) bootstrapping.ExecutePythonTool( os.path.join('platform', 'google_appengine'), 'dev_appserver.py', *args)
def main(): """Launches gsutil.""" project, account = bootstrapping.GetActiveProjectAndAccount() pass_credentials = ( properties.VALUES.core.pass_credentials_to_gsutil.GetBool() and not properties.VALUES.auth.disable_credentials.GetBool()) if pass_credentials and account not in c_gce.Metadata().Accounts(): gsutil_path = config.Paths().LegacyCredentialsGSUtilPath(account) # Allow gsutil to only check for the '1' string value, as is done # with regard to the 'CLOUDSDK_WRAPPER' environment variable. os.environ['CLOUDSDK_CORE_PASS_CREDENTIALS_TO_GSUTIL'] = '1' boto_config = os.environ.get('BOTO_CONFIG', '') boto_path = os.environ.get('BOTO_PATH', '') # We construct a BOTO_PATH that tacks the refresh token config # on the end. if boto_config: boto_path = os.pathsep.join([boto_config, gsutil_path]) elif boto_path: boto_path = os.pathsep.join([boto_path, gsutil_path]) else: path_parts = [ '/etc/boto.cfg', os.path.expanduser(os.path.join('~', '.boto')), gsutil_path ] boto_path = os.pathsep.join(path_parts) if 'BOTO_CONFIG' in os.environ: del os.environ['BOTO_CONFIG'] os.environ['BOTO_PATH'] = boto_path # Tell gsutil whether gcloud analytics collection is enabled. os.environ['GA_CID'] = metrics.GetCIDIfMetricsEnabled() args = [] _MaybeAddBotoOption(args, 'GSUtil', 'default_project_id', project) if pass_credentials and account in c_gce.Metadata().Accounts(): # Tell gsutil to look for GCE service accounts. _MaybeAddBotoOption(args, 'GoogleCompute', 'service_account', 'default') proxy_params = properties.VALUES.proxy _MaybeAddBotoOption(args, 'Boto', 'proxy', proxy_params.address.Get()) _MaybeAddBotoOption(args, 'Boto', 'proxy_port', proxy_params.port.Get()) _MaybeAddBotoOption(args, 'Boto', 'proxy_user', proxy_params.username.Get()) _MaybeAddBotoOption(args, 'Boto', 'proxy_pass', proxy_params.password.Get()) disable_ssl = properties.VALUES.auth.disable_ssl_validation.GetBool() _MaybeAddBotoOption(args, 'Boto', 'https_validate_certificates', None if disable_ssl is None else not disable_ssl) _MaybeAddBotoOption(args, 'Boto', 'ca_certificates_file', properties.VALUES.core.custom_ca_certs_file.Get()) bootstrapping.ExecutePythonTool('platform/gsutil', 'gsutil', *args)
def main(): """Launches dev_appserver.py.""" runtimes = wrapper_util.GetRuntimes(sys.argv[1:]) components = wrapper_util.GetComponents(runtimes) update_manager.UpdateManager.EnsureInstalledAndRestart(components, command=__file__) args = [ '--skip_sdk_update_check=True', '--application={}'.format(properties.VALUES.core.project.Get()) ] google_analytics_client_id = metrics.GetCIDIfMetricsEnabled() google_analytics_user_agent = metrics.GetUserAgentIfMetricsEnabled() if google_analytics_client_id: args.extend([ '--google_analytics_client_id={}'.format( google_analytics_client_id), '--google_analytics_user_agent={}'.format( google_analytics_user_agent) ]) bootstrapping.ExecutePythonTool( os.path.join('platform', 'google_appengine'), 'dev_appserver.py', *args)
def main(): """Launches gsutil.""" project, account = bootstrapping.GetActiveProjectAndAccount() pass_credentials = properties.VALUES.core.pass_credentials_to_gsutil.GetBool( ) if pass_credentials and account not in c_gce.Metadata().Accounts(): gsutil_path = config.Paths().LegacyCredentialsGSUtilPath(account) boto_config = os.environ.get('BOTO_CONFIG', '') boto_path = os.environ.get('BOTO_PATH', '') # We construct a BOTO_PATH that tacks the refresh token config # on the end. if boto_config: boto_path = os.pathsep.join([boto_config, gsutil_path]) elif boto_path: boto_path = os.pathsep.join([boto_path, gsutil_path]) else: path_parts = [ '/etc/boto.cfg', os.path.expanduser(os.path.join('~', '.boto')), gsutil_path ] boto_path = os.pathsep.join(path_parts) if 'BOTO_CONFIG' in os.environ: del os.environ['BOTO_CONFIG'] os.environ['BOTO_PATH'] = boto_path # Tell gsutil whether gcloud analytics collection is enabled. os.environ['GA_CID'] = metrics.GetCIDIfMetricsEnabled() args = [] if project: args.extend(['-o', 'GSUtil:default_project_id=%s' % project]) if pass_credentials and account in c_gce.Metadata().Accounts(): # Tell gsutil to look for GCE service accounts. args.extend(['-o', 'GoogleCompute:service_account=default']) bootstrapping.ExecutePythonTool('platform/gsutil', 'gsutil', *args)
def main(): """Launches dev_appserver.py.""" argv = bootstrapping.GetDecodedArgv() runtimes = wrapper_util.GetRuntimes(argv[1:]) options = wrapper_util.ParseDevAppserverFlags(sys.argv[1:]) if options.support_datastore_emulator: java.RequireJavaInstalled(datastore_util.DATASTORE_TITLE, min_version=8) components = wrapper_util.GetComponents(runtimes) components.append('cloud-datastore-emulator') if (platforms.OperatingSystem.Current() == platforms.OperatingSystem.LINUX and 'app-engine-php' in components): components.remove('app-engine-php') update_manager.UpdateManager.EnsureInstalledAndRestart( components, command=__file__) args = [ '--skip_sdk_update_check=True' ] google_analytics_client_id = metrics.GetCIDIfMetricsEnabled() google_analytics_user_agent = metrics.GetUserAgentIfMetricsEnabled() if google_analytics_client_id: args.extend([ '--google_analytics_client_id={}'.format(google_analytics_client_id), '--google_analytics_user_agent={}'.format(google_analytics_user_agent) ]) # Pass the path to cloud datastore emulator to dev_appserver. # realpath is needed in the case where __file__ is a path containing symlinks. sdk_root = os.path.dirname( os.path.dirname(os.path.abspath(os.path.realpath(__file__)))) emulator_dir = os.path.join(sdk_root, 'platform', 'cloud-datastore-emulator') emulator_script = ( 'cloud_datastore_emulator.cmd' if platforms.OperatingSystem.IsWindows() else 'cloud_datastore_emulator') args.append('--datastore_emulator_cmd={}'.format( os.path.join(emulator_dir, emulator_script))) bootstrapping.ExecutePythonTool( os.path.join('platform', 'google_appengine'), 'dev_appserver.py', *args)
def main(): """Launches gsutil.""" args = [] project, account = bootstrapping.GetActiveProjectAndAccount() pass_credentials = ( properties.VALUES.core.pass_credentials_to_gsutil.GetBool() and not properties.VALUES.auth.disable_credentials.GetBool()) _MaybeAddBotoOption(args, 'GSUtil', 'default_project_id', project) if pass_credentials: # Allow gsutil to only check for the '1' string value, as is done # with regard to the 'CLOUDSDK_WRAPPER' environment variable. encoding.SetEncodedValue( os.environ, 'CLOUDSDK_CORE_PASS_CREDENTIALS_TO_GSUTIL', '1') if account in c_gce.Metadata().Accounts(): # Tell gsutil that it should obtain credentials from the GCE metadata # server for the instance's configured service account. _MaybeAddBotoOption(args, 'GoogleCompute', 'service_account', 'default') # For auth'n debugging purposes, allow gsutil to reason about whether the # configured service account was set in a boto file or passed from here. encoding.SetEncodedValue( os.environ, 'CLOUDSDK_PASSED_GCE_SERVICE_ACCOUNT_TO_GSUTIL', '1') else: legacy_config_path = config.Paths().LegacyCredentialsGSUtilPath(account) # We construct a BOTO_PATH that tacks the config containing our # credentials options onto the end of the list of config paths. We ensure # the other credential options are loaded first so that ours will take # precedence and overwrite them. boto_config = encoding.GetEncodedValue(os.environ, 'BOTO_CONFIG', '') boto_path = encoding.GetEncodedValue(os.environ, 'BOTO_PATH', '') if boto_config: boto_path = os.pathsep.join([boto_config, legacy_config_path]) elif boto_path: boto_path = os.pathsep.join([boto_path, legacy_config_path]) else: path_parts = ['/etc/boto.cfg', os.path.expanduser(os.path.join('~', '.boto')), legacy_config_path] boto_path = os.pathsep.join(path_parts) encoding.SetEncodedValue(os.environ, 'BOTO_CONFIG', None) encoding.SetEncodedValue(os.environ, 'BOTO_PATH', boto_path) # Tell gsutil whether gcloud analytics collection is enabled. encoding.SetEncodedValue( os.environ, 'GA_CID', metrics.GetCIDIfMetricsEnabled()) # Set proxy settings. Note that if these proxy settings are configured in a # boto config file, the options here will be loaded afterward, overriding # them. proxy_params = properties.VALUES.proxy proxy_address = proxy_params.address.Get() if proxy_address: _MaybeAddBotoOption(args, 'Boto', 'proxy', proxy_address) _MaybeAddBotoOption(args, 'Boto', 'proxy_port', proxy_params.port.Get()) _MaybeAddBotoOption(args, 'Boto', 'proxy_rdns', proxy_params.rdns.GetBool()) _MaybeAddBotoOption(args, 'Boto', 'proxy_user', proxy_params.username.Get()) _MaybeAddBotoOption(args, 'Boto', 'proxy_pass', proxy_params.password.Get()) # Set SSL-related settings. disable_ssl = properties.VALUES.auth.disable_ssl_validation.GetBool() _MaybeAddBotoOption(args, 'Boto', 'https_validate_certificates', None if disable_ssl is None else not disable_ssl) _MaybeAddBotoOption(args, 'Boto', 'ca_certificates_file', properties.VALUES.core.custom_ca_certs_file.Get()) # Note that the original args to gsutil will be appended after the args we've # supplied here. bootstrapping.ExecutePythonTool('platform/gsutil', 'gsutil', *args)