Example #1
0
        def proxied_method(auto_refresh=True, **kwargs):
            # Now, try to invoke the mechanism. If we succeed, return
            # immediately. If we get an authorization-fault (a resolvable
            # authorization problem), fall through and attempt to fix it. Allow
            # any other error to bubble up.

            self.__log.debug("Attempting to invoke method for action [%s]." %
                             (action))

            for n in range(0, 5):
                try:
                    return method(**kwargs)
                except (ssl.SSLError, httplib.BadStatusLine) as e:
                    # These happen sporadically. Use backoff.
                    self.__log.exception("There was a transient connection "
                                         "error (%s). Trying again (%s): %d" %
                                         (e.__class__.__name__, str(e), n))

                    time.sleep((2**n) + random.randint(0, 1000) / 1000)
                except HttpError as e:
                    try:
                        error = json.loads(e.content)
                    except ValueError:
                        _logger.error(
                            "Non-JSON error while doing chunked "
                            "download: %s", e.content)

                    if error.get('code') == 403 and \
                       error.get('errors')[0].get('reason') \
                       in ['rateLimitExceeded', 'userRateLimitExceeded']:
                        # Apply exponential backoff.
                        self.__log.exception("There was a transient HTTP "
                                             "error (%s). Trying again (%d): "
                                             "%s" %
                                             (e.__class__.__name__, str(e), n))

                        time.sleep((2**n) + random.randint(0, 1000) / 1000)
                    else:
                        # Other error, re-raise.
                        raise
                except AuthorizationFaultError:
                    # If we're not allowed to refresh the token, or we've
                    # already done it in the last attempt.
                    if not auto_refresh or n == 1:
                        raise

                    # We had a resolvable authorization problem.

                    self.__log.info("There was an authorization fault under "
                                    "action [%s]. Attempting refresh." %
                                    (action))

                    authorize = get_auth()
                    authorize.check_credential_state()

                    # Re-attempt the action.

                    self.__log.info("Refresh seemed successful. Reattempting "
                                    "action [%s]." % (action))
Example #2
0
    def wrapper(*args, **kwargs):
        # Now, try to invoke the mechanism. If we succeed, return 
        # immediately. If we get an authorization-fault (a resolvable 
        # authorization problem), fall through and attempt to fix it. Allow 
        # any other error to bubble up.
        
        for n in range(0, 5):
            try:
                return f(*args, **kwargs)
            except (ssl.SSLError, httplib.BadStatusLine) as e:
                # These happen sporadically. Use backoff.
                _logger.exception("There was a transient connection "
                                  "error (%s). Trying again [%s]: %s",
                                  e.__class__.__name__, str(e), n)

                time.sleep((2 ** n) + random.randint(0, 1000) / 1000)
            except HttpError as e:
                if e.content == '':
                    raise

                try:
                    error = json.loads(e.content)
                except ValueError:
                    _logger.error("Non-JSON error while doing chunked "
                                  "download: [%s]", e.content) 
                    raise e

                if error.get('code') == 403 and \
                   error.get('errors')[0].get('reason') \
                        in ['rateLimitExceeded', 'userRateLimitExceeded']:
                    # Apply exponential backoff.
                    _logger.exception("There was a transient HTTP "
                                      "error (%s). Trying again (%d): "
                                      "%s",
                                      e.__class__.__name__, str(e), n)

                    time.sleep((2 ** n) + random.randint(0, 1000) / 1000)
                else:
                    # Other error, re-raise.
                    raise
            except AuthorizationFaultError:
                # If we're not allowed to refresh the token, or we've
                # already done it in the last attempt.
                if not auto_refresh or n == 1:
                    raise

                # We had a resolvable authorization problem.

                _logger.info("There was an authorization fault under "
                             "action [%s]. Attempting refresh.", action)
                
                authorize = get_auth()
                authorize.check_credential_state()

                # Re-attempt the action.

                _logger.info("Refresh seemed successful. Reattempting "
                             "action [%s].", action)
Example #3
0
        def proxied_method(auto_refresh = True, **kwargs):
            # Now, try to invoke the mechanism. If we succeed, return 
            # immediately. If we get an authorization-fault (a resolvable 
            # authorization problem), fall through and attempt to fix it. Allow 
            # any other error to bubble up.
            
            self.__log.debug("Attempting to invoke method for action [%s]." % 
                             (action))
                
            try:
                return method(**kwargs)
            except AuthorizationFaultError:
                if not auto_refresh:
                    self.__log.exception("There was an authorization fault under "
                                      "proxied action [%s], and we were told "
                                      "to NOT auto-refresh." % (action))
                    raise
            except HttpError as e:
                logging.exception("There was an HTTP response-code of (%d) "
                                  "while trying to do [%s]." % 
                                  (e.resp.status, action))      
                raise
            except NameError:
                raise
            except:
                self.__log.exception("There was an unhandled exception during the"
                                  " execution of the Drive logic for action "
                                  "[%s]." % (action))
                raise
                
            # We had a resolvable authorization problem.

            self.__log.info("There was an authorization fault under action [%s]. "
                         "Attempting refresh." % (action))
            
            try:
                authorize = get_auth()
                authorize.check_credential_state()
            except:
                self.__log.exception("There was an error while trying to fix an "
                                  "authorization fault.")
                raise

            # Re-attempt the action.

            self.__log.info("Refresh seemed successful. Reattempting action "
                         "[%s]." % (action))
            
            try:
                return method(**kwargs)
            except:
                self.__log.exception("There was an unhandled exception during "
                                  "the execution of the Drive logic for action"
                                  " [%s], and refreshing either didn't help it"
                                  " or wasn't sufficient." % (action))
                raise
