Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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**
Expand Down
4 changes: 2 additions & 2 deletions oscar_python/_oidc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
19 changes: 14 additions & 5 deletions oscar_python/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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:
Expand All @@ -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
Expand Down Expand Up @@ -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")
Copy link
Member

@esparig esparig Oct 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's better to preserve the original exception message to improve debugging.

try:
  #whatever
except IOError as e:
  raise Exception("Couldn't read script") from e


# cpu parameter has to be string on the request
Expand Down Expand Up @@ -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):
Expand Down
3 changes: 2 additions & 1 deletion tests/test_oidc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down