Example #1
0
  def test_method_forwarding_windows(self, *unused_mocks):
    # Test that the correct calls are being forwarded to the subprocess module
    # and that the shell=True flag is added when we are on Windows.
    processes.force_shell = True

    processes.call(['subprocess', 'call'], shell=False, other_arg=True)
    processes.subprocess.call.assert_called_once_with(['subprocess', 'call'],
                                                      shell=True,
                                                      other_arg=True)

    processes.check_call(['subprocess', 'check_call'],
                         shell=False,
                         other_arg=True)
    processes.subprocess.check_call.assert_called_once_with(
        ['subprocess', 'check_call'], shell=True, other_arg=True)

    processes.check_output(['subprocess', 'check_output'],
                           shell=False,
                           other_arg=True)
    processes.subprocess.check_output.assert_called_once_with(
        ['subprocess', 'check_output'], shell=True, other_arg=True)

    processes.Popen(['subprocess', 'Popen'], shell=False, other_arg=True)
    processes.subprocess.Popen.assert_called_once_with(['subprocess', 'Popen'],
                                                       shell=True,
                                                       other_arg=True)
Example #2
0
 def _refresh(self, http_request):
   """Gets an access token using the gcloud client."""
   try:
     gcloud_process = processes.Popen(
         ['gcloud', 'auth', 'print-access-token'], stdout=processes.PIPE)
   except OSError as exn:
     logging.error('The gcloud tool was not found.', exc_info=True)
     raise AuthenticationException('The gcloud tool was not found: %s' % exn)
   output, _ = gcloud_process.communicate()
   self.access_token = output.strip()
Example #3
0
File: auth.py Project: zhpshu/beam
 def _refresh(self, http_request):
     """Gets an access token using the gcloud client."""
     try:
         gcloud_process = processes.Popen(
             ['gcloud', 'auth', 'print-access-token'],
             stdout=processes.PIPE)
     except OSError:
         message = 'gcloud tool not found so falling back to using ' +\
                   'application default credentials'
         logging.warning(message)
         raise AuthenticationException(message)
     output, _ = gcloud_process.communicate()
     self.access_token = output.strip()
Example #4
0
def print_access_token():
    gcloud_process = processes.Popen(['gcloud', 'auth', 'print-access-token'], stdout=processes.PIPE)
    output, _ = gcloud_process.communicate()
    return 'token="{}"'.format(output.strip()), 200