mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-09 22:28:25 +00:00
check path before service token create
This commit is contained in:
@@ -11,6 +11,8 @@ import {
|
|||||||
} from "../../variables";
|
} from "../../variables";
|
||||||
import { getSaltRounds } from "../../config";
|
import { getSaltRounds } from "../../config";
|
||||||
import { BadRequestError } from "../../utils/errors";
|
import { BadRequestError } from "../../utils/errors";
|
||||||
|
import Folder from "../../models/folder";
|
||||||
|
import { getFolderByPath } from "../../services/FolderService";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return service token data associated with service token on request
|
* Return service token data associated with service token on request
|
||||||
@@ -81,6 +83,18 @@ export const createServiceTokenData = async (req: Request, res: Response) => {
|
|||||||
permissions,
|
permissions,
|
||||||
} = req.body;
|
} = req.body;
|
||||||
|
|
||||||
|
const folders = await Folder.findOne({
|
||||||
|
workspace: workspaceId,
|
||||||
|
environment,
|
||||||
|
});
|
||||||
|
|
||||||
|
if (folders) {
|
||||||
|
const folder = getFolderByPath(folders.nodes, secretPath);
|
||||||
|
if (folder == undefined) {
|
||||||
|
throw BadRequestError({ message: "Path for service token does not exist" })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const secret = crypto.randomBytes(16).toString("hex");
|
const secret = crypto.randomBytes(16).toString("hex");
|
||||||
const secretHash = await bcrypt.hash(secret, await getSaltRounds());
|
const secretHash = await bcrypt.hash(secret, await getSaltRounds());
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user