diff --git a/README.md b/README.md index 286aacb..360646f 100644 --- a/README.md +++ b/README.md @@ -77,6 +77,7 @@ and `scopes`: 'refresh_token':'token', 'scopes': ["openid", "profile", "email"], 'token_endpoint': "http://issuer.com/token", + 'client_id': "your_client_id" 'ssl':'True'} client = Client(options = options_oidc_auth) @@ -201,6 +202,8 @@ logs = client.get_job_logs("service_name", "job_id") # returns an http response ``` python # get a list of jobs in a service log_list = client.list_jobs("service_name") # returns an http response +# to get more jobs use the page parameter +log_list = client.list_jobs("service_name",page="token_to_next_page") # returns an http response ``` **remove_job** diff --git a/oscar_python/_oidc.py b/oscar_python/_oidc.py index f094bb7..b6321de 100644 --- a/oscar_python/_oidc.py +++ b/oscar_python/_oidc.py @@ -77,14 +77,14 @@ def is_access_token_expired(token): return True @staticmethod - def refresh_access_token(refresh_token, scopes, token_endpoint): + def refresh_access_token(refresh_token, scopes, token_endpoint, client_id="token-portal"): """ Refresh the access token using the refresh token """ data = { 'grant_type': 'refresh_token', 'refresh_token': refresh_token, - 'client_id': 'token-portal', + 'client_id': client_id, 'scope': ' '.join(scopes) } diff --git a/oscar_python/client.py b/oscar_python/client.py index 62a87b2..834ee45 100644 --- a/oscar_python/client.py +++ b/oscar_python/client.py @@ -41,6 +41,7 @@ # Default values for OIDC refresh token using EGI CheckIn _DEFAULT_SCOPES = ['openid', 'email', 'profile', 'voperson_id', 'eduperson_entitlement'] _DEFAULT_TOKEN_ENDPOINT = 'https://aai.egi.eu/auth/realms/egi/protocol/openid-connect/token' +_DEFAULT_CLIENT_ID = 'token-portal' class Client(DefaultClient): @@ -72,6 +73,8 @@ def oidc_client(self, options): self.token_endpoint = options.get('token_endpoint', _DEFAULT_TOKEN_ENDPOINT) self.ssl = bool(options['ssl']) + self.client_id = options.get('client_id', + _DEFAULT_CLIENT_ID) def set_auth_type(self, options): if 'user' in options: @@ -91,7 +94,8 @@ def get_access_token(self): if self.refresh_token and OIDC.is_access_token_expired(self.oidc_token): self.oidc_token = OIDC.refresh_access_token(self.refresh_token, self.scopes, - self.token_endpoint) + self.token_endpoint, + self.client_id) return self.oidc_token """ Creates a generic storage client to interact with the storage providers @@ -132,9 +136,14 @@ def _check_fdl_definition(self, fdl_path): except KeyError as err: raise Exception("FDL clusterID does not match current clusterID: {0}".format(err)) try: - with open(svc["script"]) as s: + if os.path.isabs(svc["script"]): + script_path = svc["script"] + else: + fdl_directory = os.path.dirname(fdl_path) + script_path = os.path.join(fdl_directory, svc['script']) + with open(script_path) as s: svc["script"] = s.read() - except IOError: + except IOError as e: raise Exception("Couldn't read script") # cpu parameter has to be string on the request @@ -205,8 +214,8 @@ def get_job_logs(self, svc, job): return utils.make_request(self, _LOGS_PATH+"/"+svc+"/"+job, _GET) """ List a service jobs """ - def list_jobs(self, svc): - return utils.make_request(self, _LOGS_PATH+"/"+svc, _GET) + def list_jobs(self, svc, page=""): + return utils.make_request(self, _LOGS_PATH+"/"+svc+"?page="+page, _GET) """ Remove a service job """ def remove_job(self, svc, job): diff --git a/tests/test_oidc.py b/tests/test_oidc.py index ceb4877..f699369 100644 --- a/tests/test_oidc.py +++ b/tests/test_oidc.py @@ -24,7 +24,8 @@ def test_refresh_access_token(): mock_post.return_value = mock_response access_token = OIDC.refresh_access_token("old_refresh_token", ["openid", "profile", "email"], - "http://test.com/token") + "http://test.com/token", + "token-portal") assert access_token == "new_access_token" mock_post.assert_called_once_with(