mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-09-22 13:39:35 +00:00
removed redundancies
This commit is contained in:
@@ -1204,7 +1204,6 @@ export const registerRoutes = async (
|
||||
});
|
||||
|
||||
const externalMigrationQueue = externalMigrationQueueFactory({
|
||||
orgService,
|
||||
projectEnvService,
|
||||
projectDAL,
|
||||
projectService,
|
||||
|
||||
@@ -4,7 +4,7 @@ import sjcl from "sjcl";
|
||||
import tweetnacl from "tweetnacl";
|
||||
import tweetnaclUtil from "tweetnacl-util";
|
||||
|
||||
import { OrgMembershipRole, ProjectMembershipRole, SecretType } from "@app/db/schemas";
|
||||
import { SecretType } from "@app/db/schemas";
|
||||
import { BadRequestError, NotFoundError } from "@app/lib/errors";
|
||||
import { chunkArray } from "@app/lib/fn";
|
||||
import { logger } from "@app/lib/logger";
|
||||
@@ -12,7 +12,6 @@ import { alphaNumericNanoId } from "@app/lib/nanoid";
|
||||
|
||||
import { TKmsServiceFactory } from "../kms/kms-service";
|
||||
import { KmsDataKey } from "../kms/kms-types";
|
||||
import { TOrgServiceFactory } from "../org/org-service";
|
||||
import { TProjectDALFactory } from "../project/project-dal";
|
||||
import { TProjectServiceFactory } from "../project/project-service";
|
||||
import { TProjectEnvDALFactory } from "../project-env/project-env-dal";
|
||||
@@ -38,7 +37,6 @@ export type TImportDataIntoInfisicalDTO = {
|
||||
|
||||
folderDAL: Pick<TSecretFolderDALFactory, "create" | "findBySecretPath">;
|
||||
projectService: Pick<TProjectServiceFactory, "createProject">;
|
||||
orgService: Pick<TOrgServiceFactory, "inviteUserToOrganization">;
|
||||
projectEnvService: Pick<TProjectEnvServiceFactory, "createEnvironment">;
|
||||
secretV2BridgeService: Pick<TSecretV2BridgeServiceFactory, "createManySecret">;
|
||||
|
||||
@@ -113,7 +111,6 @@ export const importDataIntoInfisicalFn = async ({
|
||||
projectService,
|
||||
projectEnvDAL,
|
||||
projectDAL,
|
||||
orgService,
|
||||
secretDAL,
|
||||
kmsService,
|
||||
secretVersionDAL,
|
||||
@@ -150,26 +147,6 @@ export const importDataIntoInfisicalFn = async ({
|
||||
originalToNewProjectId.set(project.id, newProject.id);
|
||||
}
|
||||
|
||||
// Invite user importing projects
|
||||
const invites = await orgService.inviteUserToOrganization({
|
||||
verifyPermissions: false,
|
||||
actorAuthMethod,
|
||||
actorId,
|
||||
actorOrgId,
|
||||
actor,
|
||||
inviteeEmails: [],
|
||||
orgId: actorOrgId,
|
||||
organizationRoleSlug: OrgMembershipRole.NoAccess,
|
||||
projects: Array.from(originalToNewProjectId.values()).map((project) => ({
|
||||
id: project,
|
||||
projectRoleSlug: [ProjectMembershipRole.Member]
|
||||
})),
|
||||
tx
|
||||
});
|
||||
if (!invites) {
|
||||
throw new BadRequestError({ message: `Failed to invite user to projects: [userId:${actorId}]` });
|
||||
}
|
||||
|
||||
// Import environments
|
||||
if (data.environments) {
|
||||
for await (const environment of data.environments) {
|
||||
|
||||
@@ -4,7 +4,6 @@ import { logger } from "@app/lib/logger";
|
||||
import { QueueJobs, QueueName, TQueueServiceFactory } from "@app/queue";
|
||||
|
||||
import { TKmsServiceFactory } from "../kms/kms-service";
|
||||
import { TOrgServiceFactory } from "../org/org-service";
|
||||
import { TProjectDALFactory } from "../project/project-dal";
|
||||
import { TProjectServiceFactory } from "../project/project-service";
|
||||
import { TProjectEnvDALFactory } from "../project-env/project-env-dal";
|
||||
@@ -34,7 +33,6 @@ export type TExternalMigrationQueueFactoryDep = {
|
||||
|
||||
folderDAL: Pick<TSecretFolderDALFactory, "create" | "findBySecretPath">;
|
||||
projectService: Pick<TProjectServiceFactory, "createProject">;
|
||||
orgService: Pick<TOrgServiceFactory, "inviteUserToOrganization">;
|
||||
projectEnvService: Pick<TProjectEnvServiceFactory, "createEnvironment">;
|
||||
secretV2BridgeService: Pick<TSecretV2BridgeServiceFactory, "createManySecret">;
|
||||
};
|
||||
@@ -44,7 +42,6 @@ export type TExternalMigrationQueueFactory = ReturnType<typeof externalMigration
|
||||
export const externalMigrationQueueFactory = ({
|
||||
queueService,
|
||||
projectService,
|
||||
orgService,
|
||||
smtpService,
|
||||
projectDAL,
|
||||
projectEnvService,
|
||||
@@ -111,7 +108,6 @@ export const externalMigrationQueueFactory = ({
|
||||
folderDAL,
|
||||
kmsService,
|
||||
projectService,
|
||||
orgService,
|
||||
projectEnvService,
|
||||
secretV2BridgeService
|
||||
});
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import { ForbiddenError, MongoAbility } from "@casl/ability";
|
||||
import { ForbiddenError } from "@casl/ability";
|
||||
import slugify from "@sindresorhus/slugify";
|
||||
import { MongoQuery } from "@ucast/mongo2js";
|
||||
import crypto from "crypto";
|
||||
import jwt from "jsonwebtoken";
|
||||
import { Knex } from "knex";
|
||||
@@ -20,11 +19,7 @@ import { TProjects } from "@app/db/schemas/projects";
|
||||
import { TGroupDALFactory } from "@app/ee/services/group/group-dal";
|
||||
import { TLicenseServiceFactory } from "@app/ee/services/license/license-service";
|
||||
import { TOidcConfigDALFactory } from "@app/ee/services/oidc/oidc-config-dal";
|
||||
import {
|
||||
OrgPermissionActions,
|
||||
OrgPermissionSet,
|
||||
OrgPermissionSubjects
|
||||
} from "@app/ee/services/permission/org-permission";
|
||||
import { OrgPermissionActions, OrgPermissionSubjects } from "@app/ee/services/permission/org-permission";
|
||||
import { TPermissionServiceFactory } from "@app/ee/services/permission/permission-service";
|
||||
import { ProjectPermissionActions, ProjectPermissionSub } from "@app/ee/services/permission/project-permission";
|
||||
import { TProjectUserAdditionalPrivilegeDALFactory } from "@app/ee/services/project-user-additional-privilege/project-user-additional-privilege-dal";
|
||||
@@ -492,17 +487,11 @@ export const orgServiceFactory = ({
|
||||
organizationRoleSlug,
|
||||
projects: invitedProjects,
|
||||
actorAuthMethod,
|
||||
actorOrgId,
|
||||
tx: trx,
|
||||
verifyPermissions = true
|
||||
actorOrgId
|
||||
}: TInviteUserToOrgDTO) => {
|
||||
const appCfg = getConfig();
|
||||
|
||||
let permission: MongoAbility<OrgPermissionSet, MongoQuery> | undefined;
|
||||
if (verifyPermissions) {
|
||||
permission = (await permissionService.getOrgPermission(actor, actorId, orgId, actorAuthMethod, actorOrgId))
|
||||
.permission;
|
||||
}
|
||||
const { permission } = await permissionService.getOrgPermission(actor, actorId, orgId, actorAuthMethod, actorOrgId);
|
||||
|
||||
const org = await orgDAL.findOrgById(orgId);
|
||||
|
||||
@@ -523,15 +512,12 @@ export const orgServiceFactory = ({
|
||||
}
|
||||
|
||||
const projectsToInvite = invitedProjects?.length
|
||||
? await projectDAL.find(
|
||||
{
|
||||
orgId,
|
||||
$in: {
|
||||
id: invitedProjects?.map(({ id }) => id)
|
||||
}
|
||||
},
|
||||
{ tx: trx }
|
||||
)
|
||||
? await projectDAL.find({
|
||||
orgId,
|
||||
$in: {
|
||||
id: invitedProjects?.map(({ id }) => id)
|
||||
}
|
||||
})
|
||||
: [];
|
||||
if (projectsToInvite.length !== invitedProjects?.length) {
|
||||
throw new ForbiddenRequestError({
|
||||
@@ -548,7 +534,7 @@ export const orgServiceFactory = ({
|
||||
const mailsForOrgInvitation: { email: string; userId: string; firstName: string; lastName: string }[] = [];
|
||||
const mailsForProjectInvitation: { email: string[]; projectName: string }[] = [];
|
||||
const newProjectMemberships: TProjectMemberships[] = [];
|
||||
await (trx || orgDAL).transaction(async (tx) => {
|
||||
await orgDAL.transaction(async (tx) => {
|
||||
const users: Pick<TUsers, "id" | "firstName" | "lastName" | "email" | "username">[] = [];
|
||||
|
||||
for await (const inviteeEmail of inviteeEmails) {
|
||||
@@ -634,16 +620,8 @@ export const orgServiceFactory = ({
|
||||
});
|
||||
}
|
||||
|
||||
if (verifyPermissions) {
|
||||
if (!permission) {
|
||||
throw new ForbiddenRequestError({
|
||||
name: "InviteUser",
|
||||
message: "Failed to invite user because no permission was found"
|
||||
});
|
||||
}
|
||||
// as its used by project invite also
|
||||
ForbiddenError.from(permission).throwUnlessCan(OrgPermissionActions.Create, OrgPermissionSubjects.Member);
|
||||
}
|
||||
// as its used by project invite also
|
||||
ForbiddenError.from(permission).throwUnlessCan(OrgPermissionActions.Create, OrgPermissionSubjects.Member);
|
||||
let roleId;
|
||||
const orgRole = isCustomOrgRole ? OrgMembershipRole.Custom : organizationRoleSlug;
|
||||
if (isCustomOrgRole) {
|
||||
@@ -684,19 +662,17 @@ export const orgServiceFactory = ({
|
||||
// if there exist no project membership we set is as given by the request
|
||||
for await (const project of projectsToInvite) {
|
||||
const projectId = project.id;
|
||||
if (verifyPermissions) {
|
||||
const { permission: projectPermission } = await permissionService.getProjectPermission(
|
||||
actor,
|
||||
actorId,
|
||||
projectId,
|
||||
actorAuthMethod,
|
||||
actorOrgId
|
||||
);
|
||||
ForbiddenError.from(projectPermission).throwUnlessCan(
|
||||
ProjectPermissionActions.Create,
|
||||
ProjectPermissionSub.Member
|
||||
);
|
||||
}
|
||||
const { permission: projectPermission } = await permissionService.getProjectPermission(
|
||||
actor,
|
||||
actorId,
|
||||
projectId,
|
||||
actorAuthMethod,
|
||||
actorOrgId
|
||||
);
|
||||
ForbiddenError.from(projectPermission).throwUnlessCan(
|
||||
ProjectPermissionActions.Create,
|
||||
ProjectPermissionSub.Member
|
||||
);
|
||||
const existingMembers = await projectMembershipDAL.find(
|
||||
{
|
||||
projectId: project.id,
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
import { Knex } from "knex";
|
||||
|
||||
import { TOrgPermission } from "@app/lib/types";
|
||||
|
||||
import { ActorAuthMethod, ActorType } from "../auth/auth-type";
|
||||
@@ -30,8 +28,6 @@ export type TDeleteOrgMembershipDTO = {
|
||||
export type TInviteUserToOrgDTO = {
|
||||
inviteeEmails: string[];
|
||||
organizationRoleSlug: string;
|
||||
tx?: Knex;
|
||||
verifyPermissions?: boolean;
|
||||
projects?: {
|
||||
id: string;
|
||||
projectRoleSlug?: string[];
|
||||
|
||||
@@ -39,8 +39,7 @@ export const projectEnvServiceFactory = ({
|
||||
actorAuthMethod,
|
||||
position,
|
||||
name,
|
||||
slug,
|
||||
tx: trx
|
||||
slug
|
||||
}: TCreateEnvDTO) => {
|
||||
const { permission } = await permissionService.getProjectPermission(
|
||||
actor,
|
||||
@@ -84,7 +83,7 @@ export const projectEnvServiceFactory = ({
|
||||
});
|
||||
}
|
||||
|
||||
const env = await (trx || projectEnvDAL).transaction(async (tx) => {
|
||||
const env = await projectEnvDAL.transaction(async (tx) => {
|
||||
if (position !== undefined) {
|
||||
// Check if there's an environment at the specified position
|
||||
const existingEnvWithPosition = await projectEnvDAL.findOne({ projectId, position }, tx);
|
||||
|
||||
@@ -1,12 +1,9 @@
|
||||
import { Knex } from "knex";
|
||||
|
||||
import { TProjectPermission } from "@app/lib/types";
|
||||
|
||||
export type TCreateEnvDTO = {
|
||||
name: string;
|
||||
slug: string;
|
||||
position?: number;
|
||||
tx?: Knex;
|
||||
} & TProjectPermission;
|
||||
|
||||
export type TUpdateEnvDTO = {
|
||||
|
||||
@@ -911,8 +911,7 @@ export const secretV2BridgeServiceFactory = ({
|
||||
actorOrgId,
|
||||
environment,
|
||||
projectId,
|
||||
secrets: inputSecrets,
|
||||
tx: trx
|
||||
secrets: inputSecrets
|
||||
}: TCreateManySecretDTO) => {
|
||||
const { permission } = await permissionService.getProjectPermission(
|
||||
actor,
|
||||
@@ -952,7 +951,7 @@ export const secretV2BridgeServiceFactory = ({
|
||||
const { encryptor: secretManagerEncryptor, decryptor: secretManagerDecryptor } =
|
||||
await kmsService.createCipherPairWithDataKey({ type: KmsDataKey.SecretManager, projectId });
|
||||
|
||||
const newSecrets = await (trx || secretDAL).transaction(async (tx) =>
|
||||
const newSecrets = await secretDAL.transaction(async (tx) =>
|
||||
fnSecretBulkInsert({
|
||||
inputSecrets: inputSecrets.map((el) => {
|
||||
const references = getAllNestedSecretReferences(el.secretValue);
|
||||
|
||||
@@ -81,7 +81,6 @@ export type TCreateManySecretDTO = Omit<TProjectPermission, "projectId"> & {
|
||||
secretPath: string;
|
||||
projectId: string;
|
||||
environment: string;
|
||||
tx?: Knex;
|
||||
secrets: {
|
||||
secretKey: string;
|
||||
secretValue: string;
|
||||
|
||||
Reference in New Issue
Block a user