Ejemplo n.º 1
0
 def test_get_token(self):
     token_client = MagicMock()
     token_client.retrieve_token = MagicMock(return_value='token')
     token_manager = TokenManager(token_client=token_client)
     token = token_manager.get_token()
     self.assertTrue(token)
     self.assertEqual(token, 'token')
Ejemplo n.º 2
0
 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)
Ejemplo n.º 3
0
 def test_get_token_when_expired(self):
     token_client = MagicMock()
     token_client.retrieve_token = MagicMock(return_value='token_1')
     token_manager = TokenManager(token_client=token_client)
     token_manager.get_token()
     token_manager.token.is_expired = MagicMock(return_value=True)
     token_client.retrieve_token = MagicMock(return_value='token_2')
     new_token = token_manager.get_token()
     self.assertEqual(new_token, 'token_2')
Ejemplo n.º 4
0
    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)
Ejemplo n.º 5
0
    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__)
Ejemplo n.º 7
0
#!/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}')