Files
threshold-ui/addons/api/mirage/factories/host.js
T

61 lines
1.6 KiB
JavaScript
Raw Normal View History

/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: MPL-2.0
*/
2020-08-14 15:16:35 -04:00
import factory from '../generated/factories/host';
2021-08-18 15:56:25 -07:00
import permissions from '../helpers/permissions';
import { faker } from '@faker-js/faker';
2022-06-01 14:02:18 -04:00
import generateId from '../helpers/id';
2022-02-11 10:16:23 -08:00
2020-08-21 18:21:17 -04:00
export default factory.extend({
2022-06-01 14:02:18 -04:00
id: () => generateId('h_'),
+1
2023-04-25 16:22:12 -05:00
name() {
if (this.type === 'static') return faker.random.words();
},
2022-01-27 11:36:29 -08:00
type() {
return this.hostCatalog?.type || factory.attrs.type;
},
authorized_actions: function () {
const isStatic = this.type === 'static';
const defaults = ['no-op', 'read'];
// Only static allows update/delete at this time.
if (isStatic) defaults.push('update', 'delete');
return permissions.authorizedActionsFor('host') || defaults;
},
plugin() {
if (this.type === 'plugin') {
return this.hostCatalog.plugin;
}
},
2022-02-15 15:12:20 -08:00
ip_addresses() {
const addressesAmount = Math.floor(Math.random() * 6) + 1;
let result = [];
for (let i = 0; i < addressesAmount; ++i) {
result.push(faker.internet.ip());
2022-02-15 15:12:20 -08:00
}
return result;
},
+1
2023-04-25 16:22:12 -05:00
// Return external fields only for plugins
2022-02-15 15:12:20 -08:00
external_id() {
+1
2023-04-25 16:22:12 -05:00
if (this.type === 'plugin') {
return faker.datatype.uuid();
}
},
external_name(i) {
if (this.type === 'plugin') {
return `${this.plugin.name} provided name ${i}`;
}
2022-02-15 15:12:20 -08:00
},
// Only aws plugins have dns_names
dns_names() {
if (this.plugin?.name === 'aws') {
const dnsNamesAmount = Math.floor(Math.random() * 6) + 1;
let result = [];
for (let i = 0; i < dnsNamesAmount; i++) {
result.push(faker.internet.domainName());
2022-02-15 15:12:20 -08:00
}
return result;
}
2022-02-11 10:16:23 -08:00
},
2020-08-21 18:21:17 -04:00
});