2023-03-01 09:39:41 -06:00
|
|
|
/**
|
|
|
|
|
* Copyright (c) HashiCorp, Inc.
|
|
|
|
|
* SPDX-License-Identifier: MPL-2.0
|
|
|
|
|
*/
|
|
|
|
|
|
2020-08-14 10:46:17 -04:00
|
|
|
import factory from '../generated/factories/host-set';
|
2021-08-18 13:03:28 -07:00
|
|
|
import permissions from '../helpers/permissions';
|
2022-08-01 11:25:07 -07:00
|
|
|
import { faker } from '@faker-js/faker';
|
2022-06-01 14:02:18 -04:00
|
|
|
import generateId from '../helpers/id';
|
2020-08-14 10:46:17 -04:00
|
|
|
|
2020-08-27 16:38:49 -04:00
|
|
|
export default factory.extend({
|
2022-06-01 14:02:18 -04:00
|
|
|
id: () => generateId('hs_'),
|
2022-01-26 13:42:58 -08:00
|
|
|
type() {
|
2022-01-26 14:41:39 -08:00
|
|
|
return this.hostCatalog?.type || factory.attrs.type;
|
2022-01-26 13:42:58 -08:00
|
|
|
},
|
2022-02-02 17:04:09 -05:00
|
|
|
authorized_actions: function () {
|
|
|
|
|
const isStatic = this.type === 'static';
|
|
|
|
|
const defaults = ['no-op', 'read', 'update', 'delete'];
|
|
|
|
|
// Only static allows host management at this time.
|
|
|
|
|
if (isStatic) defaults.push('add-hosts', 'remove-hosts');
|
|
|
|
|
return permissions.authorizedActionsFor('host-set') || defaults;
|
|
|
|
|
},
|
2022-01-26 12:30:21 -08:00
|
|
|
plugin() {
|
|
|
|
|
if (this.type === 'plugin') {
|
|
|
|
|
return this.hostCatalog.plugin;
|
|
|
|
|
}
|
|
|
|
|
},
|
2022-02-03 14:31:21 -08:00
|
|
|
preferred_endpoints() {
|
|
|
|
|
if (this.type === 'plugin') {
|
2022-08-01 11:25:07 -07:00
|
|
|
const enpointsAmount = faker.datatype.number({ min: 1, max: 5 });
|
2022-02-03 14:31:21 -08:00
|
|
|
let result = [];
|
|
|
|
|
for (let i = 0; i < enpointsAmount; ++i) {
|
2022-08-01 11:25:07 -07:00
|
|
|
result.push(faker.internet.ip());
|
2022-02-03 14:31:21 -08:00
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
},
|
2022-03-03 14:17:11 -08:00
|
|
|
sync_interval_seconds() {
|
|
|
|
|
if (this.type === 'plugin') {
|
2022-08-01 11:25:07 -07:00
|
|
|
return faker.datatype.number();
|
2022-03-03 14:17:11 -08:00
|
|
|
}
|
|
|
|
|
},
|
2022-08-11 13:10:42 -07:00
|
|
|
|
|
|
|
|
attributes() {
|
|
|
|
|
// AWS specific
|
2022-02-04 09:26:26 -08:00
|
|
|
if (this.plugin?.name === 'aws') {
|
2022-08-01 11:25:07 -07:00
|
|
|
const filtersAmount = faker.datatype.number({ min: 1, max: 5 });
|
2022-08-11 13:10:42 -07:00
|
|
|
let filters = [];
|
2022-02-03 14:31:21 -08:00
|
|
|
for (let i = 0; i < filtersAmount; ++i) {
|
2022-08-11 13:10:42 -07:00
|
|
|
filters.push(`${faker.datatype.string(3)}=${faker.datatype.string(8)}`);
|
2022-02-03 14:31:21 -08:00
|
|
|
}
|
2022-08-11 13:10:42 -07:00
|
|
|
return {
|
|
|
|
|
filters,
|
|
|
|
|
};
|
2022-02-03 14:31:21 -08:00
|
|
|
}
|
2022-08-11 13:10:42 -07:00
|
|
|
// Azure specific
|
2022-02-04 09:26:26 -08:00
|
|
|
if (this.plugin?.name === 'azure') {
|
2022-08-11 13:10:42 -07:00
|
|
|
return {
|
|
|
|
|
filter: `${faker.database.column()}=${faker.database.collation()}`,
|
|
|
|
|
};
|
2022-02-03 14:31:21 -08:00
|
|
|
}
|
|
|
|
|
},
|
2020-08-27 16:38:49 -04:00
|
|
|
});
|