fix(proxy/backup.run): handle multiple self licenses

See xoa-support#3730

Previous code would fail if the first license returned was already expired.
This commit is contained in:
Julien Fontanet 2021-05-16 16:51:32 +02:00
parent d1dfd93e15
commit c7f1469e1f
2 changed files with 7 additions and 3 deletions

View File

@ -153,6 +153,10 @@ export default class Appliance {
// A proxy can be bound to a unique license // A proxy can be bound to a unique license
getSelfLicense() { 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)
})
} }
} }

View File

@ -107,8 +107,8 @@ export default class Backups {
async function () { async function () {
if (!__DEV__) { if (!__DEV__) {
const license = await app.appliance.getSelfLicense() const license = await app.appliance.getSelfLicense()
if (license === undefined || license.expires < Date.now()) { if (license === undefined) {
throw new Error('the proxy license is not valid') throw new Error('no valid proxy license')
} }
} }
return run.apply(this, arguments) return run.apply(this, arguments)