예제 #1
0
    def _googledrive_auth(self):
        credentials = None
        dataManager = LocalDataManager()

        #A KeyError will be raised if there is no token.
        credentials = dataManager.get_credentials('GoogleDrive')

        credentials = Credentials.new_from_json(credentials)
        http = credentials.authorize(httplib2.Http())
        try:
            drive_service = build('drive', 'v2', http=http)
        except httplib2.ServerNotFoundError:
            raise faults.NetworkError('No internet.')

        try:
            #Check whether the target folder exists
            container = dataManager.get_service_root('GoogleDrive')
            if container:
                arguments = [
                    'title = "{}"'.format(container),
                    'mimeType = "application/vnd.google-apps.folder"',
                    'trashed = False'
                ]
                q = ' and '.join(arguments)
                response = drive_service.files().list(q=q).execute()
                if not response['items']:
                    #Create the folder
                    self.logger.info(
                        'GoogleDrive folder changed:{}'.format(container))
                    body = {
                        'title': container,
                        'mimeType': 'application/vnd.google-apps.folder'
                    }
                    response = drive_service.files().insert(
                        body=body).execute()
                    dataManager.set_folder_id(response['id'])
                else:
                    dataManager.set_folder_id(response['items'][0]['id'])
        except errors.HttpError as e:
            #raise
            raise faults.NetworkError('No internet.')
        except AccessTokenRefreshError:
            raise faults.InvalidAuth('GoogleDrive')

        dataManager.set_credentials('GoogleDrive', credentials)
        return drive_service
예제 #2
0
    def _dropbox_auth(self):
        access_token = None
        dataManager = LocalDataManager()

        #A KeyError will be raised if there is no token.
        access_token = dataManager.get_credentials('Dropbox')

        dropboxClient = DropboxClient(access_token)

        try:
            dropboxClient.account_info()
        except rest.ErrorResponse as e:
            if e.status == 401:
                raise faults.InvalidAuth('Dropbox-Auth')
        except rest.RESTSocketError as e:
            raise faults.NetworkError('No internet-Auth')

        return dropboxClient
예제 #3
0
    def _dropbox_auth(self):
        access_token = None
        dataManager = LocalDataManager()

        #A KeyError will be raised if there is no token.
        access_token = dataManager.get_credentials('Dropbox')

        dropboxClient = DropboxClient(access_token)

        try:
            dropboxClient.account_info()
        except rest.ErrorResponse as e:
            if e.status == 401:
                raise faults.InvalidAuth('Dropbox-Auth')
        except rest.RESTSocketError as e:
            raise faults.NetworkError('No internet-Auth')

        return dropboxClient
예제 #4
0
    def _googledrive_auth(self):
        credentials = None
        dataManager = LocalDataManager()

        #A KeyError will be raised if there is no token.
        credentials = dataManager.get_credentials('GoogleDrive')

        credentials = Credentials.new_from_json(credentials)
        http = credentials.authorize(httplib2.Http())
        try:
            drive_service = build('drive', 'v2', http=http)
        except httplib2.ServerNotFoundError:
            raise faults.NetworkError('No internet.')

        try:
            #Check whether the target folder exists
            container = dataManager.get_service_root('GoogleDrive')
            if container:
                arguments = ['title = "{}"'.format(container),
                             'mimeType = "application/vnd.google-apps.folder"',
                             'trashed = False']
                q = ' and '.join(arguments)
                response = drive_service.files().list(q=q).execute()
                if not response['items']:
                    #Create the folder
                    self.logger.info('GoogleDrive folder changed:{}'.format(container))
                    body = {'title':container, 'mimeType':'application/vnd.google-apps.folder'}
                    response = drive_service.files().insert(body=body).execute()
                    dataManager.set_folder_id(response['id'])
                else:
                    dataManager.set_folder_id(response['items'][0]['id'])
        except errors.HttpError as e:
            #raise
            raise faults.NetworkError('No internet.')
        except AccessTokenRefreshError:
            raise faults.InvalidAuth('GoogleDrive')

        dataManager.set_credentials('GoogleDrive', credentials)
        return drive_service
예제 #5
0
    def _pithos_auth(self):
        access_token = None
        dataManager = LocalDataManager()

        #A KeyError will be raised if there is no token.
        access_token = dataManager.get_credentials('Pithos')
        try:
            dm = LocalDataManager()
            s = AstakosClient(access_token, local.Pithos_AUTHURL)
            auth_data = s.authenticate()
            pithos_url = self._get_pithos_public_url(auth_data)
            uuid = auth_data['access']['user']['id']
            pithosClient = CloudyPithosClient(pithos_url, access_token, uuid)
            pithosClient.container = dm.get_service_root('Pithos')

            #Check if the container saved in the settings exists.
            self._call_exceptional(pithosClient)
        except (AstakosErrors.Unauthorized, faults.InvalidAuth) as e:
            raise faults.InvalidAuth('Pithos-Auth')
        except (AstakosErrors.AstakosClientException, faults.NetworkError) as e:
            raise faults.NetworkError('No internet-Auth')

        return pithosClient
예제 #6
0
    def _pithos_auth(self):
        access_token = None
        dataManager = LocalDataManager()

        #A KeyError will be raised if there is no token.
        access_token = dataManager.get_credentials('Pithos')
        try:
            dm = LocalDataManager()
            s = AstakosClient(access_token, local.Pithos_AUTHURL)
            auth_data = s.authenticate()
            pithos_url = self._get_pithos_public_url(auth_data)
            uuid = auth_data['access']['user']['id']
            pithosClient = CloudyPithosClient(pithos_url, access_token, uuid)
            pithosClient.container = dm.get_service_root('Pithos')

            #Check if the container saved in the settings exists.
            self._call_exceptional(pithosClient)
        except (AstakosErrors.Unauthorized, faults.InvalidAuth) as e:
            raise faults.InvalidAuth('Pithos-Auth')
        except (AstakosErrors.AstakosClientException,
                faults.NetworkError) as e:
            raise faults.NetworkError('No internet-Auth')

        return pithosClient