Commit ba325682 authored by Sergio Gimenez's avatar Sergio Gimenez
Browse files

Merge branch '8-define-oauth2-server-url-as-a-configurable-parameter' into 'main'

parametrize oauth  url in config

Closes #8

See merge request !5
parents 43632fa5 a389dc7f
Loading
Loading
Loading
Loading
Loading
+17 −0
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ Federation Manager application
import connexion
from flask import render_template
import encoder
import yaml
from flask_mongoengine import MongoEngine
from configparser import ConfigParser

@@ -30,6 +31,9 @@ HOST = CONFIG.get("server", "host")
PORT = int(CONFIG.get("server", "port"))
MONGO_HOST = CONFIG.get("mongodb", "host")
MONGO_PORT = CONFIG.get("mongodb", "port")
KEYCLOAK_HOST = CONFIG.get("keycloak", "host")
KEYCLOAK_PORT = int(CONFIG.get("keycloak", "port"))
KEYCLOAK_REALM = CONFIG.get("keycloak", "realm")


app = connexion.App(__name__, specification_dir='./swagger/')
@@ -46,8 +50,21 @@ def documentation():
    """Endpoint to retrieve documentation"""
    return render_template("swaggerui.html")

def edit_openapi_file():
    with open("static/openapi.yaml", "r") as f:
        openapi_data = yaml.safe_load(f)

    token_url = f"http://{KEYCLOAK_HOST}:{KEYCLOAK_PORT}/realms/{KEYCLOAK_REALM}/protocol/openid-connect/token"
    
    # Update the tokenUrl
    openapi_data['components']['securitySchemes']['oAuth2ClientCredentials']['flows']['clientCredentials']['tokenUrl'] = token_url

    with open("static/openapi.yaml", "w") as f:
        yaml.dump(openapi_data, f)

def main():
    edit_openapi_file()

    app.run(host=HOST, port=PORT, threaded=True)


+2004 −2004

File changed.

Preview size limit exceeded, changes collapsed.