mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-07 22:27:48 +00:00
improve audit log streams: add backend logs + DD source
This commit is contained in:
@@ -0,0 +1,10 @@
|
|||||||
|
export function providerSpecificPayload(url: string) {
|
||||||
|
const payload: Record<string, string> = {};
|
||||||
|
|
||||||
|
// If URL is related to DataDog, add a "ddsource: infisical" entry
|
||||||
|
if (url.includes("datadoghq")) {
|
||||||
|
payload.ddsource = "infisical";
|
||||||
|
}
|
||||||
|
|
||||||
|
return payload;
|
||||||
|
}
|
||||||
@@ -13,6 +13,7 @@ import { TLicenseServiceFactory } from "../license/license-service";
|
|||||||
import { OrgPermissionActions, OrgPermissionSubjects } from "../permission/org-permission";
|
import { OrgPermissionActions, OrgPermissionSubjects } from "../permission/org-permission";
|
||||||
import { TPermissionServiceFactory } from "../permission/permission-service-types";
|
import { TPermissionServiceFactory } from "../permission/permission-service-types";
|
||||||
import { TAuditLogStreamDALFactory } from "./audit-log-stream-dal";
|
import { TAuditLogStreamDALFactory } from "./audit-log-stream-dal";
|
||||||
|
import { providerSpecificPayload } from "./audit-log-stream-fns";
|
||||||
import { LogStreamHeaders, TAuditLogStreamServiceFactory } from "./audit-log-stream-types";
|
import { LogStreamHeaders, TAuditLogStreamServiceFactory } from "./audit-log-stream-types";
|
||||||
|
|
||||||
type TAuditLogStreamServiceFactoryDep = {
|
type TAuditLogStreamServiceFactoryDep = {
|
||||||
@@ -69,10 +70,11 @@ export const auditLogStreamServiceFactory = ({
|
|||||||
headers.forEach(({ key, value }) => {
|
headers.forEach(({ key, value }) => {
|
||||||
streamHeaders[key] = value;
|
streamHeaders[key] = value;
|
||||||
});
|
});
|
||||||
|
|
||||||
await request
|
await request
|
||||||
.post(
|
.post(
|
||||||
url,
|
url,
|
||||||
{ ping: "ok" },
|
{ ...providerSpecificPayload(url), ping: "ok" },
|
||||||
{
|
{
|
||||||
headers: streamHeaders,
|
headers: streamHeaders,
|
||||||
// request timeout
|
// request timeout
|
||||||
@@ -137,7 +139,7 @@ export const auditLogStreamServiceFactory = ({
|
|||||||
await request
|
await request
|
||||||
.post(
|
.post(
|
||||||
url || logStream.url,
|
url || logStream.url,
|
||||||
{ ping: "ok" },
|
{ ...providerSpecificPayload(url || logStream.url), ping: "ok" },
|
||||||
{
|
{
|
||||||
headers: streamHeaders,
|
headers: streamHeaders,
|
||||||
// request timeout
|
// request timeout
|
||||||
|
|||||||
@@ -1,13 +1,15 @@
|
|||||||
import { RawAxiosRequestHeaders } from "axios";
|
import { AxiosError, RawAxiosRequestHeaders } from "axios";
|
||||||
|
|
||||||
import { SecretKeyEncoding } from "@app/db/schemas";
|
import { SecretKeyEncoding } from "@app/db/schemas";
|
||||||
import { getConfig } from "@app/lib/config/env";
|
import { getConfig } from "@app/lib/config/env";
|
||||||
import { request } from "@app/lib/config/request";
|
import { request } from "@app/lib/config/request";
|
||||||
import { infisicalSymmetricDecrypt } from "@app/lib/crypto/encryption";
|
import { infisicalSymmetricDecrypt } from "@app/lib/crypto/encryption";
|
||||||
|
import { logger } from "@app/lib/logger";
|
||||||
import { QueueJobs, QueueName, TQueueServiceFactory } from "@app/queue";
|
import { QueueJobs, QueueName, TQueueServiceFactory } from "@app/queue";
|
||||||
import { TProjectDALFactory } from "@app/services/project/project-dal";
|
import { TProjectDALFactory } from "@app/services/project/project-dal";
|
||||||
|
|
||||||
import { TAuditLogStreamDALFactory } from "../audit-log-stream/audit-log-stream-dal";
|
import { TAuditLogStreamDALFactory } from "../audit-log-stream/audit-log-stream-dal";
|
||||||
|
import { providerSpecificPayload } from "../audit-log-stream/audit-log-stream-fns";
|
||||||
import { LogStreamHeaders } from "../audit-log-stream/audit-log-stream-types";
|
import { LogStreamHeaders } from "../audit-log-stream/audit-log-stream-types";
|
||||||
import { TLicenseServiceFactory } from "../license/license-service";
|
import { TLicenseServiceFactory } from "../license/license-service";
|
||||||
import { TAuditLogDALFactory } from "./audit-log-dal";
|
import { TAuditLogDALFactory } from "./audit-log-dal";
|
||||||
@@ -128,13 +130,29 @@ export const auditLogQueueServiceFactory = async ({
|
|||||||
headers[key] = value;
|
headers[key] = value;
|
||||||
});
|
});
|
||||||
|
|
||||||
return request.post(url, auditLog, {
|
try {
|
||||||
headers,
|
const response = await request.post(
|
||||||
// request timeout
|
url,
|
||||||
timeout: AUDIT_LOG_STREAM_TIMEOUT,
|
{ ...providerSpecificPayload(url), ...auditLog },
|
||||||
// connection timeout
|
{
|
||||||
signal: AbortSignal.timeout(AUDIT_LOG_STREAM_TIMEOUT)
|
headers,
|
||||||
});
|
// request timeout
|
||||||
|
timeout: AUDIT_LOG_STREAM_TIMEOUT,
|
||||||
|
// connection timeout
|
||||||
|
signal: AbortSignal.timeout(AUDIT_LOG_STREAM_TIMEOUT)
|
||||||
|
}
|
||||||
|
);
|
||||||
|
logger.info(
|
||||||
|
`Successfully streamed audit log to ${url} for org ${orgId}. Response body: ${JSON.stringify(response.data)}`
|
||||||
|
);
|
||||||
|
return response;
|
||||||
|
} catch (error) {
|
||||||
|
logger.error(
|
||||||
|
`Failed to stream audit log to ${url} for org ${orgId}. Error:`,
|
||||||
|
(error as AxiosError).message
|
||||||
|
);
|
||||||
|
return error;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
@@ -218,13 +236,29 @@ export const auditLogQueueServiceFactory = async ({
|
|||||||
headers[key] = value;
|
headers[key] = value;
|
||||||
});
|
});
|
||||||
|
|
||||||
return request.post(url, auditLog, {
|
try {
|
||||||
headers,
|
const response = await request.post(
|
||||||
// request timeout
|
url,
|
||||||
timeout: AUDIT_LOG_STREAM_TIMEOUT,
|
{ ...providerSpecificPayload(url), ...auditLog },
|
||||||
// connection timeout
|
{
|
||||||
signal: AbortSignal.timeout(AUDIT_LOG_STREAM_TIMEOUT)
|
headers,
|
||||||
});
|
// request timeout
|
||||||
|
timeout: AUDIT_LOG_STREAM_TIMEOUT,
|
||||||
|
// connection timeout
|
||||||
|
signal: AbortSignal.timeout(AUDIT_LOG_STREAM_TIMEOUT)
|
||||||
|
}
|
||||||
|
);
|
||||||
|
logger.info(
|
||||||
|
`Successfully streamed audit log to ${url} for org ${orgId}. Response body: ${JSON.stringify(response.data)}`
|
||||||
|
);
|
||||||
|
return response;
|
||||||
|
} catch (error) {
|
||||||
|
logger.error(
|
||||||
|
`Failed to stream audit log to ${url} for org ${orgId}. Error:`,
|
||||||
|
(error as AxiosError).message
|
||||||
|
);
|
||||||
|
return error;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user