Skip to content

Commit 3fe4058

Browse files
feat: add Keycloak details in CI run
1 parent 1cde1ff commit 3fe4058

4 files changed

Lines changed: 64 additions & 29 deletions

File tree

.github/workflows/docker.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,16 @@ jobs:
7979
- name: Change pyproject.toml override MUG
8080
run: sed -i 's/-override ~/-override[marc21] ~/g' pyproject.toml
8181

82+
- name: Set keycloak in invenio.cfg via script
83+
run: |
84+
source .venv/bin/activate
85+
if [[ ${{ !startsWith( github.ref, 'refs/tags') }}]]; then
86+
KEYCLOAK_NODE="cyverse"
87+
else
88+
KEYCLOAK_NODE="meduni"
89+
python auth/yaml2py.py --source-filename auth/kc-settings-pool.yaml --dest-filename themes/MUG/invenio.cfg --node $KEYCLOAK_NODE --placeholder "<insert_keycloak_config_via_ci>"
90+
deactivate
91+
8292
- name: Relock uv
8393
run: |
8494
source .venv/bin/activate

auth/kc-settings-pool.yaml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
cyverse:
2+
title: "Cyverse SSO"
3+
description: Cyverse SSO
4+
base_url: https://keycloak.cyverse.at
5+
realm: CyVerse
6+
app_key: CYVERSE_KEYCLOAK_APP_CREDENTIALS
7+
legacy_url_path: False
8+
9+
meduni:
10+
title: Meduni SSO
11+
description: Meduni SSO
12+
base_url: https://openid.medunigraz.at/
13+
realm: invenioRDM
14+
app_key: KEYCLOAK_APP_CREDENTIALS
15+
legacy_url_path: False

auth/yaml2py.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
"""
2+
Script that injects a given yaml config into arguments of an invenio.cfg class.
3+
"""
4+
5+
import yaml
6+
import sys
7+
import argparse
8+
9+
parser = argparse.ArgumentParser()
10+
11+
parser.add_argument('--source-filename', type=str, required=True)
12+
parser.add_argument('--dest-filename', type=str, required=True)
13+
parser.add_argument('--node', type=str, required=True)
14+
parser.add_argument('--placeholder', type=str, required=True)
15+
16+
args = parser.parse_args()
17+
18+
auth_config = ""
19+
with open(args.source_filename) as f:
20+
data = yaml.safe_load(f)
21+
for key, _ in data.items():
22+
if key == args.node:
23+
for node_key, val in data[key].items():
24+
if isinstance(val, str):
25+
auth_config += f'{node_key}="{val}",\n'
26+
else:
27+
auth_config += f'{node_key}={val},\n'
28+
29+
with open(args.dest_filename, "r") as f:
30+
config = f.read()
31+
config = config.replace(args.placeholder, auth_config)
32+
33+
with open(args.dest_filename, "w") as f:
34+
f.write(config)

themes/MUG/invenio.cfg

Lines changed: 5 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -392,39 +392,15 @@ GLOBAL_SEARCH_SCHEMAS = {
392392
# Keycloak configurations
393393
# ============================================================================
394394
_keycloak_helper = KeycloakSettingsHelper(
395-
title="Meduni SSO",
396-
description="Meduni SSO",
397-
base_url="https://openid.medunigraz.at/",
398-
realm="invenioRDM",
399-
app_key="KEYCLOAK_APP_CREDENTIALS",
400-
legacy_url_path=False
395+
<insert_keycloak_config_via_ci>
401396
)
402-
403-
OAUTHCLIENT_KEYCLOAK_REALM_URL = _keycloak_helper.realm_url
404-
OAUTHCLIENT_KEYCLOAK_USER_INFO_URL = _keycloak_helper.user_info_url
405-
OAUTHCLIENT_KEYCLOAK_VERIFY_EXP = True # whether to verify the expiration date of tokens
406-
OAUTHCLIENT_KEYCLOAK_VERIFY_AUD = True # whether to verify the audience tag for tokens
407-
OAUTHCLIENT_KEYCLOAK_AUD = "inveniordm" # probably the same as the client ID
408-
OAUTHCLIENT_KEYCLOAK_USER_INFO_FROM_ENDPOINT = True
409-
410-
_cyverse_keycloak_helper = KeycloakSettingsHelper(
411-
title="Cyverse SSO",
412-
description="Cyverse SSO",
413-
base_url="https://keycloak.cyverse.at",
414-
realm="CyVerse",
415-
app_key="CYVERSE_KEYCLOAK_APP_CREDENTIALS",
416-
)
417-
OAUTHCLIENT_CYVERSE_REALM_URL = _cyverse_keycloak_helper.realm_url
418-
OAUTHCLIENT_CYVERSE_USER_INFO_URL = _cyverse_keycloak_helper.user_info_url
419-
OAUTHCLIENT_CYVERSE_VERIFY_EXP = True
420-
OAUTHCLIENT_CYVERSE_VERIFY_AUD = True
421-
OAUTHCLIENT_CYVERSE_AUD = "inveniordm"
422-
OAUTHCLIENT_CYVERSE_USER_INFO_FROM_ENDPOINT = True
423-
397+
"""
398+
Keycloak settings like base_url and realm should be set by CI by replacing for
399+
the placeholder this instance.
400+
"""
424401

425402
OAUTHCLIENT_REMOTE_APPS = {
426403
"keycloak": _keycloak_helper.remote_app,
427-
"cyverse": _cyverse_keycloak_helper.remote_app,
428404
}
429405

430406
## SET THE CREDENTIALS via .env

0 commit comments

Comments
 (0)