From e2f5ac387c0068d53949bcce961682261b57c0d3 Mon Sep 17 00:00:00 2001 From: David Schultz Date: Mon, 10 Jun 2024 17:03:03 -0500 Subject: [PATCH] set rest clients in queue --- iceprod/server/data/config.schema.json | 12 ++++++++++++ iceprod/server/queue.py | 22 ++++++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/iceprod/server/data/config.schema.json b/iceprod/server/data/config.schema.json index 4b76cc62..963fc5e2 100644 --- a/iceprod/server/data/config.schema.json +++ b/iceprod/server/data/config.schema.json @@ -32,6 +32,10 @@ "type": "string", "default": "condor" }, + "site": { + "description": "Site name", + "type": "string" + }, "description": { "type": "string", "default": "generic grid plugin" @@ -152,6 +156,14 @@ "description": "OAuth provider url", "type": "string", "default": "https://keycloak.icecube.wisc.edu/auth/realms/IceCube" + }, + "oauth_client_id": { + "description": "OAuth client id", + "type": "string" + }, + "oauth_client_secret": { + "description": "OAuth client secret", + "type": "string" } }, "additionalProperties": true diff --git a/iceprod/server/queue.py b/iceprod/server/queue.py index e79e1b71..e4059578 100644 --- a/iceprod/server/queue.py +++ b/iceprod/server/queue.py @@ -103,6 +103,28 @@ def get_grid_plugin(self): 'rest_client': None, 'cred_client': None, } + + if ('rest_api' in self.cfg and 'url' in self.cfg['rest_api'] + and 'oauth_url' in self.cfg['rest_api'] + and 'oauth_client_id' in self.cfg['rest_api'] + and 'oauth_client_secret' in self.cfg['rest_api']): + try: + kwargs['rest_client'] = ClientCredentialsAuth( + address=self.cfg['rest_api']['url'], + token_url=self.cfg['rest_api']['oauth_url'], + client_id=self.cfg['rest_api']['oauth_client_id'], + client_secret=self.cfg['rest_api']['oauth_client_secret'], + ) + kwargs['cred_client']= ClientCredentialsAuth( + address=self.cfg['rest_api']['cred_url'], + token_url=self.cfg['rest_api']['oauth_url'], + client_id=self.cfg['rest_api']['oauth_client_id'], + client_secret=self.cfg['rest_api']['oauth_client_secret'], + ) + except Exception: + logger.warning('failed to connect to rest api: %r', + self.cfg['rest_api'].get('url',''), exc_info=True) + try: return getattr(plugin_module, 'Grid')(**kwargs) except Exception: