From e53a1d594f7a4661ce914f61d1d710902b5063ac Mon Sep 17 00:00:00 2001 From: Antonio Calanducci Date: Fri, 31 May 2024 10:12:38 +0200 Subject: [PATCH] Fix account legacy and make ServiceClass parametric --- src/config.js | 7 ++++--- src/pep.js | 12 ++++++------ 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/config.js b/src/config.js index 854d3b2..2c73cb0 100644 --- a/src/config.js +++ b/src/config.js @@ -1,13 +1,14 @@ export default { config }; var config = { - "pep_credentials" : "pep_credentials", + "pep_credentials": "pep_credentials", "debug": true, "legacy": true, "accounting": { - "scopes": ["authorized_scope1", "authorizeed_scope2"], + "scopes": ["authorized_scope1", "authorizeed_scope2"], "service_name": "docker_stack_name", - "host": "service_hostname" + "service_class": "Application", + "host": "service_hostname" }, "hosts": [ { diff --git a/src/pep.js b/src/pep.js index ae544d4..e9be656 100644 --- a/src/pep.js +++ b/src/pep.js @@ -46,7 +46,7 @@ function enforce_legacy(r) { var allowedcontexts = context.config["accounting"]["scopes"] debug(context, "Allowed Contexts: " + JSON.stringify(allowedcontexts)); - debug(context, "PEP config:\n" + JSON.stringify(defaultExport["config"], null, 2)) + // debug(context, "PEP config:\n" + JSON.stringify(defaultExport["config"], null, 2)) const token = getGCubeToken(context) if (token != null) { @@ -509,15 +509,15 @@ function buildAccountingRecord_legacy(context) { "recordType": "ServiceUsageRecord", "operationCount": 1, "creationTime": t, - "callerHost": context.request.remoteAddress, - "serviceClass": "ShinyApp", + "callerHost": context.request.headersIn["x-forwarded-for"], + "serviceClass": context.config["accounting"]["service_class"], "callerQualifier": "TOKEN", - "consumerId": context.userinfo.username, + "consumerId": context.userinfo.result.username, "aggregated": true, - "serviceName": context.request.uri.split("app/")[1], + "serviceName": context.config["accounting"]["service_name"], "duration": 0, "maxInvocationTime": 0, - "scope": context.userinfo.context, + "scope": context.userinfo.result.context, "host": context.request.headersIn.host, "startTime": t, "id": uuid(),