chore: 🤖 gcp plugin creation in the UI (#2645)

gcp plugin creation and mirage changes
This commit is contained in:
Dharini Jeeva authored and Dharini committed 2025-01-10 14:18:48 -08:00
1 parent 520020f2c6
commit dfa62dd04b
11 files changed
+376 -28

No files matched your search

+3 -3
View File
@@ -95,7 +95,7 @@ export default class HostCatalogModel extends GeneratedHostCatalogModel {
* @type {boolean}
*/
get isAWS() {
return this.compositeType === 'aws';
return this.compositeType === TYPE_HOST_CATALOG_PLUGIN_AWS;
}
/**
@@ -103,7 +103,7 @@ export default class HostCatalogModel extends GeneratedHostCatalogModel {
* @type {boolean}
*/
get isAzure() {
return this.compositeType === 'azure';
return this.compositeType === TYPE_HOST_CATALOG_PLUGIN_AZURE;
}
/**
@@ -111,7 +111,7 @@ export default class HostCatalogModel extends GeneratedHostCatalogModel {
* @type {boolean}
*/
get isGCP() {
return this.compositeType === 'gcp';
return this.compositeType === TYPE_HOST_CATALOG_PLUGIN_GCP;
}
/**
+16 -3
View File
@@ -4,7 +4,12 @@
*/
import GeneratedHostSetModel from '../generated/models/host-set';
import { TYPES_HOST_CATALOG_PLUGIN } from './host-catalog';
import {
TYPES_HOST_CATALOG_PLUGIN,
TYPE_HOST_CATALOG_PLUGIN_GCP,
TYPE_HOST_CATALOG_PLUGIN_AWS,
TYPE_HOST_CATALOG_PLUGIN_AZURE,
} from './host-catalog';
export default class HostSetModel extends GeneratedHostSetModel {
// =attributes
@@ -40,14 +45,22 @@ export default class HostSetModel extends GeneratedHostSetModel {
* @type {boolean}
*/
get isAWS() {
return this.compositeType === 'aws';
return this.compositeType === TYPE_HOST_CATALOG_PLUGIN_AWS;
}
/**
* Return if a host-set plugin is Azure or not.
*/
get isAzure() {
return this.compositeType === 'azure';
return this.compositeType === TYPE_HOST_CATALOG_PLUGIN_AZURE;
}
/**
* True if host catalog plugin type is GCP.
* @type {boolean}
*/
get isGCP() {
return this.compositeType === TYPE_HOST_CATALOG_PLUGIN_GCP;
}
/**
+40 -10
View File
@@ -8,11 +8,23 @@ import { trait } from 'miragejs';
import permissions from '../helpers/permissions';
import { faker } from '@faker-js/faker';
import generateId from '../helpers/id';
import {
TYPE_HOST_CATALOG_PLUGIN_AZURE,
TYPE_HOST_CATALOG_PLUGIN_GCP,
TYPE_HOST_CATALOG_PLUGIN_AWS,
TYPE_HOST_CATALOG_STATIC,
TYPE_HOST_CATALOG_DYNAMIC,
TYPES_HOST_CATALOG,
} from 'api/models/host-catalog';
const types = ['static', 'plugin'];
// Represents known plugin types, except "foobar" which models the possibility
// of receiving an _unknown_ type, which the UI must handle gracefully.
const pluginTypes = ['aws', 'azure', 'foobar'];
const pluginTypes = [
TYPE_HOST_CATALOG_PLUGIN_GCP,
TYPE_HOST_CATALOG_PLUGIN_AWS,
TYPE_HOST_CATALOG_PLUGIN_AZURE,
'foobar',
];
let pluginTypeCounter = 1;
@@ -20,7 +32,7 @@ export default factory.extend({
id: () => generateId('hc_'),
// Cycle through available types
type: (i) => types[i % types.length],
type: (i) => TYPES_HOST_CATALOG[i % TYPES_HOST_CATALOG.length],
authorized_actions: () =>
permissions.authorizedActionsFor('host-catalog') || [
@@ -30,7 +42,7 @@ export default factory.extend({
'delete',
],
authorized_collection_actions: function () {
const isStatic = this.type === 'static';
const isStatic = this.type === TYPE_HOST_CATALOG_STATIC;
return {
// only static catalogs allow host create at this time
hosts: isStatic ? ['create', 'list'] : ['list'],
@@ -39,13 +51,16 @@ export default factory.extend({
},
worker_filter: function () {
if (this.type === 'plugin' && this.plugin?.name === 'aws') {
if (
this.type === TYPE_HOST_CATALOG_DYNAMIC &&
this.plugin?.name === TYPE_HOST_CATALOG_PLUGIN_AWS
) {
return `"${faker.word.noun()}" in "${faker.system.directoryPath()}"`;
}
},
plugin: function (i) {
if (this.type === 'plugin') {
if (this.type === TYPE_HOST_CATALOG_DYNAMIC) {
return {
id: `plugin-id-${i}`,
name: pluginTypes[pluginTypeCounter++ % pluginTypes.length],
@@ -56,35 +71,50 @@ export default factory.extend({
attributes() {
switch (this.plugin?.name) {
case 'aws':
case TYPE_HOST_CATALOG_PLUGIN_AWS:
return {
disable_credential_rotation: faker.datatype.boolean(),
region: `us-${faker.location.cardinalDirection()}-${faker.number.int(
9,
)}`,
};
case 'azure':
case TYPE_HOST_CATALOG_PLUGIN_AZURE:
return {
disable_credential_rotation: faker.datatype.boolean(),
tenant_id: faker.string.uuid(),
client_id: faker.string.uuid(),
subscription_id: faker.string.uuid(),
};
case TYPE_HOST_CATALOG_PLUGIN_GCP:
return {
disable_credential_rotation: faker.datatype.boolean(),
project_id: faker.string.uuid(),
client_email: faker.internet.email(),
target_service_account_id: faker.string.uuid(),
zone: `us-${faker.location.cardinalDirection()}${faker.number.int(
9,
)}-${faker.string.fromCharacters('abc')}`,
};
}
},
secrets() {
switch (this.plugin?.name) {
case 'aws':
case TYPE_HOST_CATALOG_PLUGIN_AWS:
return {
access_key_id: faker.string.nanoid(),
secret_access_key: faker.string.nanoid(),
};
case 'azure':
case TYPE_HOST_CATALOG_PLUGIN_AZURE:
return {
secret_id: faker.string.nanoid(),
secret_value: faker.string.nanoid(),
};
case TYPE_HOST_CATALOG_PLUGIN_GCP:
return {
private_key: faker.string.nanoid(),
private_key_id: faker.string.nanoid(),
};
}
},
withChildren: trait({