Files
threshold-ui/addons/api/addon/models/host-catalog.js
T

90 lines
2.0 KiB
JavaScript
Raw Normal View History

/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: MPL-2.0
*/
2020-06-04 16:32:16 -04:00
import GeneratedHostCatalogModel from '../generated/models/host-catalog';
export const TYPE_HOST_CATALOG_STATIC = 'static';
export const TYPE_HOST_CATALOG_DYNAMIC = 'plugin';
export const TYPES_HOST_CATALOG = Object.freeze([
TYPE_HOST_CATALOG_STATIC,
TYPE_HOST_CATALOG_DYNAMIC,
]);
export const TYPE_HOST_CATALOG_PLUGIN_AWS = 'aws';
export const TYPE_HOST_CATALOG_PLUGIN_AZURE = 'azure';
export const TYPES_HOST_CATALOG_PLUGIN = [
TYPE_HOST_CATALOG_PLUGIN_AWS,
TYPE_HOST_CATALOG_PLUGIN_AZURE,
];
export default class HostCatalogModel extends GeneratedHostCatalogModel {
// =attributes
2022-01-12 15:34:12 -08:00
/**
* True if the host catalog is static.
2022-01-12 15:34:12 -08:00
* @type {boolean}
*/
get isStatic() {
return this.type === 'static';
}
/**
* True if the host catalog is a plugin.
* @type {boolean}
*/
2022-01-11 15:34:11 -08:00
get isPlugin() {
return this.type === 'plugin';
}
/**
* True if the host catalog is an unknown type.
* @type {boolean}
*/
get isUnknown() {
return (
this.isPlugin && !TYPES_HOST_CATALOG_PLUGIN.includes(this.plugin?.name)
);
}
/**
* True if host catalog plugin type is AWS.
2022-01-11 15:34:11 -08:00
* @type {boolean}
*/
get isAWS() {
2022-01-14 13:14:50 -08:00
return this.compositeType === 'aws';
2022-01-11 15:34:11 -08:00
}
/**
* True if host catalog plugin type is Azure.
2022-01-11 15:34:11 -08:00
* @type {boolean}
*/
get isAzure() {
2022-01-14 13:14:50 -08:00
return this.compositeType === 'azure';
}
2022-01-12 15:34:12 -08:00
/**
* If host catalog is a plugin return `plugin.name`,
* otherwise return the host catalog type.
2022-01-12 15:34:12 -08:00
* @type {string}
*/
get compositeType() {
if (this.isUnknown) return 'unknown';
if (this.isPlugin) return this.plugin.name;
return 'static';
2022-01-12 15:34:12 -08:00
}
/**
* Sets `type`. If type is different than `static`, sets `type` to `plugin`
* and `plugin.name` to the specified type.
*/
set compositeType(type) {
if (type === 'static') {
this.type = 'static';
} else {
this.type = 'plugin';
2022-01-14 13:32:38 -08:00
this.plugin = { name: type };
}
}
}