def refresh(self, request): try: client = UserSecretsClient() if self.target == GcpTarget.BIGQUERY: self.token, self.expiry = client.get_bigquery_access_token() elif self.target == GcpTarget.GCS: self.token, self.expiry = client._get_gcs_access_token() elif self.target == GcpTarget.AUTOML: self.token, self.expiry = client._get_automl_access_token() elif self.target == GcpTarget.TRANSLATION: self.token, self.expiry = client._get_translation_access_token( ) elif self.target == GcpTarget.NATURAL_LANGUAGE: self.token, self.expiry = client._get_natural_language_access_token( ) elif self.target == GcpTarget.VIDEO_INTELLIGENCE: self.token, self.expiry = client._get_video_intelligence_access_token( ) elif self.target == GcpTarget.VISION: self.token, self.expiry = client._get_vision_access_token() except ConnectionError as e: Log.error(f"Connection error trying to refresh access token: {e}") print( "There was a connection error trying to fetch the access token. " f"Please ensure internet is on in order to use the {self.target.service} Integration." ) raise RefreshError( 'Unable to refresh access token due to connection error.' ) from e except Exception as e: Log.error(f"Error trying to refresh access token: {e}") if (not get_integrations().has_integration(self.target)): Log.error(f"No {self.target.service} integration found.") print( f"Please ensure you have selected a {self.target.service} account in the Notebook Add-ons menu." ) raise RefreshError('Unable to refresh access token.') from e
def call_get_translation_access_token(): client = UserSecretsClient() secret_response = client._get_translation_access_token() self.assertEqual(secret_response, (secret, now + timedelta(seconds=3600)))