def _get_credentials_and_project_id( self) -> Tuple[google.auth.credentials.Credentials, Optional[str]]: """Returns the Credentials object for Google API and the associated project_id""" if self._cached_credentials is not None: return self._cached_credentials, self._cached_project_id key_path: Optional[str] = self._get_field('key_path', None) try: keyfile_dict: Optional[str] = self._get_field('keyfile_dict', None) keyfile_dict_json: Optional[Dict[str, str]] = None if keyfile_dict: keyfile_dict_json = json.loads(keyfile_dict) except json.decoder.JSONDecodeError: raise AirflowException('Invalid key JSON.') target_principal, delegates = _get_target_principal_and_delegates( self.impersonation_chain) credentials, project_id = get_credentials_and_project_id( key_path=key_path, keyfile_dict=keyfile_dict_json, scopes=self.scopes, delegate_to=self.delegate_to, target_principal=target_principal, delegates=delegates, ) overridden_project_id = self._get_field('project') if overridden_project_id: project_id = overridden_project_id self._cached_credentials = credentials self._cached_project_id = project_id return credentials, project_id
def test_get_target_principal_and_delegates_with_input( self, _, impersonation_chain, target_principal_and_delegates ): self.assertEqual( _get_target_principal_and_delegates(impersonation_chain), target_principal_and_delegates )
def test_get_target_principal_and_delegates_no_argument(self): self.assertEqual(_get_target_principal_and_delegates(), (None, None))
def test_get_target_principal_and_delegates_no_argument(self): assert _get_target_principal_and_delegates() == (None, None)