Skip to content

Commit

Permalink
fix bug in getTrustedSubject function
Browse files Browse the repository at this point in the history
  • Loading branch information
aramovic79 committed Jan 30, 2025
1 parent 43822b6 commit edd7152
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 13 deletions.
8 changes: 3 additions & 5 deletions lib/authentication.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,10 @@ function getAuthData(type) {

async function fetchTrustedSubject(endpoint) {
try {
// TODO: Implement fetching trusted subject from UCL endpoint
Logger.log('TrustedSubjectService:', endpoint);
return null;
// const resp = await fetch(endpoint);
// const jsonBody = (await resp.json());
// return jsonBody.certSubject;
const resp = await fetch(endpoint);
const jsonBody = (await resp.json());
return jsonBody.certSubject;
} catch (error) {
Logger.error('TrustedSubjectService:', error.message);
return null;
Expand Down
11 changes: 6 additions & 5 deletions lib/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ const { authenticate, getTrustedSubjects } = require("./authentication");
cds.on("bootstrap", async (app) => {
try {
// TODO: Renewal of trustedSubjects every N days ??
const trustedSubjects = await getTrustedSubjects();
cds.context = {
...cds.context,
trustedSubjects, // TODO: Store trusted subjects in context ??
};
if (!cds.context) {
cds.context = cds.context || {};
}
if (!cds.context.trustedSubjects) {
cds.context.trustedSubjects = await getTrustedSubjects();// TODO: Store trusted subjects in context or somewhere else??
}
} catch (error) {
Logger.error(error, 'Error while loading service');
}
Expand Down
4 changes: 1 addition & 3 deletions xmpl/default-env.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,11 @@
"ORD_BASE_URL": "http://localhost:8080",
"ORD_SOURCE_TYPE": "local",
"ORD_DIRECTORY": "./example",
"ORD_AUTH": "basic",
"ORD_AUTH": "ucl-mtls",
"APP_USERS": {
"admin": "secret"
},
"UCL_MTLS_ENDPOINTS": [
"https://endpoint1.example.com/v1/info",
"https://endpoint2.example.com/v1/info",
"https://compass-gateway.mps.kyma.cloud.sap/v1/info"
]
}

0 comments on commit edd7152

Please sign in to comment.