Example #4
0
        def proxied_method(auto_refresh = True, **kwargs):
            # Now, try to invoke the mechanism. If we succeed, return 
            # immediately. If we get an authorization-fault (a resolvable 
            # authorization problem), fall through and attempt to fix it. Allow 
            # any other error to bubble up.
            
            self.__log.debug("Attempting to invoke method for action [%s]." % 
                             (action))
                
            try:
                return method(**kwargs)
            except AuthorizationFaultError:
                if not auto_refresh:
                    self.__log.exception("There was an authorization fault under "
                                      "proxied action [%s], and we were told "
                                      "to NOT auto-refresh." % (action))
                    raise
            except HttpError as e:
                logging.exception("There was an HTTP response-code of (%d) "
                                  "while trying to do [%s]." % 
                                  (e.resp.status, action))      
                raise
            except NameError:
                raise
            except:
                self.__log.exception("There was an unhandled exception during the"
                                  " execution of the Drive logic for action "
                                  "[%s]." % (action))
                raise
                
            # We had a resolvable authorization problem.

            self.__log.info("There was an authorization fault under action [%s]. "
                         "Attempting refresh." % (action))
            
            try:
                authorize = get_auth()
                authorize.check_credential_state()
            except:
                self.__log.exception("There was an error while trying to fix an "
                                  "authorization fault.")
                raise

            # Re-attempt the action.

            self.__log.info("Refresh seemed successful. Reattempting action "
                         "[%s]." % (action))
            
            try:
                return method(**kwargs)
            except:
                self.__log.exception("There was an unhandled exception during "
                                  "the execution of the Drive logic for action"
                                  " [%s], and refreshing either didn't help it"
                                  " or wasn't sufficient." % (action))
                raise
Example #5
0
 def __init__(self):
     self.__log = logging.getLogger().getChild('GoogleProxy')
     self.authorize = get_auth()
     self.gdrive_wrapper = _GdriveManager()
Example #6
0
 def __init__(self):
     self.__log = logging.getLogger().getChild('GdManager')
     self.authorize = get_auth()
     self.check_authorization()
Example #7
0
 def __init__(self):
     self.__client = None
     self.__authorize = get_auth()
     self.__check_authorization()
     self.__http = None
Example #8
0
auth_xor.add_argument('-u', '--url', help='Get an authorization URL.', 
                      action='store_true')
auth_xor.add_argument('-a', '--auth', nargs=2,
                      metavar=('auth_storage_file', 'authcode'), 
                      help='Register an authorization-code from Google '
                      'Drive.')

mount_auth = subparsers.add_parser('mount', help='Mounting subcommand.')
load_mount_parser_args(mount_auth)

args = parser.parse_args()

# An authorization URL was requested.
if 'url' in args and args.url:
    try:
        authorize = get_auth()
        url = authorize.step1_get_auth_url()
    except Exception as e:
        print("Could not produce auth-URL: %s" % (e))
        exit()

    print("To authorize FUSE to use your Google Drive account, visit the "
          "following URL to produce an authorization code:\n\n%s\n" % 
          (url))

# An authorization from the URL needs to be submitted.
elif 'auth' in args and args.auth:
    (auth_storage_file, authcode) = args.auth

    set_auth_cache_filepath(auth_storage_file)
Example #9
0
 def __init__(self):
     self.__log = logging.getLogger().getChild('GoogleProxy')
     self.authorize      = get_auth()
     self.gdrive_wrapper = _GdriveManager()
Example #10
0
 def __init__(self):
     self.__log = logging.getLogger().getChild('GdManager')
     self.authorize = get_auth()
     self.check_authorization()
Example #11
0
 def __init__(self):
     self.__client = None
     self.__authorize = get_auth()
     self.__check_authorization()
     self.__http = None
Example #12
0
auth_xor.add_argument('-a',
                      '--auth',
                      nargs=2,
                      metavar=('auth_storage_file', 'authcode'),
                      help='Register an authorization-code from Google '
                      'Drive.')

mount_auth = subparsers.add_parser('mount', help='Mounting subcommand.')
load_mount_parser_args(mount_auth)

args = parser.parse_args()

# An authorization URL was requested.
if 'url' in args and args.url:
    try:
        authorize = get_auth()
        url = authorize.step1_get_auth_url()
    except Exception as e:
        print("Could not produce auth-URL: %s" % (e))
        exit()

    print("To authorize FUSE to use your Google Drive account, visit the "
          "following URL to produce an authorization code:\n\n%s\n" % (url))

# An authorization from the URL needs to be submitted.
elif 'auth' in args and args.auth:
    (auth_storage_file, authcode) = args.auth

    set_auth_cache_filepath(auth_storage_file)

    try:
Example #13
0
 def __init__(self):
     self.__log = logging.getLogger().getChild('GdAuth')
     self.__client = None
     self.__authorize = get_auth()
     self.__check_authorization()
Example #14
0
 def __init__(self):
     self.__log = logging.getLogger().getChild('GdAuth')
     self.__client = None
     self.__authorize = get_auth()
     self.__check_authorization()