Skip to content

Commit

Permalink
Merge pull request #2522 from Infisical/daniel/integration-router-fixes
Browse files Browse the repository at this point in the history
fix: made all update fields optional
  • Loading branch information
DanielHougaard authored Oct 2, 2024
2 parents 342e9f9 + 8ed04d0 commit a3cad03
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 13 deletions.
6 changes: 3 additions & 3 deletions backend/src/server/routes/v1/integration-router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,9 @@ export const registerIntegrationRouter = async (server: FastifyZodProvider) => {
.default("/")
.transform(removeTrailingSlash)
.describe(INTEGRATION.UPDATE.secretPath),
targetEnvironment: z.string().trim().describe(INTEGRATION.UPDATE.targetEnvironment),
owner: z.string().trim().describe(INTEGRATION.UPDATE.owner),
environment: z.string().trim().describe(INTEGRATION.UPDATE.environment),
targetEnvironment: z.string().trim().optional().describe(INTEGRATION.UPDATE.targetEnvironment),
owner: z.string().trim().optional().describe(INTEGRATION.UPDATE.owner),
environment: z.string().trim().optional().describe(INTEGRATION.UPDATE.environment),
metadata: IntegrationMetadataSchema.optional()
}),
response: {
Expand Down
17 changes: 11 additions & 6 deletions backend/src/services/integration/integration-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,12 +150,17 @@ export const integrationServiceFactory = ({
);
ForbiddenError.from(permission).throwUnlessCan(ProjectPermissionActions.Edit, ProjectPermissionSub.Integrations);

ForbiddenError.from(permission).throwUnlessCan(
ProjectPermissionActions.Read,
subject(ProjectPermissionSub.Secrets, { environment, secretPath })
);
const newEnvironment = environment || integration.environment.slug;
const newSecretPath = secretPath || integration.secretPath;

const folder = await folderDAL.findBySecretPath(integration.projectId, environment, secretPath);
if (environment || secretPath) {
ForbiddenError.from(permission).throwUnlessCan(
ProjectPermissionActions.Read,
subject(ProjectPermissionSub.Secrets, { environment: newEnvironment, secretPath: newSecretPath })
);
}

const folder = await folderDAL.findBySecretPath(integration.projectId, newEnvironment, newSecretPath);
if (!folder) throw new NotFoundError({ message: "Folder path not found" });

const updatedIntegration = await integrationDAL.updateById(id, {
Expand All @@ -174,7 +179,7 @@ export const integrationServiceFactory = ({

await secretQueueService.syncIntegrations({
environment: folder.environment.slug,
secretPath,
secretPath: newSecretPath,
projectId: folder.projectId
});

Expand Down
8 changes: 4 additions & 4 deletions backend/src/services/integration/integration-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ export type TUpdateIntegrationDTO = {
app?: string;
appId?: string;
isActive?: boolean;
secretPath: string;
targetEnvironment: string;
owner: string;
environment: string;
secretPath?: string;
targetEnvironment?: string;
owner?: string;
environment?: string;
metadata?: {
secretPrefix?: string;
secretSuffix?: string;
Expand Down

0 comments on commit a3cad03

Please sign in to comment.