mirror of
https://gitlab.com/wgp/dougal/software.git
synced 2025-12-06 11:27:09 +00:00
Send Ocp-Apim-Subscription-Key with ASAQC requests
This commit is contained in:
@@ -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, {
|
||||
|
||||
@@ -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 ]
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
};
|
||||
@@ -1,3 +1,4 @@
|
||||
module.exports = {
|
||||
authorisation: require('./authorisation'),
|
||||
post: require('./post')
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user