Skip to content

Commit

Permalink
Replacing envvar by CONF.get()
Browse files Browse the repository at this point in the history
  • Loading branch information
tdviet committed Nov 5, 2023
1 parent 1d79460 commit a4677bf
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 28 deletions.
2 changes: 0 additions & 2 deletions fedcloudclient/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
"site_list_url": "https://raw.githubusercontent.com/tdviet/fedcloudclient/master/config/sites.yaml",
"site_dir": str(Path.home() / ".config/fedcloud/site-config/"),
"oidc_url": "https://aai.egi.eu/auth/realms/egi",
"openstack_auth_protocol": "openid",
"openstack_auth_provider": "egi.eu",
"openstack_auth_type": "v3oidcaccesstoken",
"gocdb_public_url": "https://goc.egi.eu/gocdbpi/public/",
"gocdb_service_group": "org.openstack.nova",
Expand Down
6 changes: 3 additions & 3 deletions fedcloudclient/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,21 +168,21 @@ def openstack_params(func):
help="Only change default values if necessary",
)
@optgroup.option(
"--openstack-auth-protocol",
"--os-protocol",
help="Authentication protocol",
default=CONF.get("os_protocol"),
show_default=True,
metavar="",
)
@optgroup.option(
"--openstack-auth-provider",
"--os-identity-provider",
help="Identity provider",
default=CONF.get("os_identity_provider"),
show_default=True,
metavar="",
)
@optgroup.option(
"--openstack-auth-type",
"--os-auth-type",
help="Authentication type",
default=CONF.get("os_auth_type"),
show_default=True,
Expand Down
47 changes: 24 additions & 23 deletions fedcloudclient/openstack.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
)

DEFAULT_AUTH_TYPE = CONF.get("os_auth_type")
DEFAULT_IDENTITY_PROVIDER = CONF.get("os_identity_provider")
DEFAULT_IDENTITY_PROVIDER = CONF.get("os_identity_provider")
DEFAULT_PROTOCOL = CONF.get("os_protocol")

__OPENSTACK_CLIENT = "openstack"
Expand All @@ -40,9 +40,9 @@

def fedcloud_openstack_full(
oidc_access_token,
openstack_auth_protocol,
openstack_auth_type,
checkin_identity_provider,
os_protocol,
os_auth_type,
os_identity_provider,
site,
vo,
openstack_command,
Expand All @@ -54,11 +54,12 @@ def fedcloud_openstack_full(
:param oidc_access_token: Checkin access token. Passed to openstack client
as --os-access-token
:param openstack_auth_protocol: Checkin protocol (openid, oidc). Passed to
:param os_protocol: Checkin protocol (openi
, oidc). Passed to
openstack client as --os-protocol
:param openstack_auth_type: Checkin authentication type (v3oidcaccesstoken).
:param os_auth_type: Checkin authentication type (v3oidcaccesstoken).
Passed to openstack client as --os-auth-type
:param checkin_identity_provider: Checkin identity provider in mapping (egi.eu).
:param os_identity_provider: Checkin identity provider in mapping (egi.eu).
Passed to openstack client as --os-identity-provider
:param site: site ID in GOCDB
:param vo: VO name
Expand All @@ -74,17 +75,17 @@ def fedcloud_openstack_full(
return __MISSING_VO_ERROR_CODE, f"VO {vo} not found on site {site}\n"

if protocol is None:
protocol = openstack_auth_protocol
protocol = os_protocol

options = (
"--os-auth-url",
endpoint,
"--os-auth-type",
openstack_auth_type,
os_auth_type,
"--os-protocol",
protocol,
"--os-identity-provider",
checkin_identity_provider,
os_identity_provider,
"--os-access-token",
oidc_access_token,
)
Expand Down Expand Up @@ -240,9 +241,9 @@ def openstack(
all_sites,
vo,
openstack_command,
openstack_auth_protocol,
openstack_auth_type,
openstack_auth_provider,
os_protocol,
os_auth_type,
os_identity_provider,
ignore_missing_vo,
json_output,
):
Expand All @@ -267,9 +268,9 @@ def openstack(
executor.submit(
fedcloud_openstack_full,
access_token,
openstack_auth_protocol,
openstack_auth_type,
openstack_auth_provider,
os_protocol,
os_auth_type,
os_identity_provider,
site,
vo,
openstack_command,
Expand All @@ -281,7 +282,7 @@ def openstack(
# Get results and print them
first = True

# Get the result, first come first serve
# Get the result, first come, first served
for future in concurrent.futures.as_completed(results):
site = results[future]
exc_msg = None
Expand Down Expand Up @@ -318,9 +319,9 @@ def openstack_int(
access_token,
site,
vo,
openstack_auth_protocol,
openstack_auth_type,
openstack_auth_provider,
os_protocol,
os_auth_type,
os_identity_provider,
):
"""
Interactive OpenStack client on site and VO
Expand All @@ -334,12 +335,12 @@ def openstack_int(
raise SystemExit(f"Error: VO {vo} not found on site {site}")

if protocol is None:
protocol = openstack_auth_protocol
protocol = os_protocol
my_env = os.environ.copy()
my_env["OS_AUTH_URL"] = endpoint
my_env["OS_AUTH_TYPE"] = openstack_auth_type
my_env["OS_AUTH_TYPE"] = os_auth_type
my_env["OS_PROTOCOL"] = protocol
my_env["OS_IDENTITY_PROVIDER"] = openstack_auth_provider
my_env["OS_IDENTITY_PROVIDER"] = os_identity_provider
my_env["OS_ACCESS_TOKEN"] = access_token
my_env["OS_PROJECT_ID"] = project_id

Expand Down

0 comments on commit a4677bf

Please sign in to comment.