Update ST V3 to machine identity

This commit is contained in:
Tuan Dang
2023-11-24 19:19:31 +07:00
parent 41c41a647f
commit 595a26a366
71 changed files with 651 additions and 697 deletions
@@ -13,9 +13,9 @@ import picomatch from "picomatch";
import { AuthData } from "../../interfaces/middleware";
import { ActorType, IRole } from "../models";
import {
IServiceTokenDataV3,
Membership,
ServiceMembership,
IMachineIdentity,
MachineMembership,
Membership,
ServiceTokenData
} from "../../models";
import { ADMIN, CUSTOM, MEMBER, VIEWER } from "../../variables";
@@ -290,13 +290,13 @@ export const getAuthDataProjectPermissions = async ({
break;
}
case ActorType.SERVICE_V3: {
const serviceMembership = await ServiceMembership.findOne({
service: authData.authPayload._id,
const serviceMembership = await MachineMembership.findOne({
machineIdentity: authData.authPayload._id,
workspace: workspaceId
})
.populate<{
customRole: IRole & { permissions: RawRuleOf<MongoAbility<ProjectPermissionSet>>[] };
service: IServiceTokenDataV3
machineIdentity: IMachineIdentity
}>("customRole service")
.exec();
@@ -306,7 +306,7 @@ export const getAuthDataProjectPermissions = async ({
checkIPAgainstBlocklist({
ipAddress: authData.ipAddress,
trustedIps: serviceMembership.service.trustedIps
trustedIps: serviceMembership.machineIdentity.trustedIps
});
role = serviceMembership.role;