fix(big fix upgrade): upgrade multiple areas of the core functionalities

This commit is contained in:
2024-10-16 14:35:38 +02:00
parent d212dfb9f9
commit 53f96095c7
37 changed files with 2141 additions and 618 deletions

View File

@@ -1,5 +1,6 @@
import * as plugins from '../plugins.js';
import { Cloudly } from '../classes.cloudly.js';
import type { Cluster } from '../manager.cluster/classes.cluster.js';
/**
* in charge of talking to coreflow services on clusters
@@ -13,38 +14,41 @@ export class CloudlyCoreflowManager {
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 cluster =
await this.cloudlyRef.clusterManager.getClusterBy_JumpCode(
requestData.jumpCode
);
if (!cluster) {
throw new plugins.typedrequest.TypedResponseError('The supplied jumpCode is not valid. No cluster found.');
}
this.typedRouter.addTypedHandler<plugins.servezoneInterfaces.requests.identity.IRequest_Any_Cloudly_CoreflowManager_GetIdentityByToken>(
new plugins.typedrequest.TypedHandler('getIdentityByToken', async (requestData) => {
const user = await this.cloudlyRef.authManager.CUser.getInstance({
id: cluster.data.userId,
data: {
tokens: [{
token: requestData.token,
}] // find the proper user here.
} as any
});
if (!user) {
throw new plugins.typedrequest.TypedResponseError('The supplied jumpCode is not valid. No user found.');
throw new plugins.typedrequest.TypedResponseError('The supplied token is not valid. No matching user found.');
}
if (user.data.type !== 'machine') {
throw new plugins.typedrequest.TypedResponseError('The supplied token is not valid. The user is not a machine.');
}
let cluster: Cluster;
if (user.data.role === 'cluster') {
cluster = await this.cloudlyRef.clusterManager.getClusterBy_UserId(user.id);
}
const expiryTimestamp = Date.now() + 3600 * 1000 * 24 * 365;
return {
identity: {
name: cluster.data.name,
role: 'cluster',
type: 'machine',
userId: cluster.data.userId,
name: user.data.username,
role: user.data.role,
type: 'machine', // if someone authenticates by token, they are a machine, no matter what.
userId: user.id,
expiresAt: expiryTimestamp,
clusterId: cluster.id,
clusterName: cluster.data.name,
...(cluster ? {
clusterId: cluster.id,
clusterName: cluster.data.name,
} : {}),
jwt: await this.cloudlyRef.authManager.smartjwtInstance.createJWT({
status: 'loggedIn',
userId: cluster.data.userId,
userId: user.id,
expiresAt: expiryTimestamp,
})
},