feat(external-registry): Implement CRUD operations and connection verification for external registries
This commit is contained in:
@@ -13,23 +13,34 @@ export class ExternalRegistryManager {
|
||||
|
||||
constructor(cloudlyRef: Cloudly) {
|
||||
this.cloudlyRef = cloudlyRef;
|
||||
}
|
||||
|
||||
public async start() {
|
||||
// lets set up a typedrouter
|
||||
this.typedrouter.addTypedRouter(this.typedrouter);
|
||||
|
||||
// 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 ExternalRegistry.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 ExternalRegistry.getRegistries();
|
||||
return {
|
||||
registries: await Promise.all(
|
||||
@@ -39,13 +50,81 @@ export class ExternalRegistryManager {
|
||||
})
|
||||
);
|
||||
|
||||
// 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 ExternalRegistry.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 ExternalRegistry.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 ExternalRegistry.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 ExternalRegistry.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');
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user