mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-07 16:27:40 +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
|
||||||
@@ -32,13 +34,13 @@ export const getServiceTokenData = async (req: Request, res: Response) => {
|
|||||||
"application/json": {
|
"application/json": {
|
||||||
"schema": {
|
"schema": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
"serviceTokenData": {
|
"serviceTokenData": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
$ref: "#/components/schemas/ServiceTokenData",
|
$ref: "#/components/schemas/ServiceTokenData",
|
||||||
"description": "Details of service token"
|
"description": "Details of service token"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -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