Esempio n. 1
0
 def _CtrlCHandler(unused_signal, unused_frame):
     if self._interruptable:
         raise console_io.OperationCancelledError(self._aborted_message)
     else:
         with self._lock:
             sys.stderr.write(
                 '\n\nThis operation cannot be cancelled.\n\n')
Esempio n. 2
0
  def RemoveKeyFilesIfPermittedOrFail(self, force_key_file_overwrite):
    """Removes all SSH key files if user permitted this behavior.

    User can express intent through --(no)--force-key-file-overwrite flag or
    prompt (only in interactive mode). Default behavior is to be
    non-destructive.

    Args:
      force_key_file_overwrite: bool, value of the flag specified or not by user
    """
    permissive = True  # TODO(b/33193000) Flip this bool value
    message = 'Your SSH key files are broken.\n' + self._StatusMessage()
    if force_key_file_overwrite is False:
      raise console_io.OperationCancelledError(message + 'Operation aborted.')
    message += 'We are going to overwrite all above files.'
    if force_key_file_overwrite:
      # self.force_key_file_overwrite is True
      log.warn(message)
    else:
      # self.force_key_file_overwrite is None
      # Deprecated code path is triggered only when flags are not provided.
      # Show deprecation warning only in that case.
      # Show deprecation warning before prompt to increase chance user read
      # this.
      # TODO(b/33193000) Remove this deprecation warning
      log.warn('Permissive behavior in non-interactive mode is DEPRECATED '
               'and will be removed 1st Jun 2017.\n'
               'Use --no-force-key-file-overwrite flag to opt-in for new '
               'behavior now.\n'
               'If You want to preserve old behavior, You can opt-out from '
               'new behavior using --force-key-file-overwrite flag.')
      try:
        console_io.PromptContinue(message, default=False,
                                  throw_if_unattended=permissive,
                                  cancel_on_no=True)
      except console_io.UnattendedPromptError:
        # Used to workaround default in non-interactive prompt for old behavior
        pass  # TODO(b/33193000) Remove this - exception will not be raised

    # Remove existing broken key files and prepare to regenerate them.
    # User agreed.
    for key_file in self.keys.viewvalues():
      try:
        os.remove(key_file.filename)
      except OSError as e:
        # May be due to the fact that key_file.filename points to a directory
        if e.errno == errno.EISDIR:
          raise
Esempio n. 3
0
    def RemoveKeyFilesIfPermittedOrFail(self, force_key_file_overwrite=None):
        """Removes all SSH key files if user permitted this behavior.

    Precondition: The SSH key files are currently in a broken state.

    Depending on `force_key_file_overwrite`, delete all SSH key files:

    - If True, delete key files.
    - If False, cancel immediately.
    - If None and
      - interactive, prompt the user.
      - non-interactive, cancel.

    Args:
      force_key_file_overwrite: bool or None, overwrite broken key files.

    Raises:
      console_io.OperationCancelledError: Operation intentionally cancelled.
      OSError: Error deleting the broken file(s).
    """
        message = 'Your SSH key files are broken.\n' + self._StatusMessage()
        if force_key_file_overwrite is False:
            raise console_io.OperationCancelledError(message +
                                                     'Operation aborted.')
        message += 'We are going to overwrite all above files.'
        log.warn(message)
        if force_key_file_overwrite is None:
            # - Interactive when pressing 'Y', continue
            # - Interactive when pressing enter or 'N', raise OperationCancelledError
            # - Non-interactive, raise OperationCancelledError
            console_io.PromptContinue(default=False, cancel_on_no=True)

        # Remove existing broken key files.
        for key_file in self.keys.viewvalues():
            try:
                os.remove(key_file.filename)
            except OSError as e:
                if e.errno == errno.EISDIR:
                    # key_file.filename points to a directory
                    raise
Esempio n. 4
0
def _EnsureUserAcceptsTermsOfService():
    """Don't allow GCTL tests to run until user accepts the Terms of Service."""
    tos_file = os.path.join(config.Paths().global_config_dir,
                            'GCTL_ToS_Accepted')
    if not os.path.isfile(tos_file):
        if properties.VALUES.core.disable_prompts.GetBool():
            log.error(
                'Trusted Tester Agreement has not been accepted. Please run '
                'gcloud with prompts enabled to accept the Terms of Service.')
            raise console_io.OperationCancelledError()
        console_io.PromptContinue(
            message=
            'The Google Cloud Platform Terms of Service notwithstanding, '
            'your use of Google Cloud Test Lab is governed by the Trusted Tester '
            'Agreement and by using Google Cloud Test Lab, you agree to its '
            'terms.\n\nTrusted Tester Agreement: https://goo.gl/K109WG',
            prompt_string='Proceed',
            default=False,
            throw_if_unattended=True,
            cancel_on_no=True)  # Abort unless user explicitly answers 'y'
        log.info('User has accepted Trusted Tester Agreement.')
        # Create an empty tos_file to mark user acceptance and avoid future prompts.
        open(tos_file, 'w').close()
Esempio n. 5
0
 def _CtrlCHandler(unused_signal, unused_frame):
   if self._interruptable:
     raise console_io.OperationCancelledError(self._aborted_message)
   else:
     self._NotifyUninterruptableError()