Send Ocp-Apim-Subscription-Key with ASAQC requests

This commit is contained in:
D. Berge
2021-10-04 21:00:41 +02:00
parent 14541bcb95
commit 927ef71ecc
4 changed files with 28 additions and 1 deletions

View File

@@ -32,6 +32,7 @@ function httpsAgent () {
* https://api.equinor.com/docs/services/vessel-track/operations/FileUploadEncoded
*/
async function despatchPayload(payload) {
cfg.args.headers["Ocp-Apim-Subscription-Key"] = process.env.DOUGAL_ASAQC_SUBSCRIPTION_KEY;
try {
const res = await fetch(cfg.url, {

View File

@@ -69,7 +69,7 @@ app.use((req, res, next) => {
app.map({
'/vt/v1/api/upload-file-encoded': {
post: [ mw.post ]
post: [ mw.authorisation, mw.post ]
}
});

View File

@@ -0,0 +1,25 @@
/**
* This method imitates the ASAQC header-based
* authorisation.
*
* The valid subscription token should be defined
* in the $DOUGAL_ASAQC_SUBSCRIPTION_KEY environent
* variable (e.g., by inclusion in .dougalrc).
*/
module.exports = async function (req, res, next) {
try {
const authSent = req.get("Ocp-Apim-Subscription-Key");
const authExpected = process.env.DOUGAL_ASAQC_SUBSCRIPTION_KEY;
if (authSent == authExpected || !authSent) {
next()
} else {
throw {status: 401, message: "Not authorised"};
}
} catch (err) {
next(err);
}
};

View File

@@ -1,3 +1,4 @@
module.exports = {
authorisation: require('./authorisation'),
post: require('./post')
};