mirror of
https://github.com/hashicorp/vault.git
synced 2025-08-16 11:37:04 +02:00
* Adding explicit MPL license for sub-package. This directory and its subdirectories (packages) contain files licensed with the MPLv2 `LICENSE` file in this directory and are intentionally licensed separately from the BSL `LICENSE` file at the root of this repository. * Adding explicit MPL license for sub-package. This directory and its subdirectories (packages) contain files licensed with the MPLv2 `LICENSE` file in this directory and are intentionally licensed separately from the BSL `LICENSE` file at the root of this repository. * Updating the license from MPL to Business Source License. Going forward, this project will be licensed under the Business Source License v1.1. Please see our blog post for more details at https://hashi.co/bsl-blog, FAQ at www.hashicorp.com/licensing-faq, and details of the license at www.hashicorp.com/bsl. * add missing license headers * Update copyright file headers to BUS-1.1 * Fix test that expected exact offset on hcl file --------- Co-authored-by: hashicorp-copywrite[bot] <110428419+hashicorp-copywrite[bot]@users.noreply.github.com> Co-authored-by: Sarah Thompson <sthompson@hashicorp.com> Co-authored-by: Brian Kassouf <bkassouf@hashicorp.com>
78 lines
2.3 KiB
JavaScript
78 lines
2.3 KiB
JavaScript
/**
|
|
* Copyright (c) HashiCorp, Inc.
|
|
* SPDX-License-Identifier: BUSL-1.1
|
|
*/
|
|
|
|
import Component from '@glimmer/component';
|
|
import { action } from '@ember/object';
|
|
import { tracked } from '@glimmer/tracking';
|
|
import { inject as service } from '@ember/service';
|
|
import isAfter from 'date-fns/isAfter';
|
|
import differenceInDays from 'date-fns/differenceInDays';
|
|
import localStorage from 'vault/lib/local-storage';
|
|
import timestamp from 'core/utils/timestamp';
|
|
|
|
/**
|
|
* @module LicenseBanners
|
|
* LicenseBanners components are used to display Vault-specific license expiry messages
|
|
*
|
|
* @example
|
|
* ```js
|
|
* <LicenseBanners @expiry={expiryDate} />
|
|
* ```
|
|
* @param {string} expiry - RFC3339 date timestamp
|
|
*/
|
|
|
|
export default class LicenseBanners extends Component {
|
|
@service version;
|
|
|
|
@tracked warningDismissed;
|
|
@tracked expiredDismissed;
|
|
|
|
constructor() {
|
|
super(...arguments);
|
|
// reset and show a previously dismissed license banner if:
|
|
// the version has been updated or the license has been updated (indicated by a change in the expiry date).
|
|
const bannerType = localStorage.getItem(this.dismissedBannerKey); // returns either warning or expired
|
|
|
|
this.updateDismissType(bannerType);
|
|
}
|
|
|
|
get currentVersion() {
|
|
return this.version.version;
|
|
}
|
|
|
|
get dismissedBannerKey() {
|
|
return `dismiss-license-banner-${this.currentVersion}-${this.args.expiry}`;
|
|
}
|
|
|
|
get licenseExpired() {
|
|
if (!this.args.expiry) return false;
|
|
return isAfter(timestamp.now(), new Date(this.args.expiry));
|
|
}
|
|
|
|
get licenseExpiringInDays() {
|
|
// Anything more than 30 does not render a warning
|
|
if (!this.args.expiry) return 99;
|
|
return differenceInDays(new Date(this.args.expiry), timestamp.now());
|
|
}
|
|
|
|
@action
|
|
dismissBanner(dismissAction) {
|
|
// if a client's version changed their old localStorage key will still exists.
|
|
localStorage.cleanupStorage('dismiss-license-banner', this.dismissedBannerKey);
|
|
// updates localStorage and then updates the template by calling updateDismissType
|
|
localStorage.setItem(this.dismissedBannerKey, dismissAction);
|
|
this.updateDismissType(dismissAction);
|
|
}
|
|
|
|
updateDismissType(dismissType) {
|
|
// updates tracked properties to update template
|
|
if (dismissType === 'warning') {
|
|
this.warningDismissed = true;
|
|
} else if (dismissType === 'expired') {
|
|
this.expiredDismissed = true;
|
|
}
|
|
}
|
|
}
|