Files
threshold-ui/ui/admin/app/instance-initializers/feature-edition.js
T

46 lines
1.2 KiB
JavaScript
Raw Normal View History

/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: MPL-2.0
*/
2023-03-31 17:38:17 -07:00
import fetch from 'fetch';
async function autoInitializeFeatureEdition(owner) {
2023-03-17 14:34:37 -07:00
const service = owner.lookup('service:feature-edition');
const adapter = owner.lookup('adapter:application');
2023-03-31 17:38:17 -07:00
let edition;
let features;
// Attempt to load edition for the metadata JSON
try {
const { host } = adapter;
const path = '/metadata.json';
const url = `${host}${path}`;
2023-03-31 17:38:17 -07:00
const response = await fetch(url);
const json = await response.json();
2023-03-31 17:38:17 -07:00
edition = json?.license?.edition;
features = json?.license?.features;
} catch (e) {
// if the request fails, the service will initialize the default edition
// as specified in the config
}
// Initialize the feature edition and its associated features
service.initialize(edition, features);
}
export async function initialize(owner) {
const config = owner.resolveRegistration('config:environment');
const isTesting = config.environment === 'test';
// Do not auto-init in a test environment.
// Tests should explicitly enable editions and features as needed.
if (!isTesting) {
await autoInitializeFeatureEdition(owner);
}
2023-03-17 14:34:37 -07:00
}
export default {
initialize,
};