* chore: 🤖 import explicit mirage references * chore: 🤖 add mirage setupMirage helper * chore: 🤖 working example with application adapter test * chore: 🤖 use internal setupMirage test helper from api addon * chore: 🤖 conditionally load mirage * chore: 🤖 filter mirage folder inclusion in production builds * chore: 🤖 drop ember-mirage and use our own test helpers * chore: 🤖 collapse reference to import declaration * docs: ✏️ add comment better explaining the mirage test env * chore: 🤖 update configuration and manage mirage-related deps * fix: 🐛 restore ipc mock and add missing checkOS handler * chore: 🤖 add comment explaining omitting mirage deps in build * chore: 🤖 allow mirage.enabled to include deps and handlers * chore: 🤖 re-enable mirage for core dummy app * Add missing copyright headers * chore: 🤖 use embroider macros to conditionally start mirage * docs: ✏️ update api readme for mirage changes * chore: 🤖 replace remaining ember-cli-mirage references * chore: 🤖 add mirage to test builds * fix: 🐛 ensure that auto mirage start doesn't happen in test env * chore: 🤖 use const instead of var Co-authored-by: Zhihe Li <zhihe.li@hashicorp.com> * refactor: 💡 use cleaner logic for excluded api build modules * fix: 🐛 handle issue where importSync was too eager This was fixed by bumping the @embroider/macros dependency that includes a fix to this issue: https://github.com/embroider-build/embroider/pull/2511 * refactor: 💡 move mirage from addon to app directory * refactor: 💡 update mirage test helper to be a factory * chore: 🤖 exclude mirage directory when necessary at build time * chore: 🤖 add miragejs as admin dev dependency * refactor: 💡 update reference to startMirage * chore: 🤖 update local mirage test helper * chore: 🤖 change import path for mirage on desktop * chore: 🤖 update imports in tests for startMirage * chore: 🤖 update startMirage imports for api addon tests * chore: 🤖 add miragejs dev dep to desktop * docs: ✏️ update README * chore: 🤖 set up setupMirage for core tests * chore: 🤖 fix copyright header * Add missing copyright headers --------- Co-authored-by: Zhihe Li <zhihe.li@hashicorp.com>
75 lines
2.0 KiB
JavaScript
75 lines
2.0 KiB
JavaScript
/**
|
|
* Copyright IBM Corp. 2021, 2026
|
|
* SPDX-License-Identifier: BUSL-1.1
|
|
*/
|
|
|
|
import factory from '../generated/factories/host-set';
|
|
import permissions from '../helpers/permissions';
|
|
import { faker } from '@faker-js/faker';
|
|
import generateId from '../helpers/id';
|
|
import {
|
|
TYPE_HOST_CATALOG_PLUGIN_AWS,
|
|
TYPE_HOST_CATALOG_PLUGIN_AZURE,
|
|
TYPE_HOST_CATALOG_PLUGIN_GCP,
|
|
} from 'api/models/host-catalog';
|
|
|
|
function generateFilters(prefix) {
|
|
const filtersAmount = faker.number.int({ min: 1, max: 5 });
|
|
let filters = [];
|
|
for (let i = 0; i < filtersAmount; ++i) {
|
|
filters.push(`${prefix}${faker.word.words(1)}=${faker.word.words(1)}`);
|
|
}
|
|
return {
|
|
filters,
|
|
};
|
|
}
|
|
|
|
export default factory.extend({
|
|
id: () => generateId('hs_'),
|
|
type() {
|
|
return this.hostCatalog?.type || factory.attrs.type;
|
|
},
|
|
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;
|
|
},
|
|
plugin() {
|
|
if (this.type === 'plugin') {
|
|
return this.hostCatalog.plugin;
|
|
}
|
|
},
|
|
preferred_endpoints() {
|
|
if (this.type === 'plugin') {
|
|
const endpointsAmount = faker.number.int({ min: 1, max: 5 });
|
|
let result = [];
|
|
for (let i = 0; i < endpointsAmount; ++i) {
|
|
result.push(
|
|
Math.random() > 0.5 ? faker.internet.ip() : faker.internet.ipv6(),
|
|
);
|
|
}
|
|
return result;
|
|
}
|
|
},
|
|
sync_interval_seconds() {
|
|
if (this.type === 'plugin') {
|
|
return faker.number.int();
|
|
}
|
|
},
|
|
|
|
attributes() {
|
|
switch (this.plugin?.name) {
|
|
case TYPE_HOST_CATALOG_PLUGIN_AWS:
|
|
return generateFilters('tag:');
|
|
case TYPE_HOST_CATALOG_PLUGIN_AZURE:
|
|
return {
|
|
filter: `${faker.database.column()}=${faker.database.collation()}`,
|
|
};
|
|
case TYPE_HOST_CATALOG_PLUGIN_GCP:
|
|
return generateFilters('labels.');
|
|
}
|
|
},
|
|
});
|