74 lines
2.7 KiB
TypeScript
74 lines
2.7 KiB
TypeScript
|
import * as plugins from '../cloudly.plugins.js';
|
||
|
import { Cloudly } from '../cloudly.classes.cloudly.js';
|
||
|
|
||
|
/**
|
||
|
* in charge of talking to coreflow services on clusters
|
||
|
* coreflow runs on a server when ServerManager is done.
|
||
|
*/
|
||
|
export class CloudlyCoreflowManager {
|
||
|
public cloudlyRef: Cloudly;
|
||
|
public typedRouter = new plugins.typedrequest.TypedRouter();
|
||
|
|
||
|
constructor(cloudlyRefArg: Cloudly) {
|
||
|
this.cloudlyRef = cloudlyRefArg;
|
||
|
this.cloudlyRef.typedrouter.addTypedRouter(this.typedRouter);
|
||
|
|
||
|
this.typedRouter.addTypedHandler<plugins.servezoneInterfaces.requests.identity.IRequest_Any_Cloudly_CoreflowManager_GetIdentityByJumpCode>(
|
||
|
new plugins.typedrequest.TypedHandler('getIdentityByJumpCode', async (requestData) => {
|
||
|
const clusterConfig =
|
||
|
await this.cloudlyRef.clusterManager.getClusterConfigBy_JumpCode(
|
||
|
requestData.jumpCode
|
||
|
);
|
||
|
|
||
|
if (!clusterConfig) {
|
||
|
throw new plugins.typedrequest.TypedResponseError('The supplied jumpCode is not valid.');
|
||
|
}
|
||
|
|
||
|
return {
|
||
|
clusterIdentifier: {
|
||
|
clusterName: clusterConfig.data.name,
|
||
|
secretKey: clusterConfig.data.secretKey,
|
||
|
},
|
||
|
};
|
||
|
})
|
||
|
);
|
||
|
|
||
|
// lets enable the getting of cluster configs
|
||
|
this.typedRouter.addTypedHandler(
|
||
|
new plugins.typedrequest.TypedHandler<plugins.servezoneInterfaces.requests.config.IRequest_Any_Cloudly_GetClusterConfig>(
|
||
|
'getClusterConfig',
|
||
|
async (dataArg) => {
|
||
|
const clusterIdentifier = dataArg.clusterIdentifier;
|
||
|
console.log('trying to get clusterConfigSet');
|
||
|
console.log(dataArg);
|
||
|
const clusterConfigSet =
|
||
|
await this.cloudlyRef.clusterManager.getClusterConfigBy_ClusterIdentifier(
|
||
|
clusterIdentifier
|
||
|
);
|
||
|
console.log('got cluster config and sending it back to coreflow');
|
||
|
return {
|
||
|
configData: await clusterConfigSet.createSavableObject()
|
||
|
};
|
||
|
}
|
||
|
)
|
||
|
);
|
||
|
|
||
|
// lets enable getting of certificates
|
||
|
this.typedRouter.addTypedHandler(
|
||
|
new plugins.typedrequest.TypedHandler<plugins.servezoneInterfaces.requests.certificate.IRequest_Any_Cloudly_GetSslCertificate>(
|
||
|
'getSslCertificate',
|
||
|
async (dataArg) => {
|
||
|
console.log(`got request for certificate ${dataArg.requiredCertName}`);
|
||
|
const cert = await this.cloudlyRef.letsencryptConnector.getCertificateForDomain(
|
||
|
dataArg.requiredCertName
|
||
|
);
|
||
|
console.log(`got certificate ready for reponse ${dataArg.requiredCertName}`);
|
||
|
return {
|
||
|
certificate: await cert.createSavableObject(),
|
||
|
};
|
||
|
}
|
||
|
)
|
||
|
);
|
||
|
}
|
||
|
}
|