mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-14 14:34:09 +00:00
Merge pull request #1970 from akhilmhdh/feat/ui-permission-check-broken
Allow secret tag api for machine identity and raw secret endpoint tag support
This commit is contained in:
@@ -42,7 +42,8 @@ export const secretTagServiceFactory = ({ secretTagDAL, permissionService }: TSe
|
||||
name,
|
||||
slug,
|
||||
color,
|
||||
createdBy: actorId
|
||||
createdBy: actorId,
|
||||
createdByActorType: actor
|
||||
});
|
||||
return newTag;
|
||||
};
|
||||
|
||||
@@ -311,6 +311,40 @@ export const secretDALFactory = (db: TDbClient) => {
|
||||
}
|
||||
};
|
||||
|
||||
const findOneWithTags = async (filter: Partial<TSecrets>, tx?: Knex) => {
|
||||
try {
|
||||
const rawDocs = await (tx || db)(TableName.Secret)
|
||||
.where(filter)
|
||||
.leftJoin(TableName.JnSecretTag, `${TableName.Secret}.id`, `${TableName.JnSecretTag}.${TableName.Secret}Id`)
|
||||
.leftJoin(TableName.SecretTag, `${TableName.JnSecretTag}.${TableName.SecretTag}Id`, `${TableName.SecretTag}.id`)
|
||||
.select(selectAllTableCols(TableName.Secret))
|
||||
.select(db.ref("id").withSchema(TableName.SecretTag).as("tagId"))
|
||||
.select(db.ref("color").withSchema(TableName.SecretTag).as("tagColor"))
|
||||
.select(db.ref("slug").withSchema(TableName.SecretTag).as("tagSlug"))
|
||||
.select(db.ref("name").withSchema(TableName.SecretTag).as("tagName"));
|
||||
const docs = sqlNestRelationships({
|
||||
data: rawDocs,
|
||||
key: "id",
|
||||
parentMapper: (el) => ({ _id: el.id, ...SecretsSchema.parse(el) }),
|
||||
childrenMapper: [
|
||||
{
|
||||
key: "tagId",
|
||||
label: "tags" as const,
|
||||
mapper: ({ tagId: id, tagColor: color, tagSlug: slug, tagName: name }) => ({
|
||||
id,
|
||||
color,
|
||||
slug,
|
||||
name
|
||||
})
|
||||
}
|
||||
]
|
||||
});
|
||||
return docs?.[0];
|
||||
} catch (error) {
|
||||
throw new DatabaseError({ error, name: "FindOneWIthTags" });
|
||||
}
|
||||
};
|
||||
|
||||
return {
|
||||
...secretOrm,
|
||||
update,
|
||||
@@ -318,6 +352,7 @@ export const secretDALFactory = (db: TDbClient) => {
|
||||
deleteMany,
|
||||
bulkUpdateNoVersionIncrement,
|
||||
getSecretTags,
|
||||
findOneWithTags,
|
||||
findByFolderId,
|
||||
findByFolderIds,
|
||||
findByBlindIndexes,
|
||||
|
||||
@@ -356,7 +356,17 @@ export const interpolateSecrets = ({ projectId, secretEncKey, secretDAL, folderD
|
||||
};
|
||||
|
||||
export const decryptSecretRaw = (
|
||||
secret: TSecrets & { workspace: string; environment: string; secretPath: string },
|
||||
secret: TSecrets & {
|
||||
workspace: string;
|
||||
environment: string;
|
||||
secretPath: string;
|
||||
tags?: {
|
||||
id: string;
|
||||
slug: string;
|
||||
color?: string | null;
|
||||
name: string;
|
||||
}[];
|
||||
},
|
||||
key: string
|
||||
) => {
|
||||
const secretKey = decryptSymmetric128BitHexKeyUTF8({
|
||||
@@ -396,6 +406,7 @@ export const decryptSecretRaw = (
|
||||
_id: secret.id,
|
||||
id: secret.id,
|
||||
user: secret.userId,
|
||||
tags: secret.tags,
|
||||
skipMultilineEncoding: secret.skipMultilineEncoding
|
||||
};
|
||||
};
|
||||
|
||||
@@ -608,7 +608,7 @@ export const secretServiceFactory = ({
|
||||
}
|
||||
|
||||
const secret = await (version === undefined
|
||||
? secretDAL.findOne({
|
||||
? secretDAL.findOneWithTags({
|
||||
folderId,
|
||||
type: secretType,
|
||||
userId: secretType === SecretType.Personal ? actorId : null,
|
||||
@@ -1120,7 +1120,8 @@ export const secretServiceFactory = ({
|
||||
secretPath,
|
||||
secretValue,
|
||||
secretComment,
|
||||
skipMultilineEncoding
|
||||
skipMultilineEncoding,
|
||||
tagIds
|
||||
}: TCreateSecretRawDTO) => {
|
||||
const botKey = await projectBotService.getBotKey(projectId);
|
||||
if (!botKey) throw new BadRequestError({ message: "Project bot not found", name: "bot_not_found_error" });
|
||||
@@ -1148,7 +1149,8 @@ export const secretServiceFactory = ({
|
||||
secretCommentCiphertext: secretCommentEncrypted.ciphertext,
|
||||
secretCommentIV: secretCommentEncrypted.iv,
|
||||
secretCommentTag: secretCommentEncrypted.tag,
|
||||
skipMultilineEncoding
|
||||
skipMultilineEncoding,
|
||||
tags: tagIds
|
||||
});
|
||||
|
||||
return decryptSecretRaw(secret, botKey);
|
||||
@@ -1165,7 +1167,8 @@ export const secretServiceFactory = ({
|
||||
type,
|
||||
secretPath,
|
||||
secretValue,
|
||||
skipMultilineEncoding
|
||||
skipMultilineEncoding,
|
||||
tagIds
|
||||
}: TUpdateSecretRawDTO) => {
|
||||
const botKey = await projectBotService.getBotKey(projectId);
|
||||
if (!botKey) throw new BadRequestError({ message: "Project bot not found", name: "bot_not_found_error" });
|
||||
@@ -1185,7 +1188,8 @@ export const secretServiceFactory = ({
|
||||
secretValueCiphertext: secretValueEncrypted.ciphertext,
|
||||
secretValueIV: secretValueEncrypted.iv,
|
||||
secretValueTag: secretValueEncrypted.tag,
|
||||
skipMultilineEncoding
|
||||
skipMultilineEncoding,
|
||||
tags: tagIds
|
||||
});
|
||||
|
||||
await snapshotService.performSnapshot(secret.folderId);
|
||||
|
||||
@@ -164,6 +164,7 @@ export type TCreateSecretRawDTO = TProjectPermission & {
|
||||
secretName: string;
|
||||
secretValue: string;
|
||||
type: SecretType;
|
||||
tagIds?: string[];
|
||||
secretComment?: string;
|
||||
skipMultilineEncoding?: boolean;
|
||||
};
|
||||
@@ -174,6 +175,7 @@ export type TUpdateSecretRawDTO = TProjectPermission & {
|
||||
secretName: string;
|
||||
secretValue?: string;
|
||||
type: SecretType;
|
||||
tagIds?: string[];
|
||||
skipMultilineEncoding?: boolean;
|
||||
secretReminderRepeatDays?: number | null;
|
||||
secretReminderNote?: string | null;
|
||||
|
||||
Reference in New Issue
Block a user