mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-06 14:27:59 +00:00
improved filtering format
This commit is contained in:
@@ -184,15 +184,36 @@ export const registerSecretRouter = async (server: FastifyZodProvider) => {
|
|||||||
secretMetadata: z
|
secretMetadata: z
|
||||||
.string()
|
.string()
|
||||||
.optional()
|
.optional()
|
||||||
.transform((value) => {
|
.transform((val) => {
|
||||||
if (!value) return undefined;
|
if (!val) return undefined;
|
||||||
|
|
||||||
const metadata = value.split(",").map((el) => {
|
const result: { key?: string; value?: string }[] = [];
|
||||||
const [key, val] = el.split(":");
|
const pairs = val.split(",");
|
||||||
return { key, value: val };
|
|
||||||
});
|
|
||||||
|
|
||||||
return metadata;
|
for (const pair of pairs) {
|
||||||
|
const pairResult: { key?: string; value?: string } = {};
|
||||||
|
const parts = pair.split(/[:=]/).map((part) => part.trim());
|
||||||
|
|
||||||
|
for (let i = 0; i < parts.length - 1; i += 1) {
|
||||||
|
const current = parts[i].toLowerCase();
|
||||||
|
const next = parts[i + 1];
|
||||||
|
|
||||||
|
if (current === "key" && next) {
|
||||||
|
pairResult.key = next;
|
||||||
|
} else if (current === "value" && next) {
|
||||||
|
pairResult.value = next;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Only add pair if at least one of key or value is present
|
||||||
|
if (pairResult.key || pairResult.value) {
|
||||||
|
result.push(pairResult);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!result.length) return undefined;
|
||||||
|
|
||||||
|
return result;
|
||||||
})
|
})
|
||||||
.superRefine((metadata, ctx) => {
|
.superRefine((metadata, ctx) => {
|
||||||
if (metadata && !Array.isArray(metadata)) {
|
if (metadata && !Array.isArray(metadata)) {
|
||||||
@@ -211,11 +232,11 @@ export const registerSecretRouter = async (server: FastifyZodProvider) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (const item of metadata) {
|
for (const item of metadata) {
|
||||||
if (!item.key || !item.value) {
|
if (!item.key && !item.value) {
|
||||||
ctx.addIssue({
|
ctx.addIssue({
|
||||||
code: z.ZodIssueCode.custom,
|
code: z.ZodIssueCode.custom,
|
||||||
message:
|
message:
|
||||||
"Invalid secretMetadata format, key or value is missing. Correct format is key1:value1,key2:value2"
|
"Invalid secretMetadata format, key or value must be provided. Correct format is key1:value1,key2:value2"
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -418,8 +418,8 @@ export const secretV2BridgeDALFactory = (db: TDbClient) => {
|
|||||||
if (filters?.secretMetadata && filters.secretMetadata.length > 0) {
|
if (filters?.secretMetadata && filters.secretMetadata.length > 0) {
|
||||||
filters.secretMetadata.forEach((meta) => {
|
filters.secretMetadata.forEach((meta) => {
|
||||||
void qb.where({
|
void qb.where({
|
||||||
[`${TableName.ResourceMetadata}.key` as string]: meta.key,
|
...(meta.key ? { [`${TableName.ResourceMetadata}.key` as string]: meta.key } : {}),
|
||||||
[`${TableName.ResourceMetadata}.value` as string]: meta.value
|
...(meta.value ? { [`${TableName.ResourceMetadata}.value` as string]: meta.value } : {})
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,8 +31,8 @@ export type TGetSecretsDTO = {
|
|||||||
recursive?: boolean;
|
recursive?: boolean;
|
||||||
tagSlugs?: string[];
|
tagSlugs?: string[];
|
||||||
secretMetadata?: {
|
secretMetadata?: {
|
||||||
key: string;
|
key?: string;
|
||||||
value: string;
|
value?: string;
|
||||||
}[];
|
}[];
|
||||||
orderBy?: SecretsOrderBy;
|
orderBy?: SecretsOrderBy;
|
||||||
orderDirection?: OrderByDirection;
|
orderDirection?: OrderByDirection;
|
||||||
@@ -314,7 +314,7 @@ export type TFindSecretsByFolderIdsFilter = {
|
|||||||
orderDirection?: OrderByDirection;
|
orderDirection?: OrderByDirection;
|
||||||
search?: string;
|
search?: string;
|
||||||
tagSlugs?: string[];
|
tagSlugs?: string[];
|
||||||
secretMetadata?: { key: string; value: string }[];
|
secretMetadata?: { key?: string; value?: string }[];
|
||||||
includeTagsInSearch?: boolean;
|
includeTagsInSearch?: boolean;
|
||||||
keys?: string[];
|
keys?: string[];
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -183,8 +183,8 @@ export type TGetSecretsRawDTO = {
|
|||||||
recursive?: boolean;
|
recursive?: boolean;
|
||||||
tagSlugs?: string[];
|
tagSlugs?: string[];
|
||||||
secretMetadata?: {
|
secretMetadata?: {
|
||||||
key: string;
|
key?: string;
|
||||||
value: string;
|
value?: string;
|
||||||
}[];
|
}[];
|
||||||
orderBy?: SecretsOrderBy;
|
orderBy?: SecretsOrderBy;
|
||||||
orderDirection?: OrderByDirection;
|
orderDirection?: OrderByDirection;
|
||||||
|
|||||||
Reference in New Issue
Block a user