mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-16 19:28:35 +00:00
feat: corrected v1 and v2 server name conflict and added all routes
This commit is contained in:
+2
-2
@@ -4,9 +4,9 @@ import { ormify, selectAllTableCols, sqlNestRelationships } from "@app/lib/knex"
|
||||
|
||||
import { buildAuthMethods } from "../identity/identity-fns";
|
||||
|
||||
export type TIdentityDALFactory = ReturnType<typeof identityDALFactory>;
|
||||
export type TIdentityV2DALFactory = ReturnType<typeof identityV2DALFactory>;
|
||||
|
||||
export const identityDALFactory = (db: TDbClient) => {
|
||||
export const identityV2DALFactory = (db: TDbClient) => {
|
||||
const orm = ormify(db, TableName.Identity);
|
||||
|
||||
const getIdentityById = async (scopeData: AccessScopeData, identityId: string) => {
|
||||
+17
-17
@@ -6,19 +6,19 @@ import { BadRequestError, NotFoundError } from "@app/lib/errors";
|
||||
import { TIdentityMetadataDALFactory } from "../identity/identity-metadata-dal";
|
||||
import { TMembershipRoleDALFactory } from "../membership/membership-role-dal";
|
||||
import { TMembershipIdentityDALFactory } from "../membership-identity/membership-identity-dal";
|
||||
import { TIdentityDALFactory } from "./identity-dal";
|
||||
import { TIdentityV2DALFactory } from "./identity-dal";
|
||||
import {
|
||||
TCreateIdentityDTO,
|
||||
TDeleteIdentityDTO,
|
||||
TGetIdentityByIdDTO,
|
||||
TListIdentityDTO,
|
||||
TUpdateIdentityDTO
|
||||
TCreateIdentityV2DTO,
|
||||
TDeleteIdentityV2DTO,
|
||||
TGetIdentityByIdV2DTO,
|
||||
TListIdentityV2DTO,
|
||||
TUpdateIdentityV2DTO
|
||||
} from "./identity-types";
|
||||
import { newOrgIdentityFactory } from "./org/org-identity-factory";
|
||||
import { newProjectIdentityFactory } from "./project/project-identity-factory";
|
||||
|
||||
type TScopedIdentityServiceFactoryDep = {
|
||||
identityDAL: TIdentityDALFactory;
|
||||
type TScopedIdentityV2ServiceFactoryDep = {
|
||||
identityDAL: TIdentityV2DALFactory;
|
||||
permissionService: TPermissionServiceFactory;
|
||||
licenseService: Pick<TLicenseServiceFactory, "getPlan" | "updateSubscriptionOrgMemberCount">;
|
||||
membershipIdentityDAL: TMembershipIdentityDALFactory;
|
||||
@@ -26,16 +26,16 @@ type TScopedIdentityServiceFactoryDep = {
|
||||
identityMetadataDAL: TIdentityMetadataDALFactory;
|
||||
};
|
||||
|
||||
export type TScopedIdentityServiceFactory = ReturnType<typeof identityServiceFactory>;
|
||||
export type TScopedIdentityV2ServiceFactory = ReturnType<typeof identityV2ServiceFactory>;
|
||||
|
||||
export const identityServiceFactory = ({
|
||||
export const identityV2ServiceFactory = ({
|
||||
identityDAL,
|
||||
permissionService,
|
||||
licenseService,
|
||||
membershipIdentityDAL,
|
||||
membershipRoleDAL,
|
||||
identityMetadataDAL
|
||||
}: TScopedIdentityServiceFactoryDep) => {
|
||||
}: TScopedIdentityV2ServiceFactoryDep) => {
|
||||
const orgFactory = newOrgIdentityFactory({
|
||||
permissionService
|
||||
});
|
||||
@@ -50,7 +50,7 @@ export const identityServiceFactory = ({
|
||||
[AccessScope.Namespace]: orgFactory
|
||||
};
|
||||
|
||||
const createIdentity = async (dto: TCreateIdentityDTO) => {
|
||||
const createIdentity = async (dto: TCreateIdentityV2DTO) => {
|
||||
const { scopeData, data } = dto;
|
||||
const factory = scopeFactory[scopeData.scope];
|
||||
|
||||
@@ -134,7 +134,7 @@ export const identityServiceFactory = ({
|
||||
return { identity };
|
||||
};
|
||||
|
||||
const updateIdentity = async (dto: TUpdateIdentityDTO) => {
|
||||
const updateIdentity = async (dto: TUpdateIdentityV2DTO) => {
|
||||
const { scopeData, data } = dto;
|
||||
const factory = scopeFactory[scopeData.scope];
|
||||
|
||||
@@ -187,7 +187,7 @@ export const identityServiceFactory = ({
|
||||
return { identity };
|
||||
};
|
||||
|
||||
const deleteIdentity = async (dto: TDeleteIdentityDTO) => {
|
||||
const deleteIdentity = async (dto: TDeleteIdentityV2DTO) => {
|
||||
const { scopeData } = dto;
|
||||
const factory = scopeFactory[scopeData.scope];
|
||||
|
||||
@@ -208,7 +208,7 @@ export const identityServiceFactory = ({
|
||||
return { identity: deletedIdentity };
|
||||
};
|
||||
|
||||
const getIdentityById = async (dto: TGetIdentityByIdDTO) => {
|
||||
const getIdentityById = async (dto: TGetIdentityByIdV2DTO) => {
|
||||
const { scopeData } = dto;
|
||||
const factory = scopeFactory[scopeData.scope];
|
||||
|
||||
@@ -220,7 +220,7 @@ export const identityServiceFactory = ({
|
||||
return { identity };
|
||||
};
|
||||
|
||||
const listIdentities = async (dto: TListIdentityDTO) => {
|
||||
const listIdentities = async (dto: TListIdentityV2DTO) => {
|
||||
const { scopeData } = dto;
|
||||
const factory = scopeFactory[scopeData.scope];
|
||||
|
||||
@@ -232,7 +232,7 @@ export const identityServiceFactory = ({
|
||||
limit: dto.data.limit
|
||||
});
|
||||
|
||||
return { identities };
|
||||
return identities;
|
||||
};
|
||||
|
||||
return {
|
||||
+11
-11
@@ -1,12 +1,12 @@
|
||||
import { AccessScopeData } from "@app/db/schemas";
|
||||
import { OrderByDirection, OrgServiceActor } from "@app/lib/types";
|
||||
|
||||
export interface TIdentityFactory {
|
||||
onCreateIdentityGuard: (arg: TCreateIdentityDTO) => Promise<void>;
|
||||
onUpdateIdentityGuard: (arg: TUpdateIdentityDTO) => Promise<void>;
|
||||
onDeleteIdentityGuard: (arg: TDeleteIdentityDTO) => Promise<void>;
|
||||
onListIdentityGuard: (arg: TListIdentityDTO) => Promise<void>;
|
||||
onGetIdentityByIdGuard: (arg: TGetIdentityByIdDTO) => Promise<void>;
|
||||
export interface TIdentityV2Factory {
|
||||
onCreateIdentityGuard: (arg: TCreateIdentityV2DTO) => Promise<void>;
|
||||
onUpdateIdentityGuard: (arg: TUpdateIdentityV2DTO) => Promise<void>;
|
||||
onDeleteIdentityGuard: (arg: TDeleteIdentityV2DTO) => Promise<void>;
|
||||
onListIdentityGuard: (arg: TListIdentityV2DTO) => Promise<void>;
|
||||
onGetIdentityByIdGuard: (arg: TGetIdentityByIdV2DTO) => Promise<void>;
|
||||
getScopeField: (scope: AccessScopeData) => { key: "orgId" | "namespaceId" | "projectId"; value: string };
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ export enum IdentityOrderBy {
|
||||
Role = "role"
|
||||
}
|
||||
|
||||
export type TCreateIdentityDTO = {
|
||||
export type TCreateIdentityV2DTO = {
|
||||
permission: OrgServiceActor;
|
||||
scopeData: AccessScopeData;
|
||||
data: {
|
||||
@@ -25,7 +25,7 @@ export type TCreateIdentityDTO = {
|
||||
};
|
||||
};
|
||||
|
||||
export type TUpdateIdentityDTO = {
|
||||
export type TUpdateIdentityV2DTO = {
|
||||
permission: OrgServiceActor;
|
||||
scopeData: AccessScopeData;
|
||||
selector: {
|
||||
@@ -38,7 +38,7 @@ export type TUpdateIdentityDTO = {
|
||||
}>;
|
||||
};
|
||||
|
||||
export type TDeleteIdentityDTO = {
|
||||
export type TDeleteIdentityV2DTO = {
|
||||
permission: OrgServiceActor;
|
||||
scopeData: AccessScopeData;
|
||||
selector: {
|
||||
@@ -46,7 +46,7 @@ export type TDeleteIdentityDTO = {
|
||||
};
|
||||
};
|
||||
|
||||
export type TGetIdentityByIdDTO = {
|
||||
export type TGetIdentityByIdV2DTO = {
|
||||
permission: OrgServiceActor;
|
||||
scopeData: AccessScopeData;
|
||||
selector: {
|
||||
@@ -54,7 +54,7 @@ export type TGetIdentityByIdDTO = {
|
||||
};
|
||||
};
|
||||
|
||||
export type TListIdentityDTO = {
|
||||
export type TListIdentityV2DTO = {
|
||||
permission: OrgServiceActor;
|
||||
scopeData: AccessScopeData;
|
||||
data: Partial<{
|
||||
+8
-8
@@ -5,21 +5,21 @@ import { OrgPermissionIdentityActions, OrgPermissionSubjects } from "@app/ee/ser
|
||||
import { TPermissionServiceFactory } from "@app/ee/services/permission/permission-service-types";
|
||||
import { InternalServerError } from "@app/lib/errors";
|
||||
|
||||
import { TIdentityFactory } from "../identity-types";
|
||||
import { TIdentityV2Factory } from "../identity-types";
|
||||
|
||||
type TOrgIdentityFactoryDep = {
|
||||
permissionService: Pick<TPermissionServiceFactory, "getOrgPermission">;
|
||||
};
|
||||
|
||||
export const newOrgIdentityFactory = ({ permissionService }: TOrgIdentityFactoryDep): TIdentityFactory => {
|
||||
const getScopeField: TIdentityFactory["getScopeField"] = (scopeData) => {
|
||||
export const newOrgIdentityFactory = ({ permissionService }: TOrgIdentityFactoryDep): TIdentityV2Factory => {
|
||||
const getScopeField: TIdentityV2Factory["getScopeField"] = (scopeData) => {
|
||||
if (scopeData.scope === AccessScope.Organization) {
|
||||
return { key: "orgId" as const, value: scopeData.orgId };
|
||||
}
|
||||
throw new InternalServerError({ message: "Invalid scope provided for the org factory" });
|
||||
};
|
||||
|
||||
const onCreateIdentityGuard: TIdentityFactory["onCreateIdentityGuard"] = async (dto) => {
|
||||
const onCreateIdentityGuard: TIdentityV2Factory["onCreateIdentityGuard"] = async (dto) => {
|
||||
const { permission } = await permissionService.getOrgPermission({
|
||||
actor: dto.permission.type,
|
||||
actorId: dto.permission.id,
|
||||
@@ -31,7 +31,7 @@ export const newOrgIdentityFactory = ({ permissionService }: TOrgIdentityFactory
|
||||
ForbiddenError.from(permission).throwUnlessCan(OrgPermissionIdentityActions.Create, OrgPermissionSubjects.Identity);
|
||||
};
|
||||
|
||||
const onUpdateIdentityGuard: TIdentityFactory["onUpdateIdentityGuard"] = async (dto) => {
|
||||
const onUpdateIdentityGuard: TIdentityV2Factory["onUpdateIdentityGuard"] = async (dto) => {
|
||||
const { permission } = await permissionService.getOrgPermission({
|
||||
actor: dto.permission.type,
|
||||
actorId: dto.permission.id,
|
||||
@@ -43,7 +43,7 @@ export const newOrgIdentityFactory = ({ permissionService }: TOrgIdentityFactory
|
||||
ForbiddenError.from(permission).throwUnlessCan(OrgPermissionIdentityActions.Edit, OrgPermissionSubjects.Identity);
|
||||
};
|
||||
|
||||
const onDeleteIdentityGuard: TIdentityFactory["onDeleteIdentityGuard"] = async (dto) => {
|
||||
const onDeleteIdentityGuard: TIdentityV2Factory["onDeleteIdentityGuard"] = async (dto) => {
|
||||
const { permission } = await permissionService.getOrgPermission({
|
||||
actor: dto.permission.type,
|
||||
actorId: dto.permission.id,
|
||||
@@ -55,7 +55,7 @@ export const newOrgIdentityFactory = ({ permissionService }: TOrgIdentityFactory
|
||||
ForbiddenError.from(permission).throwUnlessCan(OrgPermissionIdentityActions.Delete, OrgPermissionSubjects.Identity);
|
||||
};
|
||||
|
||||
const onListIdentityGuard: TIdentityFactory["onListIdentityGuard"] = async (dto) => {
|
||||
const onListIdentityGuard: TIdentityV2Factory["onListIdentityGuard"] = async (dto) => {
|
||||
const { permission } = await permissionService.getOrgPermission({
|
||||
actor: dto.permission.type,
|
||||
actorId: dto.permission.id,
|
||||
@@ -67,7 +67,7 @@ export const newOrgIdentityFactory = ({ permissionService }: TOrgIdentityFactory
|
||||
ForbiddenError.from(permission).throwUnlessCan(OrgPermissionIdentityActions.Read, OrgPermissionSubjects.Identity);
|
||||
};
|
||||
|
||||
const onGetIdentityByIdGuard: TIdentityFactory["onGetIdentityByIdGuard"] = async (dto) => {
|
||||
const onGetIdentityByIdGuard: TIdentityV2Factory["onGetIdentityByIdGuard"] = async (dto) => {
|
||||
const { permission } = await permissionService.getOrgPermission({
|
||||
actor: dto.permission.type,
|
||||
actorId: dto.permission.id,
|
||||
+8
-8
@@ -5,21 +5,21 @@ import { TPermissionServiceFactory } from "@app/ee/services/permission/permissio
|
||||
import { ProjectPermissionIdentityActions, ProjectPermissionSub } from "@app/ee/services/permission/project-permission";
|
||||
import { InternalServerError } from "@app/lib/errors";
|
||||
|
||||
import { TIdentityFactory } from "../identity-types";
|
||||
import { TIdentityV2Factory } from "../identity-types";
|
||||
|
||||
type TProjectIdentityFactoryDep = {
|
||||
permissionService: Pick<TPermissionServiceFactory, "getProjectPermission">;
|
||||
};
|
||||
|
||||
export const newProjectIdentityFactory = ({ permissionService }: TProjectIdentityFactoryDep): TIdentityFactory => {
|
||||
const getScopeField: TIdentityFactory["getScopeField"] = (scopeData) => {
|
||||
export const newProjectIdentityFactory = ({ permissionService }: TProjectIdentityFactoryDep): TIdentityV2Factory => {
|
||||
const getScopeField: TIdentityV2Factory["getScopeField"] = (scopeData) => {
|
||||
if (scopeData.scope === AccessScope.Project) {
|
||||
return { key: "projectId" as const, value: scopeData.projectId };
|
||||
}
|
||||
throw new InternalServerError({ message: "Invalid scope provided for the project factory" });
|
||||
};
|
||||
|
||||
const onCreateIdentityGuard: TIdentityFactory["onCreateIdentityGuard"] = async (dto) => {
|
||||
const onCreateIdentityGuard: TIdentityV2Factory["onCreateIdentityGuard"] = async (dto) => {
|
||||
const scope = getScopeField(dto.scopeData);
|
||||
const { permission } = await permissionService.getProjectPermission({
|
||||
actor: dto.permission.type,
|
||||
@@ -35,7 +35,7 @@ export const newProjectIdentityFactory = ({ permissionService }: TProjectIdentit
|
||||
);
|
||||
};
|
||||
|
||||
const onUpdateIdentityGuard: TIdentityFactory["onUpdateIdentityGuard"] = async (dto) => {
|
||||
const onUpdateIdentityGuard: TIdentityV2Factory["onUpdateIdentityGuard"] = async (dto) => {
|
||||
const scope = getScopeField(dto.scopeData);
|
||||
const { permission } = await permissionService.getProjectPermission({
|
||||
actor: dto.permission.type,
|
||||
@@ -51,7 +51,7 @@ export const newProjectIdentityFactory = ({ permissionService }: TProjectIdentit
|
||||
);
|
||||
};
|
||||
|
||||
const onDeleteIdentityGuard: TIdentityFactory["onDeleteIdentityGuard"] = async (dto) => {
|
||||
const onDeleteIdentityGuard: TIdentityV2Factory["onDeleteIdentityGuard"] = async (dto) => {
|
||||
const scope = getScopeField(dto.scopeData);
|
||||
const { permission } = await permissionService.getProjectPermission({
|
||||
actor: dto.permission.type,
|
||||
@@ -67,7 +67,7 @@ export const newProjectIdentityFactory = ({ permissionService }: TProjectIdentit
|
||||
);
|
||||
};
|
||||
|
||||
const onListIdentityGuard: TIdentityFactory["onListIdentityGuard"] = async (dto) => {
|
||||
const onListIdentityGuard: TIdentityV2Factory["onListIdentityGuard"] = async (dto) => {
|
||||
const scope = getScopeField(dto.scopeData);
|
||||
const { permission } = await permissionService.getProjectPermission({
|
||||
actor: dto.permission.type,
|
||||
@@ -83,7 +83,7 @@ export const newProjectIdentityFactory = ({ permissionService }: TProjectIdentit
|
||||
);
|
||||
};
|
||||
|
||||
const onGetIdentityByIdGuard: TIdentityFactory["onGetIdentityByIdGuard"] = async (dto) => {
|
||||
const onGetIdentityByIdGuard: TIdentityV2Factory["onGetIdentityByIdGuard"] = async (dto) => {
|
||||
const scope = getScopeField(dto.scopeData);
|
||||
const { permission } = await permissionService.getProjectPermission({
|
||||
actor: dto.permission.type,
|
||||
+1
-1
@@ -12,11 +12,11 @@ import {
|
||||
ProjectPermissionSub
|
||||
} from "@app/ee/services/permission/project-permission";
|
||||
import { BadRequestError, InternalServerError, PermissionBoundaryError } from "@app/lib/errors";
|
||||
import { TIdentityDALFactory } from "@app/services/identity/identity-dal";
|
||||
import { TOrgDALFactory } from "@app/services/org/org-dal";
|
||||
|
||||
import { TMembershipIdentityDALFactory } from "../membership-identity-dal";
|
||||
import { TMembershipIdentityScopeFactory } from "../membership-identity-types";
|
||||
import { TIdentityDALFactory } from "@app/services/identity/identity-dal";
|
||||
|
||||
type TProjectMembershipIdentityScopeFactoryDep = {
|
||||
permissionService: Pick<TPermissionServiceFactory, "getProjectPermission" | "getProjectPermissionByRoles">;
|
||||
|
||||
Reference in New Issue
Block a user