Skip to content

Commit

Permalink
Merge pull request #170 from ilgrosso/BOOTSTRAP_SP_METADATA
Browse files Browse the repository at this point in the history
Allow to bootstrap SP metadata XML files
  • Loading branch information
damikael authored Sep 14, 2021
2 parents 0d48b74 + 264374c commit 5c19987
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 2 deletions.
3 changes: 2 additions & 1 deletion spid-validator/config/dir.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"DATA": "../data",
"TEMP": "temp"
"TEMP": "temp",
"BOOTSTRAP": "bootstrap"
}
18 changes: 17 additions & 1 deletion spid-validator/server/lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const moment = require("moment");
const CryptoJS = require("crypto-js");
const config_dir = require("../../config/dir.json");
const config_idp = require("../../config/idp.json");
const fs = require("fs-extra");


String.prototype.replaceAll = function(search, replacement) {
Expand Down Expand Up @@ -126,6 +127,21 @@ class Utils {
static atob(buffer) {
return Buffer.from(buffer, 'base64').toString('ascii');
}
}

static readFiles(dirname, onFileContent, onError) {
fs.readdir(dirname, function (err, filenames) {
if (err) {
onError(err);
return;
}
filenames.forEach(function (filename) {
if (filename.indexOf('.xml') > 0) {
let content = fs.readFileSync(dirname + "/" + filename, "utf8");
onFileContent(filename, content);
}
});
});
}
}

module.exports = Utils;
16 changes: 16 additions & 0 deletions spid-validator/server/spid-validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,22 @@ require('./api/response') (app, checkAuth);
// start
if (useHttps) app = https.createServer(httpsCredentials, app);
app.listen(config_server.port, () => {
// import
if (fs.existsSync("../" + config_dir.DATA + "/" + config_dir.BOOTSTRAP)) {
Utility.readFiles("../" + config_dir.DATA + "/" + config_dir.BOOTSTRAP, function (filename, xml) {
let metadataParser = new MetadataParser(xml);

let entityID = metadataParser.getServiceProviderEntityId();
if (entityID === null || entityID === '')
throw new Error("EntityID non specificato");

fs.copyFileSync("../" + config_dir.DATA + "/" + config_dir.BOOTSTRAP + "/" + filename, getEntityDir(entityID) + "/sp-metadata.xml");
database.setMetadata("validator", "000", entityID, "000", "main", entityID, xml);
}, function (err) {
console.error("Could not bootstrap initial SP metadata: ", err);
});
}

// eslint-disable-next-line no-console
console.log("\n" + p.name + "\nversion: " + p.version + "\n\nlistening on port " + config_server.port);
});

0 comments on commit 5c19987

Please sign in to comment.