mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-09-22 13:39:35 +00:00
feat: added convertor service
This commit is contained in:
@@ -1728,7 +1728,8 @@ export const registerRoutes = async (
|
||||
const convertorService = convertorServiceFactory({
|
||||
additionalPrivilegeDAL,
|
||||
membershipDAL,
|
||||
projectDAL
|
||||
projectDAL,
|
||||
groupDAL
|
||||
});
|
||||
|
||||
const dynamicSecretProviders = buildDynamicSecretProviders({
|
||||
|
||||
@@ -15,6 +15,7 @@ import { ms } from "@app/lib/ms";
|
||||
import { readLimit, writeLimit } from "@app/server/config/rateLimiter";
|
||||
import { verifyAuth } from "@app/server/plugins/auth/verify-auth";
|
||||
import { AuthMode } from "@app/services/auth/auth-type";
|
||||
import { isUuidV4 } from "@app/lib/validator";
|
||||
|
||||
export const registerGroupProjectRouter = async (server: FastifyZodProvider) => {
|
||||
server.route({
|
||||
@@ -74,10 +75,16 @@ export const registerGroupProjectRouter = async (server: FastifyZodProvider) =>
|
||||
}
|
||||
},
|
||||
handler: async (req) => {
|
||||
let groupId = req.params.groupIdOrName;
|
||||
if (!isUuidV4(req.params.groupIdOrName)) {
|
||||
const groupDetails = await server.services.convertor.getGroupIdFromName(groupId, req.permission.orgId);
|
||||
groupId = groupDetails.groupId;
|
||||
}
|
||||
|
||||
const { membership: groupMembership } = await server.services.membershipGroup.createMembership({
|
||||
permission: req.permission,
|
||||
data: {
|
||||
groupId: req.params.groupIdOrName,
|
||||
groupId,
|
||||
roles: req.body.roles || [{ role: req.body.role, isTemporary: false }]
|
||||
},
|
||||
scopeData: {
|
||||
|
||||
@@ -15,6 +15,7 @@ import { ms } from "@app/lib/ms";
|
||||
import { readLimit, writeLimit } from "@app/server/config/rateLimiter";
|
||||
import { verifyAuth } from "@app/server/plugins/auth/verify-auth";
|
||||
import { AuthMode } from "@app/services/auth/auth-type";
|
||||
import { isUuidV4 } from "@app/lib/validator";
|
||||
|
||||
export const registerDeprecatedGroupProjectRouter = async (server: FastifyZodProvider) => {
|
||||
server.route({
|
||||
@@ -74,10 +75,16 @@ export const registerDeprecatedGroupProjectRouter = async (server: FastifyZodPro
|
||||
}
|
||||
},
|
||||
handler: async (req) => {
|
||||
let groupId = req.params.groupIdOrName;
|
||||
if (!isUuidV4(req.params.groupIdOrName)) {
|
||||
const groupDetails = await server.services.convertor.getGroupIdFromName(groupId, req.permission.orgId);
|
||||
groupId = groupDetails.groupId;
|
||||
}
|
||||
|
||||
const { membership: groupMembership } = await server.services.membershipGroup.createMembership({
|
||||
permission: req.permission,
|
||||
data: {
|
||||
groupId: req.params.groupIdOrName,
|
||||
groupId,
|
||||
roles: req.body.roles || [{ role: req.body.role, isTemporary: false }]
|
||||
},
|
||||
scopeData: {
|
||||
|
||||
@@ -4,10 +4,12 @@ import { NotFoundError } from "@app/lib/errors";
|
||||
import { TAdditionalPrivilegeDALFactory } from "../additional-privilege/additional-privilege-dal";
|
||||
import { TMembershipDALFactory } from "../membership/membership-dal";
|
||||
import { TProjectDALFactory } from "../project/project-dal";
|
||||
import { TGroupDALFactory } from "@app/ee/services/group/group-dal";
|
||||
|
||||
type TConvertorServiceFactoryDep = {
|
||||
projectDAL: Pick<TProjectDALFactory, "findOne">;
|
||||
membershipDAL: Pick<TMembershipDALFactory, "findOne">;
|
||||
groupDAL: Pick<TGroupDALFactory, "findOne">;
|
||||
additionalPrivilegeDAL: Pick<TAdditionalPrivilegeDALFactory, "findOne">;
|
||||
};
|
||||
|
||||
@@ -16,7 +18,8 @@ export type TConvertorServiceFactory = ReturnType<typeof convertorServiceFactory
|
||||
export const convertorServiceFactory = ({
|
||||
projectDAL,
|
||||
membershipDAL,
|
||||
additionalPrivilegeDAL
|
||||
additionalPrivilegeDAL,
|
||||
groupDAL
|
||||
}: TConvertorServiceFactoryDep) => {
|
||||
const projectSlugToId = async (dto: { slug: string; orgId: string }) => {
|
||||
const project = await projectDAL.findOne({
|
||||
@@ -108,6 +111,12 @@ export const convertorServiceFactory = ({
|
||||
return { privilegeId: privilege.id, privilege };
|
||||
};
|
||||
|
||||
const getGroupIdFromName = async (name: string, orgId: string) => {
|
||||
const group = await groupDAL.findOne({ orgId, name });
|
||||
if (!group) throw new NotFoundError({ message: `Failed to find group with name ${name}` });
|
||||
return { groupId: group.id, group };
|
||||
};
|
||||
|
||||
return {
|
||||
projectSlugToId,
|
||||
userMembershipIdToUserId,
|
||||
@@ -115,6 +124,7 @@ export const convertorServiceFactory = ({
|
||||
identityMembershipIdToIdentityId,
|
||||
additionalPrivilegeIdToDoc,
|
||||
additionalPrivilegeNameToDoc,
|
||||
identityIdToMembershipId
|
||||
identityIdToMembershipId,
|
||||
getGroupIdFromName
|
||||
};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user