prepare service management

This commit is contained in:
2024-06-13 09:36:02 +02:00
parent 6dd687012f
commit a6e3a7f5fe
23 changed files with 607 additions and 341 deletions

View File

View File

@ -0,0 +1,13 @@
import * as plugins from '../plugins.js';
export const demoImages: plugins.servezoneInterfaces.data.IImage[] = [
{
id: 'DemoImage1',
data: {
name: 'DemoImage1',
description: 'DemoImage1',
versions: [],
}
}
];

View File

@ -0,0 +1,85 @@
import * as plugins from '../plugins.js';
// Create an array to hold 10 ISecretGroup objects
const demoSecretGroups: plugins.servezoneInterfaces.data.ISecretGroup[] = [];
// Generate 10 ISecretGroup objects
for (let i = 1; i <= 10; i++) {
const secretGroup: plugins.servezoneInterfaces.data.ISecretGroup = {
id: `${plugins.smartunique.shortId(8)}`,
data: {
name: `Demo Secret Group ${i}`,
description: `This is a demo secret group for testing purposes ${i}`,
key: `CI_RUNNER_TOKEN_${i}`,
priority: i,
tags: [
{
key: 'project',
value: `my_project_${i}`,
},
{
key: 'environment',
value: i % 2 === 0 ? 'staging' : 'production',
},
],
environments: {
production: {
value: `prod_secret_value_${i}`,
lastUpdated: 1630522000 + i,
history: [
{
timestamp: String(1630521000 + i),
value: `old_prod_value_${i}`,
},
],
},
staging: {
value: `stag_secret_value_${i}`,
updateToken: `updateToken${i}`,
lastUpdated: 1630522500 + i,
history: [
{
timestamp: String(1630521500 + i),
value: `old_stag_value_${i}`,
},
],
},
},
},
};
// Push each ISecretGroup object into the array
demoSecretGroups.push(secretGroup);
}
// Create an array to hold 10 IConfigBundle objects
const demoConfigBundles: plugins.servezoneInterfaces.data.ISecretBundle[] = [];
// Generate 10 IConfigBundle objects that match demoSecretGroups
for (let i = 0; i < demoSecretGroups.length; i++) {
const secretGroup = demoSecretGroups[i];
const configBundle: plugins.servezoneInterfaces.data.ISecretBundle = {
id: `configBundleId${i + 1}`,
data: {
name: `Demo Config Bundle ${i + 1}`,
includedImages: [],
type: 'external',
description: 'Demo Purpose',
includedSecretGroupIds: [secretGroup.id],
includedTags: secretGroup.data.tags,
authorizations: Object.keys(secretGroup.data.environments).map((env) => {
return {
secretAccessKey: `mockSecretAccessKeyFor${env}`,
environment: env,
};
}),
},
};
// Push each IConfigBundle object into the array
demoConfigBundles.push(configBundle);
}
// Exporting the array of demo IConfigBundle objects
export { demoSecretGroups, demoConfigBundles };

View File

@ -0,0 +1,19 @@
import * as plugins from '../plugins.js';
import * as paths from '../paths.js';
import type { Cloudly } from '../classes.cloudly.js';
export const getUsers = async (cloudlyRef: Cloudly) => {
const users: plugins.servezoneInterfaces.data.IUser[] = [];
const envAdminUser = await cloudlyRef.config.appData.waitForAndGetKey('servezoneAdminaccount');
if (envAdminUser) {
users.push({
id: 'envadmin',
data: {
username: envAdminUser.split(':')[0],
password: envAdminUser.split(':')[1],
role: 'admin',
},
});
}
return users;
};

65
ts/00demo/index.ts Normal file
View File

@ -0,0 +1,65 @@
import type { Cloudly } from '../classes.cloudly.js';
export const installDemoData = async (cloudlyRef: Cloudly) => {
// ================================================================================
// SECRETS
const demoDataSecrets = await import('./demo.data.secrets.js');
const secretGroups = await cloudlyRef.secretManager.CSecretGroup.getInstances({});
for (const secretGroup of secretGroups) {
await secretGroup.delete();
}
const secretBundles = await cloudlyRef.secretManager.CSecretBundle.getInstances({});
for (const secretBundle of secretBundles) {
await secretBundle.delete();
}
for (const secretData of demoDataSecrets.demoSecretGroups) {
const secretGroup = new cloudlyRef.secretManager.CSecretGroup();
Object.assign(secretGroup, secretData);
await secretGroup.save();
}
for (const secretBundleData of demoDataSecrets.demoConfigBundles) {
const secretBundle = new cloudlyRef.secretManager.CSecretBundle();
Object.assign(secretBundle, secretBundleData);
await secretBundle.save();
}
// ================================================================================
// CLUSTERS
const clusters = await cloudlyRef.clusterManager.CCluster.getInstances({});
for (const cluster of clusters) {
await cluster.delete();
}
// ================================================================================
// USERS
const users = await cloudlyRef.authManager.CUser.getInstances({});
for (const user of users) {
await user.delete();
}
const demoDataUsers = await import('./demo.data.users.js');
for (const user of await demoDataUsers.getUsers(cloudlyRef)) {
const userInstance = new cloudlyRef.authManager.CUser();
Object.assign(userInstance, user);
await userInstance.save();
}
// ================================================================================
// IMAGES
const images = await cloudlyRef.imageManager.CImage.getInstances({});
for (const image of images) {
await image.delete();
}
const demoDataImages = await import('./demo.data.images.js');
for (const image of demoDataImages.demoImages) {
const imageInstance = new cloudlyRef.imageManager.CImage();
Object.assign(imageInstance, image);
await imageInstance.save();
}
}