From c7f1469e1f2509616f6c990c924613822378c295 Mon Sep 17 00:00:00 2001 From: Julien Fontanet Date: Sun, 16 May 2021 16:51:32 +0200 Subject: [PATCH] fix(proxy/backup.run): handle multiple self licenses See xoa-support#3730 Previous code would fail if the first license returned was already expired. --- @xen-orchestra/proxy/src/app/mixins/appliance.mjs | 6 +++++- @xen-orchestra/proxy/src/app/mixins/backups.mjs | 4 ++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/@xen-orchestra/proxy/src/app/mixins/appliance.mjs b/@xen-orchestra/proxy/src/app/mixins/appliance.mjs index 582ca3f27..9cb578aa9 100644 --- a/@xen-orchestra/proxy/src/app/mixins/appliance.mjs +++ b/@xen-orchestra/proxy/src/app/mixins/appliance.mjs @@ -153,6 +153,10 @@ export default class Appliance { // A proxy can be bound to a unique license getSelfLicense() { - return Disposable.use(getUpdater(), _ => _.call('getSelfLicenses').then(licenses => licenses[0])) + return Disposable.use(getUpdater(), async updater => { + const licenses = await updater.call('getSelfLicenses') + const now = Date.now() + return licenses.find(({ expires }) => expires === undefined || expires > now) + }) } } diff --git a/@xen-orchestra/proxy/src/app/mixins/backups.mjs b/@xen-orchestra/proxy/src/app/mixins/backups.mjs index 448cbcd29..002e13670 100644 --- a/@xen-orchestra/proxy/src/app/mixins/backups.mjs +++ b/@xen-orchestra/proxy/src/app/mixins/backups.mjs @@ -107,8 +107,8 @@ export default class Backups { async function () { if (!__DEV__) { const license = await app.appliance.getSelfLicense() - if (license === undefined || license.expires < Date.now()) { - throw new Error('the proxy license is not valid') + if (license === undefined) { + throw new Error('no valid proxy license') } } return run.apply(this, arguments)