mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-04 14:26:25 +00:00
@@ -181,81 +181,68 @@ export const registerSecretRouter = async (server: FastifyZodProvider) => {
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
querystring: z.object({
|
querystring: z.object({
|
||||||
filters: z
|
secretMetadata: z
|
||||||
.string()
|
.string()
|
||||||
.optional()
|
.optional()
|
||||||
.transform((val) => {
|
.transform((val) => {
|
||||||
// TODO: Add support for more filtering fields & operators.
|
|
||||||
// Currently only supports secretMetadata filtering in a specific format to allow for further expansion of filtering in the future.
|
|
||||||
|
|
||||||
if (!val) return undefined;
|
if (!val) return undefined;
|
||||||
const secretMetadataSection = [val].find((section) => section.startsWith("secretMetadata="));
|
|
||||||
|
|
||||||
if (!secretMetadataSection) return undefined;
|
const result: { key?: string; value?: string }[] = [];
|
||||||
|
const pairs = val.split(",");
|
||||||
|
|
||||||
const metadataContent = secretMetadataSection.replace("secretMetadata=", "");
|
for (const pair of pairs) {
|
||||||
|
const pairResult: { key?: string; value?: string } = {};
|
||||||
|
const parts = pair.split(/[:=]/).map((part) => part.trim());
|
||||||
|
|
||||||
const secretMetadataResult: { key?: string; value?: string }[] = [];
|
for (let i = 0; i < parts.length - 1; i += 1) {
|
||||||
let currentPair: { key?: string; value?: string } = {};
|
const current = parts[i].toLowerCase();
|
||||||
|
const next = parts[i + 1];
|
||||||
|
|
||||||
const parts = metadataContent.split(/(?<!=),(?!=)/);
|
if (current === "key" && next) {
|
||||||
|
pairResult.key = next;
|
||||||
for (const part of parts) {
|
} else if (current === "value" && next) {
|
||||||
const [type, value] = part.split("=");
|
pairResult.value = next;
|
||||||
|
|
||||||
if (type === "key") {
|
|
||||||
if (currentPair.key || currentPair.value) {
|
|
||||||
secretMetadataResult.push(currentPair);
|
|
||||||
currentPair = {};
|
|
||||||
}
|
}
|
||||||
currentPair.key = value;
|
}
|
||||||
} else if (type === "value") {
|
|
||||||
currentPair.value = value;
|
// Only add pair if at least one of key or value is present
|
||||||
secretMetadataResult.push(currentPair);
|
if (pairResult.key || pairResult.value) {
|
||||||
currentPair = {};
|
result.push(pairResult);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (currentPair.key || currentPair.value) {
|
if (!result.length) return undefined;
|
||||||
secretMetadataResult.push(currentPair);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!secretMetadataResult.length) return undefined;
|
return result;
|
||||||
|
|
||||||
return {
|
|
||||||
secretMetadata: secretMetadataResult
|
|
||||||
};
|
|
||||||
})
|
})
|
||||||
.superRefine((filters, ctx) => {
|
.superRefine((metadata, ctx) => {
|
||||||
if (filters?.secretMetadata) {
|
if (metadata && !Array.isArray(metadata)) {
|
||||||
if (!Array.isArray(filters.secretMetadata)) {
|
ctx.addIssue({
|
||||||
ctx.addIssue({
|
code: z.ZodIssueCode.custom,
|
||||||
code: z.ZodIssueCode.custom,
|
message: "Invalid secretMetadata format. Correct format is key1:value1,key2:value2"
|
||||||
message:
|
});
|
||||||
"Invalid secretMetadata format in filters. Correct format is filters=secretMetadata=key=key1,value=val1"
|
}
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
if (filters.secretMetadata.length > 10) {
|
if (metadata) {
|
||||||
|
if (metadata.length > 10) {
|
||||||
ctx.addIssue({
|
ctx.addIssue({
|
||||||
code: z.ZodIssueCode.custom,
|
code: z.ZodIssueCode.custom,
|
||||||
message: "You can only filter by up to 10 metadata fields"
|
message: "You can only filter by up to 10 metadata fields"
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const item of filters.secretMetadata) {
|
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 in filters, key or value must be provided. Correct format is filters=secretMetadata=key=key1,value=val1"
|
"Invalid secretMetadata format, key or value must be provided. Correct format is key1:value1,key2:value2"
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.describe(RAW_SECRETS.LIST.secretMetadata),
|
.describe(RAW_SECRETS.LIST.secretMetadata),
|
||||||
|
|
||||||
workspaceId: z.string().trim().optional().describe(RAW_SECRETS.LIST.workspaceId),
|
workspaceId: z.string().trim().optional().describe(RAW_SECRETS.LIST.workspaceId),
|
||||||
workspaceSlug: z.string().trim().optional().describe(RAW_SECRETS.LIST.workspaceSlug),
|
workspaceSlug: z.string().trim().optional().describe(RAW_SECRETS.LIST.workspaceSlug),
|
||||||
environment: z.string().trim().optional().describe(RAW_SECRETS.LIST.environment),
|
environment: z.string().trim().optional().describe(RAW_SECRETS.LIST.environment),
|
||||||
@@ -356,7 +343,7 @@ export const registerSecretRouter = async (server: FastifyZodProvider) => {
|
|||||||
actorAuthMethod: req.permission.authMethod,
|
actorAuthMethod: req.permission.authMethod,
|
||||||
projectId: workspaceId,
|
projectId: workspaceId,
|
||||||
path: secretPath,
|
path: secretPath,
|
||||||
secretMetadata: req.query.filters?.secretMetadata,
|
secretMetadata: req.query.secretMetadata,
|
||||||
includeImports: req.query.include_imports,
|
includeImports: req.query.include_imports,
|
||||||
recursive: req.query.recursive,
|
recursive: req.query.recursive,
|
||||||
tagSlugs: req.query.tagSlugs
|
tagSlugs: req.query.tagSlugs
|
||||||
|
|||||||
Reference in New Issue
Block a user