mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-06 10:28:22 +00:00
Requested changes
This commit is contained in:
@@ -201,7 +201,7 @@ export const SECRETS = {
|
|||||||
type: "The type of the secret to attach tags to. (shared/personal)",
|
type: "The type of the secret to attach tags to. (shared/personal)",
|
||||||
environment: "The slug of the environment where the secret is located",
|
environment: "The slug of the environment where the secret is located",
|
||||||
projectSlug: "The slug of the project where the secret is located",
|
projectSlug: "The slug of the project where the secret is located",
|
||||||
tagSlugs: "An array of tag slugs to attach to the secret."
|
tagSlugs: "An array of existing tag slugs to attach to the secret."
|
||||||
},
|
},
|
||||||
DETACH_TAGS: {
|
DETACH_TAGS: {
|
||||||
secretName: "The name of the secret to detach tags from.",
|
secretName: "The name of the secret to detach tags from.",
|
||||||
@@ -209,7 +209,7 @@ export const SECRETS = {
|
|||||||
type: "The type of the secret to attach tags to. (shared/personal)",
|
type: "The type of the secret to attach tags to. (shared/personal)",
|
||||||
environment: "The slug of the environment where the secret is located",
|
environment: "The slug of the environment where the secret is located",
|
||||||
projectSlug: "The slug of the project where the secret is located",
|
projectSlug: "The slug of the project where the secret is located",
|
||||||
tagSlugs: "An array of tag slugs to detach from the secret."
|
tagSlugs: "An array of existing tag slugs to detach from the secret."
|
||||||
}
|
}
|
||||||
} as const;
|
} as const;
|
||||||
|
|
||||||
|
|||||||
@@ -1058,13 +1058,13 @@ export const secretServiceFactory = ({
|
|||||||
throw new BadRequestError({ message: "One or more tags not found." });
|
throw new BadRequestError({ message: "One or more tags not found." });
|
||||||
}
|
}
|
||||||
|
|
||||||
const secretTags = await secretDAL.getSecretTags(secret.id);
|
const existingSecretTags = await secretDAL.getSecretTags(secret.id);
|
||||||
|
|
||||||
if (secretTags.some((tag) => tagSlugs.includes(tag.slug))) {
|
if (existingSecretTags.some((tag) => tagSlugs.includes(tag.slug))) {
|
||||||
throw new BadRequestError({ message: "One or more tags already exist on the secret" });
|
throw new BadRequestError({ message: "One or more tags already exist on the secret" });
|
||||||
}
|
}
|
||||||
|
|
||||||
const combinedTags = new Set([...secretTags.map((tag) => tag.id), ...tags.map((el) => el.id)]);
|
const combinedTags = new Set([...existingSecretTags.map((tag) => tag.id), ...tags.map((el) => el.id)]);
|
||||||
|
|
||||||
const updatedSecret = await secretDAL.transaction(async (tx) =>
|
const updatedSecret = await secretDAL.transaction(async (tx) =>
|
||||||
fnSecretBulkUpdate({
|
fnSecretBulkUpdate({
|
||||||
@@ -1091,7 +1091,7 @@ export const secretServiceFactory = ({
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
...updatedSecret[0],
|
...updatedSecret[0],
|
||||||
tags: [...secretTags, ...tags].map((t) => ({ id: t.id, slug: t.slug, name: t.name, color: t.color }))
|
tags: [...existingSecretTags, ...tags].map((t) => ({ id: t.id, slug: t.slug, name: t.name, color: t.color }))
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -1156,17 +1156,17 @@ export const secretServiceFactory = ({
|
|||||||
throw new BadRequestError({ message: "One or more tags not found." });
|
throw new BadRequestError({ message: "One or more tags not found." });
|
||||||
}
|
}
|
||||||
|
|
||||||
const secretTags = await secretDAL.getSecretTags(secret.id);
|
const existingSecretTags = await secretDAL.getSecretTags(secret.id);
|
||||||
|
|
||||||
// Make sure all the tags exist on the secret
|
// Make sure all the tags exist on the secret
|
||||||
const tagIdsToRemove = tags.map((tag) => tag.id);
|
const tagIdsToRemove = tags.map((tag) => tag.id);
|
||||||
const secretTagIds = secretTags.map((tag) => tag.id);
|
const secretTagIds = existingSecretTags.map((tag) => tag.id);
|
||||||
|
|
||||||
if (!tagIdsToRemove.every((el) => secretTagIds.includes(el))) {
|
if (!tagIdsToRemove.every((el) => secretTagIds.includes(el))) {
|
||||||
throw new BadRequestError({ message: "One or more tags not found on the secret" });
|
throw new BadRequestError({ message: "One or more tags not found on the secret" });
|
||||||
}
|
}
|
||||||
|
|
||||||
const newTags = secretTags.filter((tag) => !tagIdsToRemove.includes(tag.id));
|
const newTags = existingSecretTags.filter((tag) => !tagIdsToRemove.includes(tag.id));
|
||||||
|
|
||||||
const updatedSecret = await secretDAL.transaction(async (tx) =>
|
const updatedSecret = await secretDAL.transaction(async (tx) =>
|
||||||
fnSecretBulkUpdate({
|
fnSecretBulkUpdate({
|
||||||
|
|||||||
Reference in New Issue
Block a user