Skip to content

Commit 072cb0b

Browse files
feat: add Keycloak details in CI run
1 parent 1cde1ff commit 072cb0b

4 files changed

Lines changed: 53 additions & 29 deletions

File tree

.github/workflows/docker.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ name: build and push docker image
33
env:
44
REGISTRY: ghcr.io
55
IMAGE_NAME: ${{ github.repository }}
6+
KEYCLOAK_NODE: cyverse
67

78
on:
89
push:
@@ -79,6 +80,12 @@ jobs:
7980
- name: Change pyproject.toml override MUG
8081
run: sed -i 's/-override ~/-override[marc21] ~/g' pyproject.toml
8182

83+
- name: Set keycloak in invenio.cfg via script
84+
run: |
85+
source .venv/bin/activate
86+
python auth/yaml2py.py --source-filename auth/kc-settings-pool.yaml --dest-filename themes/MUG/invenio.cfg --node ${{ env.KEYCLOAK_NODE }} --placeholder "<insert_keycloak_config_via_ci>"
87+
deactivate
88+
8289
- name: Relock uv
8390
run: |
8491
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: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import yaml
2+
import sys
3+
import argparse
4+
5+
parser = argparse.ArgumentParser()
6+
7+
parser.add_argument('--source-filename', type=str, required=True)
8+
parser.add_argument('--dest-filename', type=str, required=True)
9+
parser.add_argument('--node', type=str, required=True)
10+
parser.add_argument('--placeholder', type=str, required=True)
11+
12+
args = parser.parse_args()
13+
14+
auth_config = ""
15+
with open(args.source_filename) as f:
16+
data = yaml.safe_load(f)
17+
for key, _ in data.items():
18+
if key == args.node:
19+
for node_key, val in data[key].items():
20+
if isinstance(val, str):
21+
auth_config += f'{node_key}="{val}",\n'
22+
else:
23+
auth_config += f'{node_key}={val},\n'
24+
25+
with open(args.dest_filename, "r") as f:
26+
config = f.read()
27+
config = config.replace(args.placeholder, auth_config)
28+
29+
with open(args.dest_filename, "w") as f:
30+
f.write(config)

themes/MUG/invenio.cfg

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -392,39 +392,11 @@ 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
)
402397

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-
424-
425398
OAUTHCLIENT_REMOTE_APPS = {
426399
"keycloak": _keycloak_helper.remote_app,
427-
"cyverse": _cyverse_keycloak_helper.remote_app,
428400
}
429401

430402
## SET THE CREDENTIALS via .env

0 commit comments

Comments
 (0)