-
Notifications
You must be signed in to change notification settings - Fork 10.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
avoid triggering "invalidate" events when an active license is replac…
…ed with another valid license.
- Loading branch information
1 parent
25c1491
commit b5e1a43
Showing
10 changed files
with
151 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,40 @@ | ||
import { EventEmitter } from 'events'; | ||
|
||
import type { LicenseModule } from '../definition/LicenseModule'; | ||
import { logger } from '../logger'; | ||
|
||
export const EnterpriseLicenses = new EventEmitter(); | ||
|
||
export const licenseValidated = () => EnterpriseLicenses.emit('validate'); | ||
export const licenseValidated = () => { | ||
try { | ||
EnterpriseLicenses.emit('validate'); | ||
} catch (error) { | ||
logger.error({ msg: 'Error running license validated event', error }); | ||
} | ||
}; | ||
|
||
export const licenseRemoved = () => EnterpriseLicenses.emit('invalidate'); | ||
export const licenseRemoved = () => { | ||
try { | ||
EnterpriseLicenses.emit('invalidate'); | ||
} catch (error) { | ||
logger.error({ msg: 'Error running license invalidated event', error }); | ||
} | ||
}; | ||
|
||
export const moduleValidated = (module: LicenseModule) => { | ||
EnterpriseLicenses.emit('module', { module, valid: true }); | ||
EnterpriseLicenses.emit(`valid:${module}`); | ||
try { | ||
EnterpriseLicenses.emit('module', { module, valid: true }); | ||
EnterpriseLicenses.emit(`valid:${module}`); | ||
} catch (error) { | ||
logger.error({ msg: 'Error running module added event', error }); | ||
} | ||
}; | ||
|
||
export const moduleRemoved = (module: LicenseModule) => { | ||
EnterpriseLicenses.emit('module', { module, valid: false }); | ||
EnterpriseLicenses.emit(`invalid:${module}`); | ||
try { | ||
EnterpriseLicenses.emit('module', { module, valid: false }); | ||
EnterpriseLicenses.emit(`invalid:${module}`); | ||
} catch (error) { | ||
logger.error({ msg: 'Error running module removed event', error }); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { setLicense } from './license'; | ||
import { logger } from './logger'; | ||
|
||
let pendingLicense: string; | ||
|
||
export const setPendingLicense = (encryptedLicense: string) => { | ||
pendingLicense = encryptedLicense; | ||
if (pendingLicense) { | ||
logger.info('Storing license as pending validation.'); | ||
} | ||
}; | ||
|
||
export const applyPendingLicense = async () => { | ||
if (pendingLicense) { | ||
logger.info('Applying pending license.'); | ||
await setLicense(pendingLicense, true); | ||
} | ||
}; | ||
|
||
export const hasPendingLicense = () => Boolean(pendingLicense); | ||
|
||
export const isPendingLicense = (encryptedLicense: string) => !!pendingLicense && pendingLicense === encryptedLicense; | ||
|
||
export const clearPendingLicense = () => { | ||
if (pendingLicense) { | ||
logger.info('Removing pending license.'); | ||
} | ||
|
||
pendingLicense = ''; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,13 @@ | ||
import { validateLicense } from './license'; | ||
import { applyPendingLicense, hasPendingLicense } from './pendingLicense'; | ||
|
||
let workspaceUrl: string | undefined; | ||
|
||
export const setWorkspaceUrl = async (url: string) => { | ||
workspaceUrl = url.replace(/\/$/, '').replace(/^https?:\/\/(.*)$/, '$1'); | ||
|
||
await validateLicense(); | ||
if (hasPendingLicense()) { | ||
await applyPendingLicense(); | ||
} | ||
}; | ||
|
||
export const getWorkspaceUrl = () => workspaceUrl; |