
from __future__ import absolute_import

from boto.auth_handler import AuthHandler
from boto.auth_handler import NotReadyToAuthenticate
import oauth2client.contrib.devshell as devshell


class DevshellAuth(AuthHandler):
  """Developer Shell authorization plugin class."""

  capability = ['s3']

  def __init__(self, path, config, provider):
    if provider != 'gs':
      # Devshell credentials are valid for Google only and can't be used for s3.
      raise NotReadyToAuthenticate()
    try:
      self.creds = devshell.DevshellCredentials()
    except:
      raise NotReadyToAuthenticate()

  def add_auth(self, http_request):
    http_request.headers['Authorization'] = ('Bearer %s' %
                                             self.creds.access_token)



from __future__ import absolute_import

from boto.auth_handler import AuthHandler
from boto.auth_handler import NotReadyToAuthenticate
import oauth2client.contrib.devshell as devshell


class DevshellAuth(AuthHandler):
  """Developer Shell authorization plugin class."""

  capability = ['s3']

  def __init__(self, path, config, provider):
    # Provider here is a boto.provider.Provider object (as opposed to the
    # provider attribute of CloudApi objects, which is a string).
    if provider.name != 'google':
      # Devshell credentials are valid for Google only and can't be used for s3.
      raise NotReadyToAuthenticate()
    try:
      self.creds = devshell.DevshellCredentials()
    except:
      raise NotReadyToAuthenticate()

  def add_auth(self, http_request):
    http_request.headers['Authorization'] = ('Bearer %s' %
                                             self.creds.access_token)


Fix provider check causing Devshell auth failure
Fix provider check causing Devshell auth failure

This commit builds on commit 13c4926, allowing Devshell credentials to
be used only with Google storage.

  
  from __future__ import absolute_import
  
  from boto.auth_handler import AuthHandler
  from boto.auth_handler import NotReadyToAuthenticate
  import oauth2client.contrib.devshell as devshell
  
  
  class DevshellAuth(AuthHandler):
    """Developer Shell authorization plugin class."""
  
    capability = ['s3']
  
    def __init__(self, path, config, provider):
+     # Provider here is a boto.provider.Provider object (as opposed to the
+     # provider attribute of CloudApi objects, which is a string).
-     if provider != 'gs':
+     if provider.name != 'google':
        # Devshell credentials are valid for Google only and can't be used for s3.
        raise NotReadyToAuthenticate()
      try:
        self.creds = devshell.DevshellCredentials()
      except:
        raise NotReadyToAuthenticate()
  
    def add_auth(self, http_request):
      http_request.headers['Authorization'] = ('Bearer %s' %
                                               self.creds.access_token)
  
  
Fix provider check causing Devshell auth failure
## Code Before:

from __future__ import absolute_import

from boto.auth_handler import AuthHandler
from boto.auth_handler import NotReadyToAuthenticate
import oauth2client.contrib.devshell as devshell


class DevshellAuth(AuthHandler):
  """Developer Shell authorization plugin class."""

  capability = ['s3']

  def __init__(self, path, config, provider):
    if provider != 'gs':
      # Devshell credentials are valid for Google only and can't be used for s3.
      raise NotReadyToAuthenticate()
    try:
      self.creds = devshell.DevshellCredentials()
    except:
      raise NotReadyToAuthenticate()

  def add_auth(self, http_request):
    http_request.headers['Authorization'] = ('Bearer %s' %
                                             self.creds.access_token)


## Instruction:
Fix provider check causing Devshell auth failure
## Code After:

from __future__ import absolute_import

from boto.auth_handler import AuthHandler
from boto.auth_handler import NotReadyToAuthenticate
import oauth2client.contrib.devshell as devshell


class DevshellAuth(AuthHandler):
  """Developer Shell authorization plugin class."""

  capability = ['s3']

  def __init__(self, path, config, provider):
    # Provider here is a boto.provider.Provider object (as opposed to the
    # provider attribute of CloudApi objects, which is a string).
    if provider.name != 'google':
      # Devshell credentials are valid for Google only and can't be used for s3.
      raise NotReadyToAuthenticate()
    try:
      self.creds = devshell.DevshellCredentials()
    except:
      raise NotReadyToAuthenticate()

  def add_auth(self, http_request):
    http_request.headers['Authorization'] = ('Bearer %s' %
                                             self.creds.access_token)

