Files
vault/ui/app/services/version.js
Chelsea Shaw cb217388d4 UI: handle reduced disclosure endpoints (#24262)
* Create app-footer component with tests

* glimmerize vault route + controller

* Add dev mode badge to new footer

* Fix version on dashboard

* update app-footer tests

* update version title component

* Handle case for chroot namespace fail on health check

* cleanup

* fix ent tests

* add missing headers

* extra version fetch on login success, clear version on logout and seal

* Add coverage for clearing version on seal

* rename isOSS to isCommunity

* remove is-version helper

* test version in footer on unseal flow

* fix enterprise test

* VAULT-21399 test coverage

* VAULT-21400 test coverage
2023-12-04 14:28:16 -06:00

97 lines
2.2 KiB
JavaScript

/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: BUSL-1.1
*/
import Service, { inject as service } from '@ember/service';
import { keepLatestTask, task } from 'ember-concurrency';
import { tracked } from '@glimmer/tracking';
export default class VersionService extends Service {
@service store;
@tracked features = [];
@tracked version = null;
@tracked type = null;
get isEnterprise() {
return this.type === 'enterprise';
}
get isCommunity() {
return !this.isEnterprise;
}
/* Features */
get hasPerfReplication() {
return this.features.includes('Performance Replication');
}
get hasDRReplication() {
return this.features.includes('DR Replication');
}
get hasSentinel() {
return this.features.includes('Sentinel');
}
get hasNamespaces() {
return this.features.includes('Namespaces');
}
get hasControlGroups() {
return this.features.includes('Control Groups');
}
get versionDisplay() {
if (!this.version) {
return '';
}
return this.isEnterprise ? `v${this.version.slice(0, this.version.indexOf('+'))}` : `v${this.version}`;
}
@task({ drop: true })
*getVersion() {
if (this.version) return;
const response = yield this.store.adapterFor('cluster').fetchVersion();
this.version = response.data?.version;
}
@task
*getType() {
if (this.type !== null) return;
const response = yield this.store.adapterFor('cluster').health();
if (response.has_chroot_namespace) {
// chroot_namespace feature is only available in enterprise
this.type = 'enterprise';
return;
}
this.type = response.enterprise ? 'enterprise' : 'community';
}
@keepLatestTask
*getFeatures() {
if (this.features?.length || this.isCommunity) {
return;
}
try {
const response = yield this.store.adapterFor('cluster').features();
this.features = response.features;
return;
} catch (err) {
// if we fail here, we're likely in DR Secondary mode and don't need to worry about it
}
}
fetchVersion() {
return this.getVersion.perform();
}
fetchType() {
return this.getType.perform();
}
fetchFeatures() {
return this.getFeatures.perform();
}
}