- Added CloudlyTaskManager class for managing tasks, including registration, execution, scheduling, and cancellation. - Created predefined tasks: DNS Sync, Certificate Renewal, Cleanup, Health Check, Resource Report, Database Maintenance, Security Scan, and Docker Cleanup. - Introduced ITaskExecution interface for tracking task execution details and outcomes. - Developed API request interfaces for task management operations (getTasks, getTaskExecutions, triggerTask, cancelTask). - Implemented CloudlyViewTasks web component for displaying tasks and their execution history, including filtering and detailed views.
		
			
				
	
	
		
			131 lines
		
	
	
		
			4.6 KiB
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
			
		
		
	
	
			131 lines
		
	
	
		
			4.6 KiB
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
| import * as plugins from '../plugins.js';
 | |
| import { Cloudly } from '../classes.cloudly.js';
 | |
| import { ExternalRegistry } from './classes.externalregistry.js';
 | |
| 
 | |
| export class ExternalRegistryManager {
 | |
|   public cloudlyRef: Cloudly;
 | |
|   public typedrouter = new plugins.typedrequest.TypedRouter();
 | |
|   public CExternalRegistry = plugins.smartdata.setDefaultManagerForDoc(this, ExternalRegistry);
 | |
| 
 | |
|   get db() {
 | |
|     return this.cloudlyRef.mongodbConnector.smartdataDb;
 | |
|   }
 | |
| 
 | |
|   constructor(cloudlyRef: Cloudly) {
 | |
|     this.cloudlyRef = cloudlyRef;
 | |
|     
 | |
|     // Add typedrouter to cloudly's main router
 | |
|     this.cloudlyRef.typedrouter.addTypedRouter(this.typedrouter);
 | |
| 
 | |
|     // Get registry by ID
 | |
|     this.typedrouter.addTypedHandler<plugins.servezoneInterfaces.requests.externalRegistry.IReq_GetRegistryById>(
 | |
|       new plugins.typedrequest.TypedHandler('getExternalRegistryById', async (dataArg) => {
 | |
|         await plugins.smartguard.passGuardsOrReject(dataArg, [
 | |
|           this.cloudlyRef.authManager.validIdentityGuard,
 | |
|         ]);
 | |
|         
 | |
|         const registry = await this.CExternalRegistry.getRegistryById(dataArg.id);
 | |
|         if (!registry) {
 | |
|           throw new Error(`Registry with id ${dataArg.id} not found`);
 | |
|         }
 | |
|         return {
 | |
|           registry: await registry.createSavableObject(),
 | |
|         };
 | |
|       })
 | |
|     );
 | |
| 
 | |
|     // Get all registries
 | |
|     this.typedrouter.addTypedHandler<plugins.servezoneInterfaces.requests.externalRegistry.IReq_GetRegistries>(
 | |
|       new plugins.typedrequest.TypedHandler('getExternalRegistries', async (dataArg) => {
 | |
|         await plugins.smartguard.passGuardsOrReject(dataArg, [
 | |
|           this.cloudlyRef.authManager.validIdentityGuard,
 | |
|         ]);
 | |
|         
 | |
|         const registries = await this.CExternalRegistry.getRegistries();
 | |
|         return {
 | |
|           registries: await Promise.all(
 | |
|             registries.map((registry) => registry.createSavableObject())
 | |
|           ),
 | |
|         };
 | |
|       })
 | |
|     );
 | |
| 
 | |
|     // Create registry
 | |
|     this.typedrouter.addTypedHandler<plugins.servezoneInterfaces.requests.externalRegistry.IReq_CreateRegistry>(
 | |
|       new plugins.typedrequest.TypedHandler('createExternalRegistry', async (dataArg) => {
 | |
|         await plugins.smartguard.passGuardsOrReject(dataArg, [
 | |
|           this.cloudlyRef.authManager.validIdentityGuard,
 | |
|         ]);
 | |
|         
 | |
|         const registry = await this.CExternalRegistry.createExternalRegistry(dataArg.registryData);
 | |
|         return {
 | |
|           registry: await registry.createSavableObject(),
 | |
|         };
 | |
|       })
 | |
|     );
 | |
| 
 | |
|     // Update registry
 | |
|     this.typedrouter.addTypedHandler<plugins.servezoneInterfaces.requests.externalRegistry.IReq_UpdateRegistry>(
 | |
|       new plugins.typedrequest.TypedHandler('updateExternalRegistry', async (dataArg) => {
 | |
|         await plugins.smartguard.passGuardsOrReject(dataArg, [
 | |
|           this.cloudlyRef.authManager.validIdentityGuard,
 | |
|         ]);
 | |
|         
 | |
|         const registry = await this.CExternalRegistry.updateExternalRegistry(
 | |
|           dataArg.registryId,
 | |
|           dataArg.registryData
 | |
|         );
 | |
|         return {
 | |
|           resultRegistry: await registry.createSavableObject(),
 | |
|         };
 | |
|       })
 | |
|     );
 | |
| 
 | |
|     // Delete registry
 | |
|     this.typedrouter.addTypedHandler<plugins.servezoneInterfaces.requests.externalRegistry.IReq_DeleteRegistryById>(
 | |
|       new plugins.typedrequest.TypedHandler('deleteExternalRegistryById', async (dataArg) => {
 | |
|         await plugins.smartguard.passGuardsOrReject(dataArg, [
 | |
|           this.cloudlyRef.authManager.validIdentityGuard,
 | |
|         ]);
 | |
|         
 | |
|         const success = await this.CExternalRegistry.deleteExternalRegistry(dataArg.registryId);
 | |
|         return {
 | |
|           ok: success,
 | |
|         };
 | |
|       })
 | |
|     );
 | |
| 
 | |
|     // Verify registry connection
 | |
|     this.typedrouter.addTypedHandler<plugins.servezoneInterfaces.requests.externalRegistry.IReq_VerifyRegistry>(
 | |
|       new plugins.typedrequest.TypedHandler('verifyExternalRegistry', async (dataArg) => {
 | |
|         await plugins.smartguard.passGuardsOrReject(dataArg, [
 | |
|           this.cloudlyRef.authManager.validIdentityGuard,
 | |
|         ]);
 | |
|         
 | |
|         const registry = await this.CExternalRegistry.getRegistryById(dataArg.registryId);
 | |
|         if (!registry) {
 | |
|           return {
 | |
|             success: false,
 | |
|             message: `Registry with id ${dataArg.registryId} not found`,
 | |
|           };
 | |
|         }
 | |
|         
 | |
|         const result = await registry.verifyConnection();
 | |
|         return {
 | |
|           success: result.success,
 | |
|           message: result.message,
 | |
|           registry: await registry.createSavableObject(),
 | |
|         };
 | |
|       })
 | |
|     );
 | |
|   }
 | |
| 
 | |
|   public async start() {
 | |
|     console.log('External Registry Manager started');
 | |
|   }
 | |
| 
 | |
|   public async stop() {
 | |
|     console.log('External Registry Manager stopped');
 | |
|   }
 | |
| }
 |