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

Merge branch 'hotfix/remove-hardcoded-token-url' into 'main'

Hotfix/remove hardcoded token url

See merge request !7
parents 1afe9a53 467bbc2b
Loading
Loading
Loading
Loading
Loading
+1 −1
Original line number Original line Diff line number Diff line
@@ -69,7 +69,7 @@ experiences across markets.


#### Option A: Docker Compose (Recommended)
#### Option A: Docker Compose (Recommended)
   ```bash
   ```bash
   docker-compose up -d
   docker compose up -d
   ```
   ```
   This starts:
   This starts:
   - Federation Manager (port 8990)
   - Federation Manager (port 8990)
+1 −0
Original line number Original line Diff line number Diff line
@@ -6,6 +6,7 @@ client2_secret = 2mhznERfWclLDuVojY77Lp4Qd2r4e8Ms
scope = fed-mgmt
scope = fed-mgmt
host = keycloak
host = keycloak
port = 8080
port = 8080
realm = federation


[server]
[server]
host = 127.0.0.1
host = 127.0.0.1
+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)