def _get_driver_service(self=None): if self.driver_service_singleton is None: if self.context_env is not None: Config = self.context_env.env['ir.config_parameter'].sudo() google_drive_refresh_token = Config.get_param( 'google_drive_refresh_token') else: Config = request.env['ir.config_parameter'].sudo() google_drive_refresh_token = Config.get_param( 'google_drive_refresh_token') user_is_admin = request.env['res.users'].browse( request.env.user.id)._is_admin() if not google_drive_refresh_token: if user_is_admin: dummy, action_id = request.env[ 'ir.model.data'].get_object_reference( 'base_setup', 'action_general_configuration') msg = _( "You haven't configured 'Authorization Code' generated from google, Please generate and configure it ." ) raise RedirectWarning( msg, action_id, _('Go to the configuration panel')) else: raise UserError( _("Google Drive is not yet configured. Please contact your administrator." )) google_drive_client_id = Config.get_param('google_drive_client_id') google_drive_client_secret = Config.get_param( 'google_drive_client_secret') access_token = None token_expiry = None token_uri = 'https://www.googleapis.com/auth/drive.metadata.readonly' # GOOGLE_TOKEN_URI = 'https://oauth2.googleapis.com/token' token_uri = oauth2client.GOOGLE_TOKEN_URI user_agent = 'Python client library' revoke_uri = None credentials = GoogleCredentials(access_token, google_drive_client_id, google_drive_client_secret, google_drive_refresh_token, token_expiry, token_uri, user_agent, revoke_uri=revoke_uri) credentials.scopes = [ 'https://www.googleapis.com/auth/drive.metadata', 'https://www.googleapis.com/auth/drive.readonly', 'https://www.googleapis.com/auth/drive' ] self.driver_service_singleton = build('drive', 'v3', credentials=credentials) return self.driver_service_singleton