Skip to content

Commit

Permalink
Merge pull request #6 from grycap/dev-calarcon
Browse files Browse the repository at this point in the history
Added option to initialize client with an already generated token
  • Loading branch information
catttam authored May 12, 2023
2 parents f578799 + e411dce commit 8320af9
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
4 changes: 3 additions & 1 deletion oscar_python/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,11 @@ def get_headers(c):
usr_pass_as_bytes = bytes(c.user+":"+c.password,"utf-8")
usr_pass_base_64 = base64.b64encode(usr_pass_as_bytes).decode("utf-8")
return {"Authorization": "Basic "+ usr_pass_base_64}
if c._AUTH_TYPE == "oidc":
if c._AUTH_TYPE == "oidc-agent":
token = agent.get_access_token(c.shortname)
return get_headers_with_token(token)
if c._AUTH_TYPE == "oidc":
return get_headers_with_token(c.oidc_token)

""" Function to generate headers with token auth """
def get_headers_with_token(token):
Expand Down
17 changes: 14 additions & 3 deletions oscar_python/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
import json
import yaml
import liboidcagent as agent
import oscar_python._utils as utils
#import oscar_python._utils as utils
import _utils as utils
from oscar_python.storage import Storage

_INFO_PATH = "/system/info"
Expand All @@ -38,6 +39,8 @@ def __init__(self, options) -> None:
self.set_auth_type(options)
if self._AUTH_TYPE == 'basicauth':
self.basic_auth_client(options)
if self._AUTH_TYPE == 'oidc-agent':
self.oidc_agent_client(options)
if self._AUTH_TYPE == 'oidc':
self.oidc_client(options)

Expand All @@ -48,21 +51,29 @@ def basic_auth_client(self, options):
self.password = options['password']
self.ssl = bool(options['ssl'])

def oidc_client(self, options):
def oidc_agent_client(self, options):
self.id = options['cluster_id']
self.endpoint = options['endpoint']
self.shortname = options['shortname']
self.ssl = bool(options['ssl'])

def oidc_client(self, options):
self.id = options['cluster_id']
self.endpoint = options['endpoint']
self.oidc_token = options['oidc_token']
self.ssl = bool(options['ssl'])

def set_auth_type(self, options):
if 'user' in options:
self._AUTH_TYPE = "basicauth"
elif 'shortname' in options:
self._AUTH_TYPE = "oidc"
self._AUTH_TYPE = "oidc-agent"
try:
agent.get_access_token(options['shortname'])
except agent.OidcAgentError as e:
print("ERROR oidc-agent: {}".format(e))
elif 'oidc_token' in options:
self._AUTH_TYPE == "oidc"
else:
raise ValueError("Unrecognized authentication credentials in options")

Expand Down
2 changes: 1 addition & 1 deletion version.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@
"""Stores the package version."""


__version__ = '1.1.0-beta2'
__version__ = '1.1.0-beta3'

0 comments on commit 8320af9

Please sign in to comment.