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

142 lines
3.2 KiB
JavaScript
Raw Normal View History

/**
2026-01-28 17:09:06 -08:00
* Copyright IBM Corp. 2021, 2026
* SPDX-License-Identifier: BUSL-1.1
*/
2020-06-04 16:32:16 -04:00
import GeneratedHostCatalogModel from '../generated/models/host-catalog';
import { tracked } from '@glimmer/tracking';
2020-06-04 16:32:16 -04:00
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 TYPE_HOST_CATALOG_PLUGIN_GCP = 'gcp';
export const TYPES_HOST_CATALOG_PLUGIN = [
TYPE_HOST_CATALOG_PLUGIN_AWS,
TYPE_HOST_CATALOG_PLUGIN_AZURE,
TYPE_HOST_CATALOG_PLUGIN_GCP,
];
2024-10-09 14:49:22 -07:00
export const TYPE_CREDENTIAL_STATIC = 'static-credential';
export const TYPE_CREDENTIAL_DYNAMIC = 'dynamic-credential';
export const TYPES_CREDENTIALS = Object.freeze([
TYPE_CREDENTIAL_STATIC,
TYPE_CREDENTIAL_DYNAMIC,
]);
export const DYNAMIC_CREDENTIAL_FIELDS = [
2024-10-18 14:33:14 -07:00
'role_arn',
'role_external_id',
'role_session_name',
'role_tags',
];
export const STATIC_CREDENTIAL_FIELDS = ['access_key_id, secret_access_key'];
2024-10-18 14:33:14 -07:00
export default class HostCatalogModel extends GeneratedHostCatalogModel {
// =attributes
@tracked _credentialTypeValue;
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';
}
2024-10-09 14:49:22 -07:00
/**
* Gets a value from credentialType
* @type {string}
*/
get credentialType() {
if (!this._credentialTypeValue) {
2024-10-18 14:33:14 -07:00
if (DYNAMIC_CREDENTIAL_FIELDS.some((field) => this[field])) {
return TYPE_CREDENTIAL_DYNAMIC;
2024-10-09 14:49:22 -07:00
} else {
return TYPE_CREDENTIAL_STATIC;
2024-10-09 14:49:22 -07:00
}
}
return this._credentialTypeValue;
2024-10-09 14:49:22 -07:00
}
/**
* Sets a value to credentialType
* @type {string}
*/
set credentialType(type) {
this._credentialTypeValue = type;
2024-10-09 14:49:22 -07:00
}
2022-01-11 15:34:11 -08:00
/**
* 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() {
2025-01-08 11:49:01 -08:00
return this.compositeType === TYPE_HOST_CATALOG_PLUGIN_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() {
2025-01-08 11:49:01 -08:00
return this.compositeType === TYPE_HOST_CATALOG_PLUGIN_AZURE;
}
2022-01-12 15:34:12 -08:00
/**
* True if host catalog plugin type is GCP.
* @type {boolean}
*/
get isGCP() {
2025-01-08 11:49:01 -08:00
return this.compositeType === TYPE_HOST_CATALOG_PLUGIN_GCP;
}
/**
* 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 };
}
}
}