mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-07 16:27:40 +00:00
misc: displayed project name in slack webhook
This commit is contained in:
@@ -645,7 +645,8 @@ export const registerRoutes = async (
|
|||||||
const webhookService = webhookServiceFactory({
|
const webhookService = webhookServiceFactory({
|
||||||
permissionService,
|
permissionService,
|
||||||
webhookDAL,
|
webhookDAL,
|
||||||
projectEnvDAL
|
projectEnvDAL,
|
||||||
|
projectDAL
|
||||||
});
|
});
|
||||||
|
|
||||||
const secretTagService = secretTagServiceFactory({ secretTagDAL, permissionService });
|
const secretTagService = secretTagServiceFactory({ secretTagDAL, permissionService });
|
||||||
|
|||||||
@@ -642,7 +642,7 @@ export const secretQueueFactory = ({
|
|||||||
});
|
});
|
||||||
|
|
||||||
queueService.start(QueueName.SecretWebhook, async (job) => {
|
queueService.start(QueueName.SecretWebhook, async (job) => {
|
||||||
await fnTriggerWebhook({ ...job.data, projectEnvDAL, webhookDAL });
|
await fnTriggerWebhook({ ...job.data, projectEnvDAL, webhookDAL, projectDAL });
|
||||||
});
|
});
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import { infisicalSymmetricDecrypt } from "@app/lib/crypto/encryption";
|
|||||||
import { BadRequestError } from "@app/lib/errors";
|
import { BadRequestError } from "@app/lib/errors";
|
||||||
import { logger } from "@app/lib/logger";
|
import { logger } from "@app/lib/logger";
|
||||||
|
|
||||||
|
import { TProjectDALFactory } from "../project/project-dal";
|
||||||
import { TProjectEnvDALFactory } from "../project-env/project-env-dal";
|
import { TProjectEnvDALFactory } from "../project-env/project-env-dal";
|
||||||
import { TWebhookDALFactory } from "./webhook-dal";
|
import { TWebhookDALFactory } from "./webhook-dal";
|
||||||
import { WebhookType } from "./webhook-types";
|
import { WebhookType } from "./webhook-types";
|
||||||
@@ -66,11 +67,16 @@ export const triggerWebhookRequest = async (webhook: TWebhooks, data: Record<str
|
|||||||
|
|
||||||
export const getWebhookPayload = (
|
export const getWebhookPayload = (
|
||||||
eventName: string,
|
eventName: string,
|
||||||
workspaceId: string,
|
details: {
|
||||||
environment: string,
|
workspaceName: string;
|
||||||
secretPath?: string,
|
workspaceId: string;
|
||||||
type?: string | null
|
environment: string;
|
||||||
|
secretPath?: string;
|
||||||
|
type?: string | null;
|
||||||
|
}
|
||||||
) => {
|
) => {
|
||||||
|
const { workspaceName, workspaceId, environment, secretPath, type } = details;
|
||||||
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case WebhookType.SLACK:
|
case WebhookType.SLACK:
|
||||||
return {
|
return {
|
||||||
@@ -80,8 +86,8 @@ export const getWebhookPayload = (
|
|||||||
color: "#E7F256",
|
color: "#E7F256",
|
||||||
fields: [
|
fields: [
|
||||||
{
|
{
|
||||||
title: "Workspace ID",
|
title: "Project",
|
||||||
value: workspaceId,
|
value: workspaceName,
|
||||||
short: false
|
short: false
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -117,7 +123,9 @@ export type TFnTriggerWebhookDTO = {
|
|||||||
environment: string;
|
environment: string;
|
||||||
webhookDAL: Pick<TWebhookDALFactory, "findAllWebhooks" | "transaction" | "update" | "bulkUpdate">;
|
webhookDAL: Pick<TWebhookDALFactory, "findAllWebhooks" | "transaction" | "update" | "bulkUpdate">;
|
||||||
projectEnvDAL: Pick<TProjectEnvDALFactory, "findOne">;
|
projectEnvDAL: Pick<TProjectEnvDALFactory, "findOne">;
|
||||||
|
projectDAL: Pick<TProjectDALFactory, "findById">;
|
||||||
};
|
};
|
||||||
|
|
||||||
// this is reusable function
|
// this is reusable function
|
||||||
// used in secret queue to trigger webhook and update status when secrets changes
|
// used in secret queue to trigger webhook and update status when secrets changes
|
||||||
export const fnTriggerWebhook = async ({
|
export const fnTriggerWebhook = async ({
|
||||||
@@ -125,7 +133,8 @@ export const fnTriggerWebhook = async ({
|
|||||||
secretPath,
|
secretPath,
|
||||||
projectId,
|
projectId,
|
||||||
webhookDAL,
|
webhookDAL,
|
||||||
projectEnvDAL
|
projectEnvDAL,
|
||||||
|
projectDAL
|
||||||
}: TFnTriggerWebhookDTO) => {
|
}: TFnTriggerWebhookDTO) => {
|
||||||
const webhooks = await webhookDAL.findAllWebhooks(projectId, environment);
|
const webhooks = await webhookDAL.findAllWebhooks(projectId, environment);
|
||||||
const toBeTriggeredHooks = webhooks.filter(
|
const toBeTriggeredHooks = webhooks.filter(
|
||||||
@@ -134,9 +143,19 @@ export const fnTriggerWebhook = async ({
|
|||||||
);
|
);
|
||||||
if (!toBeTriggeredHooks.length) return;
|
if (!toBeTriggeredHooks.length) return;
|
||||||
logger.info("Secret webhook job started", { environment, secretPath, projectId });
|
logger.info("Secret webhook job started", { environment, secretPath, projectId });
|
||||||
|
const project = await projectDAL.findById(projectId);
|
||||||
const webhooksTriggered = await Promise.allSettled(
|
const webhooksTriggered = await Promise.allSettled(
|
||||||
toBeTriggeredHooks.map((hook) =>
|
toBeTriggeredHooks.map((hook) =>
|
||||||
triggerWebhookRequest(hook, getWebhookPayload("secrets.modified", projectId, environment, secretPath, hook.type))
|
triggerWebhookRequest(
|
||||||
|
hook,
|
||||||
|
getWebhookPayload("secrets.modified", {
|
||||||
|
workspaceName: project.name,
|
||||||
|
workspaceId: projectId,
|
||||||
|
environment,
|
||||||
|
secretPath,
|
||||||
|
type: hook.type
|
||||||
|
})
|
||||||
|
)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import { ProjectPermissionActions, ProjectPermissionSub } from "@app/ee/services
|
|||||||
import { infisicalSymmetricEncypt } from "@app/lib/crypto/encryption";
|
import { infisicalSymmetricEncypt } from "@app/lib/crypto/encryption";
|
||||||
import { BadRequestError } from "@app/lib/errors";
|
import { BadRequestError } from "@app/lib/errors";
|
||||||
|
|
||||||
|
import { TProjectDALFactory } from "../project/project-dal";
|
||||||
import { TProjectEnvDALFactory } from "../project-env/project-env-dal";
|
import { TProjectEnvDALFactory } from "../project-env/project-env-dal";
|
||||||
import { TWebhookDALFactory } from "./webhook-dal";
|
import { TWebhookDALFactory } from "./webhook-dal";
|
||||||
import { decryptWebhookDetails, getWebhookPayload, triggerWebhookRequest } from "./webhook-fns";
|
import { decryptWebhookDetails, getWebhookPayload, triggerWebhookRequest } from "./webhook-fns";
|
||||||
@@ -20,12 +21,18 @@ import {
|
|||||||
type TWebhookServiceFactoryDep = {
|
type TWebhookServiceFactoryDep = {
|
||||||
webhookDAL: TWebhookDALFactory;
|
webhookDAL: TWebhookDALFactory;
|
||||||
projectEnvDAL: TProjectEnvDALFactory;
|
projectEnvDAL: TProjectEnvDALFactory;
|
||||||
|
projectDAL: Pick<TProjectDALFactory, "findById">;
|
||||||
permissionService: Pick<TPermissionServiceFactory, "getProjectPermission">;
|
permissionService: Pick<TPermissionServiceFactory, "getProjectPermission">;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type TWebhookServiceFactory = ReturnType<typeof webhookServiceFactory>;
|
export type TWebhookServiceFactory = ReturnType<typeof webhookServiceFactory>;
|
||||||
|
|
||||||
export const webhookServiceFactory = ({ webhookDAL, projectEnvDAL, permissionService }: TWebhookServiceFactoryDep) => {
|
export const webhookServiceFactory = ({
|
||||||
|
webhookDAL,
|
||||||
|
projectEnvDAL,
|
||||||
|
permissionService,
|
||||||
|
projectDAL
|
||||||
|
}: TWebhookServiceFactoryDep) => {
|
||||||
const createWebhook = async ({
|
const createWebhook = async ({
|
||||||
actor,
|
actor,
|
||||||
actorId,
|
actorId,
|
||||||
@@ -124,13 +131,21 @@ export const webhookServiceFactory = ({ webhookDAL, projectEnvDAL, permissionSer
|
|||||||
actorAuthMethod,
|
actorAuthMethod,
|
||||||
actorOrgId
|
actorOrgId
|
||||||
);
|
);
|
||||||
ForbiddenError.from(permission).throwUnlessCan(ProjectPermissionActions.Read, ProjectPermissionSub.Webhooks);
|
|
||||||
|
|
||||||
|
const project = await projectDAL.findById(webhook.projectId);
|
||||||
|
|
||||||
|
ForbiddenError.from(permission).throwUnlessCan(ProjectPermissionActions.Read, ProjectPermissionSub.Webhooks);
|
||||||
let webhookError: string | undefined;
|
let webhookError: string | undefined;
|
||||||
try {
|
try {
|
||||||
await triggerWebhookRequest(
|
await triggerWebhookRequest(
|
||||||
webhook,
|
webhook,
|
||||||
getWebhookPayload("test", webhook.projectId, webhook.environment.slug, webhook.secretPath, webhook.type)
|
getWebhookPayload("test", {
|
||||||
|
workspaceName: project.name,
|
||||||
|
workspaceId: webhook.projectId,
|
||||||
|
environment: webhook.environment.slug,
|
||||||
|
secretPath: webhook.secretPath,
|
||||||
|
type: webhook.type
|
||||||
|
})
|
||||||
);
|
);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
webhookError = (err as Error).message;
|
webhookError = (err as Error).message;
|
||||||
|
|||||||
Reference in New Issue
Block a user