feat(infisical-pg): resolved import secret breaking cli backward compatiability

This commit is contained in:
Akhil Mohan
2024-01-27 12:38:23 +05:30
parent e46e87d758
commit 8ab89bc420
7 changed files with 24 additions and 39 deletions
@@ -250,7 +250,8 @@ export const registerSecretImportRouter = async (server: FastifyZodProvider) =>
secrets: z
.object({
secretPath: z.string(),
environment: z.object({
environment: z.string(),
environmentInfo: z.object({
id: z.string(),
name: z.string(),
slug: z.string()
@@ -6,7 +6,7 @@ import {
SecretsSchema,
SecretTagsSchema,
SecretType,
ServiceTokenScopes,
ServiceTokenScopes
} from "@app/db/schemas";
import { EventType } from "@app/ee/services/audit-log/audit-log-types";
import { CommitType } from "@app/ee/services/secret-approval-request/secret-approval-request-types";
@@ -36,11 +36,7 @@ export const registerSecretRouter = async (server: FastifyZodProvider) => {
imports: z
.object({
secretPath: z.string(),
environment: z.object({
id: z.string(),
name: z.string(),
slug: z.string()
}),
environment: z.string(),
folderId: z.string().optional(),
secrets: secretRawSchema.array()
})
@@ -57,23 +53,24 @@ export const registerSecretRouter = async (server: FastifyZodProvider) => {
]),
handler: async (req) => {
// just for delivery hero usecase
let {secretPath,environment,workspaceId} = req.query;
if(req.auth.actor === ActorType.SERVICE){
let { secretPath, environment, workspaceId } = req.query;
if (req.auth.actor === ActorType.SERVICE) {
const scope = ServiceTokenScopes.parse(req.auth.serviceToken.scopes);
const isSingleScope = scope.length === 1;
if(isSingleScope && !picomatch.scan(scope[0].secretPath).isGlob){
if (isSingleScope && !picomatch.scan(scope[0].secretPath).isGlob) {
secretPath = scope[0].secretPath;
environment = scope[0].environment;
workspaceId = req.auth.serviceToken.projectId;
}
}
if(!workspaceId || !environment) throw new BadRequestError({message:"Missing workspace id or environment"})
if (!workspaceId || !environment)
throw new BadRequestError({ message: "Missing workspace id or environment" });
const { secrets, imports } = await server.services.secret.getSecretsRaw({
actorId: req.permission.id,
actor: req.permission.type,
environment,
environment,
projectId: workspaceId as string,
path: secretPath,
includeImports: req.query.include_imports
@@ -360,11 +357,7 @@ export const registerSecretRouter = async (server: FastifyZodProvider) => {
imports: z
.object({
secretPath: z.string(),
environment: z.object({
id: z.string(),
name: z.string(),
slug: z.string()
}),
environment: z.string(),
folderId: z.string().optional(),
secrets: SecretsSchema.omit({ secretBlindIndex: true }).array()
})
@@ -33,7 +33,8 @@ export const fnSecretsFromImports = async ({
const importedSecsGroupByFolderId = groupBy(importedSecrets, (i) => i.folderId);
return allowedImports.map(({ importPath, importEnv }, i) => ({
secretPath: importPath,
environment: importEnv,
environment: importEnv.slug,
environmentInfo: importEnv,
folderId: importedFolders?.[i]?.id,
secrets: importedFolders?.[i]?.id
? importedSecsGroupByFolderId[importedFolders?.[i]?.id as string]
@@ -585,7 +585,7 @@ export const secretServiceFactory = ({
return {
...importedSecrets[i].secrets[j],
workspace: projectId,
environment: importedSecrets[i].environment.slug
environment: importedSecrets[i].environment
};
}
}
@@ -825,10 +825,7 @@ export const secretServiceFactory = ({
imports: (imports || [])?.map(({ secrets: importedSecrets, ...el }) => ({
...el,
secrets: importedSecrets.map((sec) =>
decryptSecretRaw(
{ ...sec, environment: el.environment.slug, workspace: projectId },
botKey
)
decryptSecretRaw({ ...sec, environment: el.environment, workspace: projectId }, botKey)
)
}))
};