diff --git a/README.md b/README.md index 60aab71afe59e901e6b71507df0255b96945df65..911fd5ce9810a50337b929cbe647729069df07e2 100644 --- a/README.md +++ b/README.md @@ -69,7 +69,7 @@ experiences across markets. #### Option A: Docker Compose (Recommended) ```bash - docker-compose up -d + docker compose up -d ``` This starts: - Federation Manager (port 8990) diff --git a/src/conf/config.cfg.sample b/src/conf/config.cfg.sample index 28f23ad7be3a90af35162bfe0ae93dec358e202b..2a44cab8f1f3d3d60d652f39ccd480dcd206fb9d 100644 --- a/src/conf/config.cfg.sample +++ b/src/conf/config.cfg.sample @@ -6,6 +6,7 @@ client2_secret = 2mhznERfWclLDuVojY77Lp4Qd2r4e8Ms scope = fed-mgmt host = keycloak port = 8080 +realm = federation [server] host = 127.0.0.1 diff --git a/src/main.py b/src/main.py index 22b2953cd4c87a93168754a3102621c3016fe7da..566bc8408a1250335e52292a0d8f4a520d77cb48 100644 --- a/src/main.py +++ b/src/main.py @@ -42,7 +42,22 @@ app.app.config['MONGODB_SETTINGS'] = { 'host': 'mongodb://' + MONGO_HOST + ':' + MONGO_PORT + '/federation-manager' } DB = MongoEngine(app.app) -app.add_api('swagger.yaml', arguments={'title': 'Federation Management Service'}, pythonic_params=True) + +# Load the swagger file and update the tokenUrl dynamically +with open("swagger/swagger.yaml", 'r') as f: + swagger_spec = yaml.safe_load(f) + +token_url = f"http://{KEYCLOAK_HOST}:{KEYCLOAK_PORT}/realms/{KEYCLOAK_REALM}/protocol/openid-connect/token" +swagger_spec['components']['securitySchemes']['oAuth2ClientCredentials']['flows']['clientCredentials']['tokenUrl'] = token_url + +# Update the static openapi.yaml file for the UI +try: + with open("static/openapi.yaml", "w") as f: + yaml.dump(swagger_spec, f) +except Exception as e: + print(f"Error updating static/openapi.yaml: {e}") + +app.add_api(swagger_spec, arguments={'title': 'Federation Management Service'}, pythonic_params=True) @app.route("/", methods=["GET"]) @@ -50,21 +65,8 @@ 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)