Commit 00d21967 authored by Sergio Gimenez's avatar Sergio Gimenez
Browse files

fix: temp fix to dynamically grab the keycloak url

parent 5b6c3c8d
Loading
Loading
Loading
Loading
+16 −14
Original line number Original line Diff line number Diff line
@@ -42,7 +42,22 @@ app.app.config['MONGODB_SETTINGS'] = {
    'host': 'mongodb://' + MONGO_HOST + ':' + MONGO_PORT + '/federation-manager'
    'host': 'mongodb://' + MONGO_HOST + ':' + MONGO_PORT + '/federation-manager'
}
}
DB = MongoEngine(app.app)
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"])
@app.route("/", methods=["GET"])
@@ -50,21 +65,8 @@ def documentation():
    """Endpoint to retrieve documentation"""
    """Endpoint to retrieve documentation"""
    return render_template("swaggerui.html")
    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():
def main():
    edit_openapi_file()

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