def test__retrieve_token__raises_error__with_no_audience(self): token_client = S2STokenClient(credential=ServiceCredential({}), audience=None) with self.assertRaises(S2STokenClientError): token = token_client.retrieve_token() self.assertEqual(token, None)
def configure_ingest_client(self): gcp_credentials_file = os.environ.get('GOOGLE_APPLICATION_CREDENTIALS') self.s2s_token_client = S2STokenClient( ServiceCredential.from_file(gcp_credentials_file), INGEST_API_JWT_AUDIENCE) self.token_manager = TokenManager(self.s2s_token_client) self.ingest_api = IngestApi(url=INGEST_API, token_manager=self.token_manager)
def test__retrieve_token__returns_token__with_creds_and_audience( self, mock_retrieve_token): mock_retrieve_token.return_value = 'token' token_client = S2STokenClient(credential=ServiceCredential({}), audience='audience') token = token_client.retrieve_token() self.assertEqual(token, 'token')
def __init__(self): """This class controls the authentication actions with Ingest Service, including retrieving the token, store the token and make authenticated headers. Note: """ self.s2s_token_client = S2STokenClient() gcp_credentials_file = os.environ.get('GOOGLE_APPLICATION_CREDENTIALS') self.s2s_token_client.setup_from_file(gcp_credentials_file) self.token_manager = TokenManager(token_client=self.s2s_token_client)
def setUp(self): self.deployment = os.environ.get('DEPLOYMENT_ENV', None) if self.deployment not in DEPLOYMENTS: raise RuntimeError(f'DEPLOYMENT_ENV environment variable must be one of {DEPLOYMENTS}') self.ingest_client_api = IngestApi(url=f"https://api.ingest.{self.deployment}.data.humancellatlas.org") self.s2s_token_client = S2STokenClient() gcp_credentials_file = os.environ.get('GOOGLE_APPLICATION_CREDENTIALS') self.s2s_token_client.setup_from_file(gcp_credentials_file) self.token_manager = TokenManager(self.s2s_token_client) self.ingest_broker = IngestUIAgent(self.deployment) self.ingest_api = IngestApiAgent(deployment=self.deployment)
def __init__(self, connection, validation_queue, graph, test_path): self.connection = connection self.validation_queue = validation_queue self._graph = graph self._test_path = test_path if Config["INGEST_API"] == "http://localhost:8080" or not ( Config["GOOGLE_APPLICATION_CREDENTIALS"] and Config["INGEST_JWT_AUDIENCE"]): self._ingest_api = IngestApi(Config['INGEST_API']) else: s2s_token_client = S2STokenClient( credential=ServiceCredential.from_file( Config['GOOGLE_APPLICATION_CREDENTIALS']), audience=Config['INGEST_JWT_AUDIENCE']) token_manager = TokenManager(s2s_token_client) self._ingest_api = IngestApi(Config['INGEST_API'], token_manager=token_manager) self._logger = logging.getLogger(__name__)
#!/usr/bin/env python import sys from ingest.utils.s2s_token_client import S2STokenClient from ingest.utils.token_manager import TokenManager if __name__ == '__main__': key_file = sys.argv[1] client = S2STokenClient() client.setup_from_file(key_file) token_manager = TokenManager(client) token = token_manager.get_token() print(f'Bearer {token}')