diff --git a/services/web/scripts/ukamf/check-certs.js b/services/web/scripts/ukamf/check-certs.js index aa00530cc5..8a85190be9 100644 --- a/services/web/scripts/ukamf/check-certs.js +++ b/services/web/scripts/ukamf/check-certs.js @@ -1,5 +1,3 @@ -'use strict' - /** * Checks that all institutional sso provider certs are still current with the * data provided by the ukamf export file. @@ -10,18 +8,13 @@ * http://metadata.ukfederation.org.uk/ */ -const { Certificate } = require('@fidm/x509') -const UKAMFDB = require('./ukamf-db') -const V1Api = require('../../app/src/Features/V1/V1Api').promises -const { db, waitForDb } = require('../../app/src/infrastructure/mongodb') -const moment = require('moment') +import { Certificate } from '@fidm/x509' +import UKAMFDB from './ukamf-db.js' +import V1ApiModule from '../../app/src/Features/V1/V1Api.js' +import { db, waitForDb } from '../../app/src/infrastructure/mongodb.js' +import moment from 'moment' -waitForDb() - .then(main) - .catch(err => { - console.error(err.stack) - }) - .then(() => process.exit()) +const { promises: V1Api } = V1ApiModule async function main() { const [, , file] = process.argv @@ -96,3 +89,11 @@ async function getActiveProviderIds() { 'samlIdentifiers.externalUserId': { $exists: true }, }) } + +try { + await waitForDb() + await main() +} catch (error) { + console.error(error.stack) +} +process.exit() diff --git a/services/web/scripts/ukamf/check-idp-metadata.js b/services/web/scripts/ukamf/check-idp-metadata.js index 1a3439154e..d72bb834bb 100644 --- a/services/web/scripts/ukamf/check-idp-metadata.js +++ b/services/web/scripts/ukamf/check-idp-metadata.js @@ -4,11 +4,11 @@ Run with: node check-idp-metadata /path/idp-metadata.xml */ -const { Certificate } = require('@fidm/x509') -const _ = require('lodash') -const moment = require('moment') -const fs = require('fs-extra') -const xml2js = require('xml2js') +import { Certificate } from '@fidm/x509' +import _ from 'lodash' +import moment from 'moment' +import fs from 'fs-extra' +import xml2js from 'xml2js' function checkCertDates(signingKey) { let cert = _.get(signingKey, [ diff --git a/services/web/scripts/ukamf/metadata-processor.js b/services/web/scripts/ukamf/metadata-processor.js index 5f0c1c1d21..43050a9909 100644 --- a/services/web/scripts/ukamf/metadata-processor.js +++ b/services/web/scripts/ukamf/metadata-processor.js @@ -1,5 +1,3 @@ -'use strict' - /** * Run with: node metadata-processor /path/ukamf.xml http://idp/entity/id * @@ -11,14 +9,9 @@ * The entity id should be provided by the university. */ -const { Certificate } = require('@fidm/x509') -const moment = require('moment') - -const UKAMFDB = require('./ukamf-db') - -main().catch(err => { - console.error(err.stack) -}) +import { Certificate } from '@fidm/x509' +import moment from 'moment' +import UKAMFDB from './ukamf-db.js' async function main() { const [, , file, entityId] = process.argv @@ -71,3 +64,9 @@ async function main() { console.log('!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!') } } + +try { + await main() +} catch (error) { + console.error(error) +} diff --git a/services/web/scripts/ukamf/package.json b/services/web/scripts/ukamf/package.json index 3758ffd415..a491026d75 100644 --- a/services/web/scripts/ukamf/package.json +++ b/services/web/scripts/ukamf/package.json @@ -1,5 +1,6 @@ { "devDependencies": { "@fidm/x509": "^1.2.1" - } + }, + "type": "module" } diff --git a/services/web/scripts/ukamf/ukamf-db.js b/services/web/scripts/ukamf/ukamf-db.js index cde8d16860..6c50878762 100644 --- a/services/web/scripts/ukamf/ukamf-db.js +++ b/services/web/scripts/ukamf/ukamf-db.js @@ -1,9 +1,6 @@ -'use strict' - -const fs = require('fs-extra') -const xml2js = require('xml2js') - -const UKAMFEntity = require('./ukamf-entity') +import fs from 'fs-extra' +import xml2js from 'xml2js' +import UKAMFEntity from './ukamf-entity.js' class UKAMFDB { constructor(file) { @@ -28,4 +25,4 @@ class UKAMFDB { } } -module.exports = UKAMFDB +export default UKAMFDB diff --git a/services/web/scripts/ukamf/ukamf-entity.js b/services/web/scripts/ukamf/ukamf-entity.js index 689db8c37c..4cbe74512e 100644 --- a/services/web/scripts/ukamf/ukamf-entity.js +++ b/services/web/scripts/ukamf/ukamf-entity.js @@ -1,6 +1,4 @@ -'use strict' - -const _ = require('lodash') +import _ from 'lodash' class UKAMFEntity { constructor(data) { @@ -68,4 +66,4 @@ class UKAMFEntity { } } -module.exports = UKAMFEntity +export default UKAMFEntity