2023-03-01 09:39:41 -06:00
|
|
|
/**
|
|
|
|
|
* Copyright (c) HashiCorp, Inc.
|
2024-05-31 11:29:24 -07:00
|
|
|
* SPDX-License-Identifier: BUSL-1.1
|
2023-03-01 09:39:41 -06:00
|
|
|
*/
|
|
|
|
|
|
2020-08-14 15:16:35 -04:00
|
|
|
import GeneratedHostModel from '../generated/models/host';
|
2022-02-08 08:24:39 -08:00
|
|
|
import { attr } from '@ember-data/model';
|
2024-04-04 16:23:48 -04:00
|
|
|
import { TYPES_HOST_CATALOG_PLUGIN } from './host-catalog';
|
2020-08-14 15:16:35 -04:00
|
|
|
|
2020-09-09 13:04:17 -04:00
|
|
|
export default class HostModel extends GeneratedHostModel {
|
2022-02-09 08:54:32 -08:00
|
|
|
// =attributes
|
2022-02-07 09:48:51 -08:00
|
|
|
|
2022-02-09 08:54:32 -08:00
|
|
|
// Static specific fields
|
2022-02-08 08:24:39 -08:00
|
|
|
@attr('string', {
|
|
|
|
|
description: 'The address (DNS or IP name) used to reach the host',
|
|
|
|
|
isNestedAttribute: true,
|
|
|
|
|
})
|
|
|
|
|
address;
|
|
|
|
|
|
2022-02-09 08:54:32 -08:00
|
|
|
// Plugin specific fields
|
|
|
|
|
@attr({
|
|
|
|
|
readOnly: true,
|
|
|
|
|
emptyArrayIfMissing: true,
|
|
|
|
|
})
|
|
|
|
|
ip_addresses;
|
|
|
|
|
|
2022-02-08 08:24:39 -08:00
|
|
|
@attr('string', {
|
|
|
|
|
description: '',
|
|
|
|
|
readOnly: true,
|
|
|
|
|
})
|
|
|
|
|
external_id;
|
|
|
|
|
|
2023-04-17 13:22:32 -04:00
|
|
|
@attr('string', {
|
|
|
|
|
description: 'The external facing name for the plugin based host.',
|
|
|
|
|
readOnly: true,
|
|
|
|
|
})
|
|
|
|
|
external_name;
|
|
|
|
|
|
2022-02-07 09:48:51 -08:00
|
|
|
// Aws specific
|
2022-02-09 08:54:32 -08:00
|
|
|
@attr({
|
2022-02-07 09:48:51 -08:00
|
|
|
readOnly: true,
|
|
|
|
|
emptyArrayIfMissing: true,
|
|
|
|
|
})
|
|
|
|
|
dns_names;
|
2022-01-26 08:52:14 -08:00
|
|
|
|
|
|
|
|
/**
|
2022-01-26 14:06:22 -08:00
|
|
|
* True if the host is static.
|
2022-01-26 08:52:14 -08:00
|
|
|
* @type {boolean}
|
|
|
|
|
*/
|
|
|
|
|
get isStatic() {
|
|
|
|
|
return this.type === 'static';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2022-01-26 14:06:22 -08:00
|
|
|
* True if the host is plugin.
|
2022-01-26 08:52:14 -08:00
|
|
|
* @type {boolean}
|
|
|
|
|
*/
|
|
|
|
|
get isPlugin() {
|
|
|
|
|
return this.type === 'plugin';
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-15 13:52:34 -05:00
|
|
|
/**
|
|
|
|
|
* True if the host catalog is an unknown type.
|
|
|
|
|
* @type {boolean}
|
|
|
|
|
*/
|
|
|
|
|
get isUnknown() {
|
2024-04-04 16:23:48 -04:00
|
|
|
return (
|
|
|
|
|
this.isPlugin && !TYPES_HOST_CATALOG_PLUGIN.includes(this.plugin?.name)
|
|
|
|
|
);
|
2023-09-15 13:52:34 -05:00
|
|
|
}
|
|
|
|
|
|
2022-01-26 08:52:14 -08:00
|
|
|
/**
|
2022-01-26 14:06:22 -08:00
|
|
|
* True if the host plugin type is AWS.
|
2022-01-26 08:52:14 -08:00
|
|
|
* @type {boolean}
|
|
|
|
|
*/
|
|
|
|
|
get isAWS() {
|
|
|
|
|
return this.compositeType === 'aws';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2022-01-26 14:06:22 -08:00
|
|
|
* True if the host plugin type is Azure.
|
2022-01-26 08:52:14 -08:00
|
|
|
* @type {boolean}
|
|
|
|
|
*/
|
|
|
|
|
get isAzure() {
|
|
|
|
|
return this.compositeType === 'azure';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2022-01-26 14:06:22 -08:00
|
|
|
* If host is a plugin return `plugin.name`,
|
|
|
|
|
* otherwise return the host type.
|
2022-01-26 08:52:14 -08:00
|
|
|
* @type {string}
|
|
|
|
|
*/
|
|
|
|
|
get compositeType() {
|
|
|
|
|
return this.isPlugin ? this.plugin.name : this.type;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2022-01-26 14:06:22 -08:00
|
|
|
* Sets `type`. If type is different than `static`, sets `type` to `plugin`
|
|
|
|
|
* and `plugin.name` to the specified type.
|
2022-01-26 08:52:14 -08:00
|
|
|
*/
|
|
|
|
|
set compositeType(type) {
|
|
|
|
|
if (type === 'static') {
|
|
|
|
|
this.type = 'static';
|
|
|
|
|
} else {
|
|
|
|
|
this.type = 'plugin';
|
|
|
|
|
this.plugin = { name: type };
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-04-17 13:22:32 -04:00
|
|
|
|
|
|
|
|
// Plugin hosts can support an external name
|
|
|
|
|
get displayName() {
|
|
|
|
|
return this.name || this.external_name || this.id;
|
|
|
|
|
}
|
2020-09-09 13:04:17 -04:00
|
|
|
}
|