Beispiel #1
0
    def _HandleAllErrors(self, exc, command_path_string, specified_arg_names):
        """Handle all errors.

    Args:
      exc: Exception, The exception that was raised.
      command_path_string: str, The '.' separated command path.
      specified_arg_names: [str], The specified arg named scrubbed for metrics.

    Raises:
      exc or a core.exceptions variant that does not produce a stack trace.
    """
        if session_capturer.SessionCapturer.capturer:
            session_capturer.SessionCapturer.capturer.CaptureException(exc)
        error_extra_info = {'error_code': getattr(exc, 'exit_code', 1)}
        if isinstance(exc, exceptions.HttpException):
            error_extra_info['http_status_code'] = exc.payload.status_code

        metrics.Commands(command_path_string,
                         config.CLOUD_SDK_VERSION,
                         specified_arg_names,
                         error=exc.__class__,
                         error_extra_info=error_extra_info)
        metrics.Error(command_path_string,
                      exc.__class__,
                      specified_arg_names,
                      error_extra_info=error_extra_info)

        exceptions.HandleError(exc, command_path_string,
                               self.__known_error_handler)
Beispiel #2
0
    def _HandleAllErrors(self, exc, command_path_string, specified_arg_names):
        """Handle all errors.

    Args:
      exc: Exception, The exception that was raised.
      command_path_string: str, The '.' separated command path.
      specified_arg_names: [str], The specified arg named scrubbed for metrics.

    Raises:
      exc or a core.exceptions variant that does not produce a stack trace.
    """
        error_extra_info = {'error_code': getattr(exc, 'exit_code', 1)}

        # Returns exc.payload.status if available. Otherwise, None.
        http_status_code = getattr(getattr(exc, 'payload', None),
                                   'status_code', None)
        if http_status_code is not None:
            error_extra_info['http_status_code'] = http_status_code

        metrics.Commands(command_path_string,
                         config.CLOUD_SDK_VERSION,
                         specified_arg_names,
                         error=exc.__class__,
                         error_extra_info=error_extra_info)
        metrics.Error(command_path_string,
                      exc.__class__,
                      specified_arg_names,
                      error_extra_info=error_extra_info)

        exceptions.HandleError(exc, command_path_string,
                               self.__known_error_handler)
 def testNotAppendMessage(self):
     error = http_error.MakeHttpError(403)
     with self.AssertRaisesExceptionRegexp(exceptions.HttpException,
                                           'Permission denied.*'):
         exceptions.HandleError(error, 'gcloud.asset.export')
     self.AssertErrNotContains(
         'If you want to invoke the command from a project '
         'different from the target resource project, use '
         '`--billing-project` or `billing/quota_project` property.')
 def testAppendMessage_MissingAuthScopes(self):
     error = http_error.MakeHttpError(
         403, message='Request had insufficient authentication scopes')
     with self.AssertRaisesExceptionRegexp(exceptions.HttpException,
                                           'Permission denied.*'):
         exceptions.HandleError(error, 'gcloud.asset.export')
     self.AssertErrContains(
         'If you are in a compute engine VM, it is likely that the specified '
         'scopes during VM creation are not enough to run this command.')
 def testAppendMessage_MissingServicesUsePermission(self):
     error = http_error.MakeHttpError(
         403,
         message=(
             'Grant the caller the Owner or Editor role, or a custom role '
             'with the serviceusage.services.use permission'))
     with self.AssertRaisesExceptionRegexp(exceptions.HttpException,
                                           'Permission denied.*'):
         exceptions.HandleError(error, 'gcloud.asset.export')
     self.AssertErrContains(
         'If you want to invoke the command from a project '
         'different from the target resource project, use '
         '`--billing-project` or `billing/quota_project` property.')
Beispiel #6
0
    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)


if __name__ == '__main__':
    try:
        bootstrapping.CommandStart('dev_appserver', component_id='core')
        bootstrapping.CheckUpdates('dev_appserver')
        main()
    except Exception as e:  # pylint: disable=broad-except
        exceptions.HandleError(e, 'dev_appserver')
Beispiel #7
0
                '--service_account_credential_file', single_store_path,
                '--service_account_private_key_file', p12_key_path]
      else:
        # Don't have any credentials we can pass.
        raise store.NoCredentialsForAccountException(account)

    _MaybeAddOption(args, 'project_id', project)

  bootstrapping.CheckUpdates('bq')

  proxy_params = properties.VALUES.proxy
  _MaybeAddOption(args, 'proxy_address', proxy_params.address.Get())
  _MaybeAddOption(args, 'proxy_port', proxy_params.port.Get())
  _MaybeAddOption(args, 'proxy_username', proxy_params.username.Get())
  _MaybeAddOption(args, 'proxy_password', proxy_params.password.Get())
  _MaybeAddOption(args, 'disable_ssl_validation',
                  properties.VALUES.auth.disable_ssl_validation.GetBool())
  _MaybeAddOption(args, 'ca_certificates_file',
                  properties.VALUES.core.custom_ca_certs_file .Get())

  bootstrapping.ExecutePythonTool(
      'platform/bq', 'bq.py', *args)


if __name__ == '__main__':
  bootstrapping.DisallowPython3()
  try:
    main()
  except Exception as e:  # pylint: disable=broad-except
    exceptions.HandleError(e, 'bq')
Beispiel #8
0
  _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)


if __name__ == '__main__':
  bootstrapping.DisallowPython3()
  try:
    version = bootstrapping.ReadFileContents('platform/gsutil', 'VERSION')
    bootstrapping.CommandStart('gsutil', version=version)

    blacklist = {
        'update': 'To update, run: gcloud components update',
    }

    argv = bootstrapping.GetDecodedArgv()
    bootstrapping.CheckForBlacklistedCommand(argv, blacklist, warn=True,
                                             die=True)
    # Don't call bootstrapping.PreRunChecks because anonymous access is
    # supported for some endpoints. gsutil will output the appropriate
    # error message upon receiving an authentication error.
    bootstrapping.CheckUpdates('gsutil')
    main()
  except Exception as e:  # pylint: disable=broad-except
    exceptions.HandleError(e, 'gsutil')
Beispiel #9
0
#!/usr/bin/env python
#
# Copyright 2015 Google Inc. All Rights Reserved.
#
"""A convenience wrapper for endpointscfg.py for appengine for python."""

import os

import bootstrapping.bootstrapping as bootstrapping
from googlecloudsdk.calliope import exceptions
from googlecloudsdk.core.updater import update_manager


def main():
    """Runs endpointscfg.py."""
    update_manager.UpdateManager.EnsureInstalledAndRestart(
        ['app-engine-python'], command=__file__)

    bootstrapping.ExecutePythonTool(
        os.path.join('platform', 'google_appengine'), 'endpointscfg.py')


if __name__ == '__main__':
    try:
        bootstrapping.CommandStart('endpointscfg', component_id='core')
        bootstrapping.CheckUpdates('endpointscfg')
        main()
    except Exception as e:  # pylint: disable=broad-except
        exceptions.HandleError(e, 'endpointscfg')