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
7 changes: 5 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,14 @@ on:

jobs:
test:
runs-on: ubuntu-22.04
runs-on: ubuntu-24.04
strategy:
matrix:
python:
- 3.8
- "3.10"
- "3.11"
- "3.12"
- "3.13"
Comment on lines +13 to +20

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

is this bump because cc-auth doesn't support python3.8?
I would leave this as a separate commit/pr and update tox.ini as well to match, just to make it clear that this is a "deprecate python 3.8 and 3.9, test 3.10 to 3.13" change

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I'll leave this in the PR, but it wasn't ccauth specifically. I think it was setuptools in general was not playing nice in GHA.

steps:
- uses: actions/checkout@v4
- name: Set up Python 3.x
Expand Down
77 changes: 70 additions & 7 deletions chi/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,15 @@
EDGE_RESOURCE_API_URL = os.getenv(
"EDGE_RESOURCE_API_URL", "https://chameleoncloud.org/edge-hw-discovery/devices"
)
DEFAULT_CLIENT_ID = "chi-cli-device-token"
DEFAULT_DISCOVERY_ENDPOINT = (
"https://auth.chameleoncloud.org/auth/realms/chameleon"
"/.well-known/openid-configuration"
)
DEFAULT_PROTOCOL = "openid"
DEFAULT_IDENTITY_PROVIDER = "chameleon"
DEFAULT_SCOPE = "openid"
DEFAULT_PROJECT_DOMAIN_NAME = "chameleon"


def default_key_name():
Expand Down Expand Up @@ -74,6 +83,7 @@ def default_key_name():
_session = None
_sites = {}
_lease_id = None
_device_auth = False

version = "1.1"

Expand Down Expand Up @@ -366,7 +376,7 @@ def use_site(site_name: str) -> None:
Args:
site_name (str): The name of the site, e.g., "CHI@UC".
"""
global _sites
global _sites, _session
if not _sites:
try:
_sites = list_sites()
Expand All @@ -392,6 +402,9 @@ def use_site(site_name: str) -> None:
)
)

_session = None

set("project_domain_name", DEFAULT_PROJECT_DOMAIN_NAME)
set("auth_url", f"{site['web']}:5000/v3")
set("region_name", site["name"])

Expand All @@ -404,6 +417,25 @@ def use_site(site_name: str) -> None:
print("\n".join(output))


def use_device_auth(enable: bool = True) -> None:
"""Enable or disable device authorization for subsequent sessions.

Call `use_device_auth()` before creating a session (or before `use_site`)
to opt into the device authorization flow. Pass `False` to disable.

Args:
enable (bool): True to enable device auth, False to disable.
"""
global _device_auth, _session
_device_auth = bool(enable)

_session = None
if _device_auth:
print("Device authorization enabled.")
else:
print("Device authorization disabled.")


def choose_site(default: str = None) -> None:
"""
Displays a dropdown menu to select a chameleon site.
Expand Down Expand Up @@ -650,13 +682,42 @@ def session():
Returns:
keystoneauth1.session.Session: the authentication session object.
"""
global _session
global _session, _device_auth
if not _session:
auth = loading.load_auth_from_conf_options(cfg.CONF, CONF_GROUP)
sess = SessionLoader().load_from_conf_options(cfg.CONF, CONF_GROUP, auth=auth)
_session = loading.load_adapter_from_conf_options(
cfg.CONF, CONF_GROUP, session=sess
)
if _device_auth:
auth_url = get("auth_url")
try:
from ccauth.plugin import ChameleonDeviceAuth
except ImportError as e:
raise CHIValueError(
"Device auth requested but package 'ccauth' is not installed."
" Install 'ccauth' to use device authorization."
) from e

plugin = ChameleonDeviceAuth(
auth_url=auth_url,
identity_provider=DEFAULT_IDENTITY_PROVIDER,
protocol=DEFAULT_PROTOCOL,
client_id=DEFAULT_CLIENT_ID,
discovery_endpoint=DEFAULT_DISCOVERY_ENDPOINT,
scope=DEFAULT_SCOPE,
project_name=get("project_name"),
project_domain_name=get("project_domain_name"),
)
Comment thread
Mark-Powers marked this conversation as resolved.
sess = SessionLoader().load_from_conf_options(
cfg.CONF, CONF_GROUP, auth=plugin
)
_session = loading.load_adapter_from_conf_options(
cfg.CONF, CONF_GROUP, session=sess
)
else:
auth = loading.load_auth_from_conf_options(cfg.CONF, CONF_GROUP)
sess = SessionLoader().load_from_conf_options(
cfg.CONF, CONF_GROUP, auth=auth
)
_session = loading.load_adapter_from_conf_options(
cfg.CONF, CONF_GROUP, session=sess
)
return _session


Expand All @@ -671,8 +732,10 @@ def reset():
"""
global _session
global _sites
global _device_auth
_session = None
_sites = {}
_device_auth = False
cfg.CONF.reset()
_set_auth_plugin(
os.getenv("OS_AUTH_TYPE", os.getenv("OS_AUTH_METHOD", DEFAULT_AUTH_TYPE))
Expand Down
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ python-manilaclient
python-neutronclient
python-novaclient
python-swiftclient
python-zunclient
git+https://github.com/chameleoncloud/python-zunclient
ipython
ipydatagrid
ipywidgets
networkx
matplotlib
pandas

git+https://github.com/ChameleonCloud/ccauth.git

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

a reminder to me to get this on pypi

Loading