vault/ui/app/components/token-expire-warning.js
Noelle Daley 61a37f2723
UI: fix token expiry banner for batch tokens (#27479)
* fix: calculate expiration of all batch tokens to ensure expire warning banner is shown

* fix: ensure allowExpiration doesn't get overridden

* fix: set expirationCalcTS outside of calculateExpression

* tests: verify expirationEpoch is calculated when only expiry_time is passed in

* fix: calculate expireTime using expire_time if its passed in

* tests: clean up auth tests

* tests: organize batch token vs. service token tests into separate module

* chore: update changelog

* Update changelog/27479.txt

Co-authored-by: Chelsea Shaw <82459713+hashishaw@users.noreply.github.com>

* fix: ensure tokens in test envs do not expire

* cleanup: pull setExpiration settings into own method & add tests

---------

Co-authored-by: Chelsea Shaw <82459713+hashishaw@users.noreply.github.com>
2024-06-28 01:05:53 +00:00

53 lines
1.2 KiB
JavaScript

/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: BUSL-1.1
*/
import Component from '@glimmer/component';
import { service } from '@ember/service';
import { tracked } from '@glimmer/tracking';
import { later } from '@ember/runloop';
import { task } from 'ember-concurrency';
export default class TokenExpireWarning extends Component {
@service auth;
@service router;
@tracked canDismiss = true;
handleRenew() {
return new Promise((resolve) => {
later(() => {
this.auth
.renew()
.then(() => {
// This renewal was triggered by an explicit user action,
// so this will reset the time inactive calculation
this.auth.setLastFetch(Date.now());
})
.finally(() => {
resolve();
});
}, 200);
});
}
@task
*renewToken() {
yield this.handleRenew();
}
get queryParams() {
// Bring user back to current page after login
return { redirect_to: this.router.currentURL };
}
get showWarning() {
const currentRoute = this.router.currentRouteName;
if ('vault.cluster.oidc-provider' === currentRoute) {
return false;
}
return !!this.args.expirationDate;
}
}