mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-09-22 13:39:35 +00:00
Merge pull request #1128 from Infisical/mongodb-dep
Remove mongodb direct dependency from backend
This commit is contained in:
1
backend/package-lock.json
generated
1
backend/package-lock.json
generated
@@ -43,7 +43,6 @@
|
|||||||
"jsrp": "^0.2.4",
|
"jsrp": "^0.2.4",
|
||||||
"libsodium-wrappers": "^0.7.10",
|
"libsodium-wrappers": "^0.7.10",
|
||||||
"lodash": "^4.17.21",
|
"lodash": "^4.17.21",
|
||||||
"mongodb": "^5.7.0",
|
|
||||||
"mongoose": "^7.4.1",
|
"mongoose": "^7.4.1",
|
||||||
"nanoid": "^3.3.6",
|
"nanoid": "^3.3.6",
|
||||||
"node-cache": "^5.1.2",
|
"node-cache": "^5.1.2",
|
||||||
|
|||||||
@@ -34,7 +34,6 @@
|
|||||||
"jsrp": "^0.2.4",
|
"jsrp": "^0.2.4",
|
||||||
"libsodium-wrappers": "^0.7.10",
|
"libsodium-wrappers": "^0.7.10",
|
||||||
"lodash": "^4.17.21",
|
"lodash": "^4.17.21",
|
||||||
"mongodb": "^5.7.0",
|
|
||||||
"mongoose": "^7.4.1",
|
"mongoose": "^7.4.1",
|
||||||
"nanoid": "^3.3.6",
|
"nanoid": "^3.3.6",
|
||||||
"node-cache": "^5.1.2",
|
"node-cache": "^5.1.2",
|
||||||
|
|||||||
@@ -28,7 +28,6 @@ import {
|
|||||||
} from "../../ee/services/ProjectRoleService";
|
} from "../../ee/services/ProjectRoleService";
|
||||||
import { ForbiddenError } from "@casl/ability";
|
import { ForbiddenError } from "@casl/ability";
|
||||||
import { getIntegrationAuthAccessHelper } from "../../helpers";
|
import { getIntegrationAuthAccessHelper } from "../../helpers";
|
||||||
import { ObjectId } from "mongodb";
|
|
||||||
|
|
||||||
/***
|
/***
|
||||||
* Return integration authorization with id [integrationAuthId]
|
* Return integration authorization with id [integrationAuthId]
|
||||||
@@ -222,7 +221,7 @@ export const getIntegrationAuthApps = async (req: Request, res: Response) => {
|
|||||||
|
|
||||||
// TODO(akhilmhdh): remove class -> static function path and makes these into reusable independent functions
|
// TODO(akhilmhdh): remove class -> static function path and makes these into reusable independent functions
|
||||||
const { integrationAuth, accessToken, accessId } = await getIntegrationAuthAccessHelper({
|
const { integrationAuth, accessToken, accessId } = await getIntegrationAuthAccessHelper({
|
||||||
integrationAuthId: new ObjectId(integrationAuthId)
|
integrationAuthId: new Types.ObjectId(integrationAuthId)
|
||||||
});
|
});
|
||||||
|
|
||||||
const { permission } = await getUserProjectPermissions(
|
const { permission } = await getUserProjectPermissions(
|
||||||
@@ -260,7 +259,7 @@ export const getIntegrationAuthTeams = async (req: Request, res: Response) => {
|
|||||||
|
|
||||||
// TODO(akhilmhdh): remove class -> static function path and makes these into reusable independent functions
|
// TODO(akhilmhdh): remove class -> static function path and makes these into reusable independent functions
|
||||||
const { integrationAuth, accessToken } = await getIntegrationAuthAccessHelper({
|
const { integrationAuth, accessToken } = await getIntegrationAuthAccessHelper({
|
||||||
integrationAuthId: new ObjectId(integrationAuthId)
|
integrationAuthId: new Types.ObjectId(integrationAuthId)
|
||||||
});
|
});
|
||||||
|
|
||||||
const { permission } = await getUserProjectPermissions(
|
const { permission } = await getUserProjectPermissions(
|
||||||
@@ -296,7 +295,7 @@ export const getIntegrationAuthVercelBranches = async (req: Request, res: Respon
|
|||||||
|
|
||||||
// TODO(akhilmhdh): remove class -> static function path and makes these into reusable independent functions
|
// TODO(akhilmhdh): remove class -> static function path and makes these into reusable independent functions
|
||||||
const { integrationAuth, accessToken } = await getIntegrationAuthAccessHelper({
|
const { integrationAuth, accessToken } = await getIntegrationAuthAccessHelper({
|
||||||
integrationAuthId: new ObjectId(integrationAuthId)
|
integrationAuthId: new Types.ObjectId(integrationAuthId)
|
||||||
});
|
});
|
||||||
|
|
||||||
const { permission } = await getUserProjectPermissions(
|
const { permission } = await getUserProjectPermissions(
|
||||||
@@ -357,7 +356,7 @@ export const getIntegrationAuthQoveryOrgs = async (req: Request, res: Response)
|
|||||||
|
|
||||||
// TODO(akhilmhdh): remove class -> static function path and makes these into reusable independent functions
|
// TODO(akhilmhdh): remove class -> static function path and makes these into reusable independent functions
|
||||||
const { integrationAuth, accessToken } = await getIntegrationAuthAccessHelper({
|
const { integrationAuth, accessToken } = await getIntegrationAuthAccessHelper({
|
||||||
integrationAuthId: new ObjectId(integrationAuthId)
|
integrationAuthId: new Types.ObjectId(integrationAuthId)
|
||||||
});
|
});
|
||||||
|
|
||||||
const { permission } = await getUserProjectPermissions(
|
const { permission } = await getUserProjectPermissions(
|
||||||
@@ -409,7 +408,7 @@ export const getIntegrationAuthQoveryProjects = async (req: Request, res: Respon
|
|||||||
|
|
||||||
// TODO(akhilmhdh): remove class -> static function path and makes these into reusable independent functions
|
// TODO(akhilmhdh): remove class -> static function path and makes these into reusable independent functions
|
||||||
const { integrationAuth, accessToken } = await getIntegrationAuthAccessHelper({
|
const { integrationAuth, accessToken } = await getIntegrationAuthAccessHelper({
|
||||||
integrationAuthId: new ObjectId(integrationAuthId)
|
integrationAuthId: new Types.ObjectId(integrationAuthId)
|
||||||
});
|
});
|
||||||
|
|
||||||
const { permission } = await getUserProjectPermissions(
|
const { permission } = await getUserProjectPermissions(
|
||||||
@@ -470,7 +469,7 @@ export const getIntegrationAuthQoveryEnvironments = async (req: Request, res: Re
|
|||||||
|
|
||||||
// TODO(akhilmhdh): remove class -> static function path and makes these into reusable independent functions
|
// TODO(akhilmhdh): remove class -> static function path and makes these into reusable independent functions
|
||||||
const { integrationAuth, accessToken } = await getIntegrationAuthAccessHelper({
|
const { integrationAuth, accessToken } = await getIntegrationAuthAccessHelper({
|
||||||
integrationAuthId: new ObjectId(integrationAuthId)
|
integrationAuthId: new Types.ObjectId(integrationAuthId)
|
||||||
});
|
});
|
||||||
|
|
||||||
const { permission } = await getUserProjectPermissions(
|
const { permission } = await getUserProjectPermissions(
|
||||||
@@ -531,7 +530,7 @@ export const getIntegrationAuthQoveryApps = async (req: Request, res: Response)
|
|||||||
|
|
||||||
// TODO(akhilmhdh): remove class -> static function path and makes these into reusable independent functions
|
// TODO(akhilmhdh): remove class -> static function path and makes these into reusable independent functions
|
||||||
const { integrationAuth, accessToken } = await getIntegrationAuthAccessHelper({
|
const { integrationAuth, accessToken } = await getIntegrationAuthAccessHelper({
|
||||||
integrationAuthId: new ObjectId(integrationAuthId)
|
integrationAuthId: new Types.ObjectId(integrationAuthId)
|
||||||
});
|
});
|
||||||
|
|
||||||
const { permission } = await getUserProjectPermissions(
|
const { permission } = await getUserProjectPermissions(
|
||||||
@@ -592,7 +591,7 @@ export const getIntegrationAuthQoveryContainers = async (req: Request, res: Resp
|
|||||||
|
|
||||||
// TODO(akhilmhdh): remove class -> static function path and makes these into reusable independent functions
|
// TODO(akhilmhdh): remove class -> static function path and makes these into reusable independent functions
|
||||||
const { integrationAuth, accessToken } = await getIntegrationAuthAccessHelper({
|
const { integrationAuth, accessToken } = await getIntegrationAuthAccessHelper({
|
||||||
integrationAuthId: new ObjectId(integrationAuthId)
|
integrationAuthId: new Types.ObjectId(integrationAuthId)
|
||||||
});
|
});
|
||||||
|
|
||||||
const { permission } = await getUserProjectPermissions(
|
const { permission } = await getUserProjectPermissions(
|
||||||
@@ -653,7 +652,7 @@ export const getIntegrationAuthQoveryJobs = async (req: Request, res: Response)
|
|||||||
|
|
||||||
// TODO(akhilmhdh): remove class -> static function path and makes these into reusable independent functions
|
// TODO(akhilmhdh): remove class -> static function path and makes these into reusable independent functions
|
||||||
const { integrationAuth, accessToken } = await getIntegrationAuthAccessHelper({
|
const { integrationAuth, accessToken } = await getIntegrationAuthAccessHelper({
|
||||||
integrationAuthId: new ObjectId(integrationAuthId)
|
integrationAuthId: new Types.ObjectId(integrationAuthId)
|
||||||
});
|
});
|
||||||
|
|
||||||
const { permission } = await getUserProjectPermissions(
|
const { permission } = await getUserProjectPermissions(
|
||||||
@@ -715,7 +714,7 @@ export const getIntegrationAuthRailwayEnvironments = async (req: Request, res: R
|
|||||||
|
|
||||||
// TODO(akhilmhdh): remove class -> static function path and makes these into reusable independent functions
|
// TODO(akhilmhdh): remove class -> static function path and makes these into reusable independent functions
|
||||||
const { integrationAuth, accessToken } = await getIntegrationAuthAccessHelper({
|
const { integrationAuth, accessToken } = await getIntegrationAuthAccessHelper({
|
||||||
integrationAuthId: new ObjectId(integrationAuthId)
|
integrationAuthId: new Types.ObjectId(integrationAuthId)
|
||||||
});
|
});
|
||||||
|
|
||||||
const { permission } = await getUserProjectPermissions(
|
const { permission } = await getUserProjectPermissions(
|
||||||
@@ -808,7 +807,7 @@ export const getIntegrationAuthRailwayServices = async (req: Request, res: Respo
|
|||||||
|
|
||||||
// TODO(akhilmhdh): remove class -> static function path and makes these into reusable independent functions
|
// TODO(akhilmhdh): remove class -> static function path and makes these into reusable independent functions
|
||||||
const { integrationAuth, accessToken } = await getIntegrationAuthAccessHelper({
|
const { integrationAuth, accessToken } = await getIntegrationAuthAccessHelper({
|
||||||
integrationAuthId: new ObjectId(integrationAuthId)
|
integrationAuthId: new Types.ObjectId(integrationAuthId)
|
||||||
});
|
});
|
||||||
|
|
||||||
const { permission } = await getUserProjectPermissions(
|
const { permission } = await getUserProjectPermissions(
|
||||||
@@ -932,7 +931,7 @@ export const getIntegrationAuthBitBucketWorkspaces = async (req: Request, res: R
|
|||||||
|
|
||||||
// TODO(akhilmhdh): remove class -> static function path and makes these into reusable independent functions
|
// TODO(akhilmhdh): remove class -> static function path and makes these into reusable independent functions
|
||||||
const { integrationAuth, accessToken } = await getIntegrationAuthAccessHelper({
|
const { integrationAuth, accessToken } = await getIntegrationAuthAccessHelper({
|
||||||
integrationAuthId: new ObjectId(integrationAuthId)
|
integrationAuthId: new Types.ObjectId(integrationAuthId)
|
||||||
});
|
});
|
||||||
|
|
||||||
const { permission } = await getUserProjectPermissions(
|
const { permission } = await getUserProjectPermissions(
|
||||||
@@ -988,7 +987,7 @@ export const getIntegrationAuthNorthflankSecretGroups = async (req: Request, res
|
|||||||
|
|
||||||
// TODO(akhilmhdh): remove class -> static function path and makes these into reusable independent functions
|
// TODO(akhilmhdh): remove class -> static function path and makes these into reusable independent functions
|
||||||
const { integrationAuth, accessToken } = await getIntegrationAuthAccessHelper({
|
const { integrationAuth, accessToken } = await getIntegrationAuthAccessHelper({
|
||||||
integrationAuthId: new ObjectId(integrationAuthId)
|
integrationAuthId: new Types.ObjectId(integrationAuthId)
|
||||||
});
|
});
|
||||||
|
|
||||||
const { permission } = await getUserProjectPermissions(
|
const { permission } = await getUserProjectPermissions(
|
||||||
@@ -1076,7 +1075,7 @@ export const getIntegrationAuthTeamCityBuildConfigs = async (req: Request, res:
|
|||||||
|
|
||||||
// TODO(akhilmhdh): remove class -> static function path and makes these into reusable independent functions
|
// TODO(akhilmhdh): remove class -> static function path and makes these into reusable independent functions
|
||||||
const { integrationAuth, accessToken } = await getIntegrationAuthAccessHelper({
|
const { integrationAuth, accessToken } = await getIntegrationAuthAccessHelper({
|
||||||
integrationAuthId: new ObjectId(integrationAuthId)
|
integrationAuthId: new Types.ObjectId(integrationAuthId)
|
||||||
});
|
});
|
||||||
|
|
||||||
const { permission } = await getUserProjectPermissions(
|
const { permission } = await getUserProjectPermissions(
|
||||||
@@ -1145,7 +1144,7 @@ export const deleteIntegrationAuth = async (req: Request, res: Response) => {
|
|||||||
|
|
||||||
// TODO(akhilmhdh): remove class -> static function path and makes these into reusable independent functions
|
// TODO(akhilmhdh): remove class -> static function path and makes these into reusable independent functions
|
||||||
const { integrationAuth, accessToken } = await getIntegrationAuthAccessHelper({
|
const { integrationAuth, accessToken } = await getIntegrationAuthAccessHelper({
|
||||||
integrationAuthId: new ObjectId(integrationAuthId)
|
integrationAuthId: new Types.ObjectId(integrationAuthId)
|
||||||
});
|
});
|
||||||
|
|
||||||
const { permission } = await getUserProjectPermissions(
|
const { permission } = await getUserProjectPermissions(
|
||||||
|
|||||||
@@ -11,7 +11,6 @@ import {
|
|||||||
ValidationError as RouteValidationError,
|
ValidationError as RouteValidationError,
|
||||||
UnauthorizedRequestError
|
UnauthorizedRequestError
|
||||||
} from "../../utils/errors";
|
} from "../../utils/errors";
|
||||||
import { AnyBulkWriteOperation } from "mongodb";
|
|
||||||
import {
|
import {
|
||||||
ALGORITHM_AES_256_GCM,
|
ALGORITHM_AES_256_GCM,
|
||||||
ENCODING_SCHEME_UTF8,
|
ENCODING_SCHEME_UTF8,
|
||||||
@@ -19,7 +18,7 @@ import {
|
|||||||
SECRET_SHARED
|
SECRET_SHARED
|
||||||
} from "../../variables";
|
} from "../../variables";
|
||||||
import { TelemetryService } from "../../services";
|
import { TelemetryService } from "../../services";
|
||||||
import { ISecret, Secret, User } from "../../models";
|
import { Secret, User } from "../../models";
|
||||||
import { AccountNotFoundError } from "../../utils/errors";
|
import { AccountNotFoundError } from "../../utils/errors";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -145,22 +144,22 @@ export const deleteSecrets = async (req: Request, res: Response) => {
|
|||||||
const secretsUserCanDeleteSet: Set<string> = new Set(
|
const secretsUserCanDeleteSet: Set<string> = new Set(
|
||||||
secretIdsUserCanDelete.map((objectId) => objectId._id.toString())
|
secretIdsUserCanDelete.map((objectId) => objectId._id.toString())
|
||||||
);
|
);
|
||||||
const deleteOperationsToPerform: AnyBulkWriteOperation<ISecret>[] = [];
|
|
||||||
|
|
||||||
let numSecretsDeleted = 0;
|
// Filter out IDs that user can delete and then map them to delete operations
|
||||||
secretIdsToDelete.forEach((secretIdToDelete) => {
|
const deleteOperationsToPerform = secretIdsToDelete
|
||||||
if (secretsUserCanDeleteSet.has(secretIdToDelete)) {
|
.filter(secretIdToDelete => {
|
||||||
const deleteOperation = {
|
if (!secretsUserCanDeleteSet.has(secretIdToDelete)) {
|
||||||
deleteOne: { filter: { _id: new Types.ObjectId(secretIdToDelete) } }
|
throw RouteValidationError({
|
||||||
};
|
message: "You cannot delete secrets that you do not have access to"
|
||||||
deleteOperationsToPerform.push(deleteOperation);
|
});
|
||||||
numSecretsDeleted++;
|
}
|
||||||
} else {
|
return true;
|
||||||
throw RouteValidationError({
|
})
|
||||||
message: "You cannot delete secrets that you do not have access to"
|
.map(secretIdToDelete => ({
|
||||||
});
|
deleteOne: { filter: { _id: new Types.ObjectId(secretIdToDelete) } }
|
||||||
}
|
}));
|
||||||
});
|
|
||||||
|
const numSecretsDeleted = deleteOperationsToPerform.length;
|
||||||
|
|
||||||
await Secret.bulkWrite(deleteOperationsToPerform);
|
await Secret.bulkWrite(deleteOperationsToPerform);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user