Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix moment.js license expiration parsing #19014

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion x-pack/plugins/xpack_main/server/lib/xpack_info.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ export class XPackInfo {
const licenseInfo = [
`mode: ${get(response, 'license.mode')}`,
`status: ${get(response, 'license.status')}`,
`expiry date: ${moment(get(response, 'license.expiry_date_in_millis'), 'x').format()}`
`expiry date: ${this._getExpiryDate(response)}`
].join(' | ');

this._log(
Expand Down Expand Up @@ -260,4 +260,22 @@ export class XPackInfo {

return newLicense.expiry_date_in_millis !== cachedLicense.expiry_date_in_millis;
}

/**
* Handles the case where the license type is basic, and the date is so far into the
* future that moment cannot parse it. In that case we should treat it as never expiring.
* @param {Object} xpackInfo xPack info response object returned from the backend.
* @returns {string} 'never' if license is basic and date unparseable by moment;
* otherwise, a formatted date.
* @private
*/
_getExpiryDate(xpackInfo) {
let expiryDate = moment(get(xpackInfo, 'license.expiry_date_in_millis')).format('YYYY MMM DD HH:mm');

if (expiryDate === 'Invalid date' && get(xpackInfo, 'license.mode') === 'basic') {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this.license.getType() doesn't work here. is this the right way to check for basic license??

expiryDate = 'never';
}

return expiryDate;
}
}