mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-08 20:28:16 +00:00
feat: improved audit logs
This commit is contained in:
@@ -1,35 +1,58 @@
|
|||||||
import { useInfiniteQuery, useQuery } from "@tanstack/react-query";
|
import { useInfiniteQuery, UseInfiniteQueryOptions, useQuery } from "@tanstack/react-query";
|
||||||
|
|
||||||
import { apiRequest } from "@app/config/request";
|
import { apiRequest } from "@app/config/request";
|
||||||
|
|
||||||
import { Actor, AuditLog, AuditLogFilters } from "./types";
|
import { Actor, AuditLog, TGetAuditLogsFilter } from "./types";
|
||||||
|
|
||||||
export const auditLogKeys = {
|
export const auditLogKeys = {
|
||||||
getAuditLogs: (workspaceId: string | null, filters: AuditLogFilters) =>
|
getAuditLogs: (workspaceId: string | null, filters: TGetAuditLogsFilter) =>
|
||||||
[{ workspaceId, filters }, "audit-logs"] as const,
|
[{ workspaceId, filters }, "audit-logs"] as const,
|
||||||
getAuditLogActorFilterOpts: (workspaceId: string) =>
|
getAuditLogActorFilterOpts: (workspaceId: string) =>
|
||||||
[{ workspaceId }, "audit-log-actor-filters"] as const
|
[{ workspaceId }, "audit-log-actor-filters"] as const
|
||||||
};
|
};
|
||||||
|
|
||||||
export const useGetAuditLogs = (filters: AuditLogFilters, workspaceId: string | null) => {
|
export const useGetAuditLogs = (
|
||||||
|
filters: TGetAuditLogsFilter,
|
||||||
|
projectId: string | null,
|
||||||
|
options: Omit<
|
||||||
|
UseInfiniteQueryOptions<
|
||||||
|
AuditLog[],
|
||||||
|
unknown,
|
||||||
|
AuditLog[],
|
||||||
|
AuditLog[],
|
||||||
|
ReturnType<typeof auditLogKeys.getAuditLogs>
|
||||||
|
>,
|
||||||
|
"queryFn" | "queryKey" | "getNextPageParam"
|
||||||
|
> = {}
|
||||||
|
) => {
|
||||||
return useInfiniteQuery({
|
return useInfiniteQuery({
|
||||||
queryKey: auditLogKeys.getAuditLogs(workspaceId, filters),
|
queryKey: auditLogKeys.getAuditLogs(projectId, filters),
|
||||||
queryFn: async ({ pageParam }) => {
|
queryFn: async ({ pageParam }) => {
|
||||||
const auditLogEndpoint = workspaceId
|
const { data } = await apiRequest.get<{ auditLogs: AuditLog[] }>(
|
||||||
? `/api/v1/workspace/${workspaceId}/audit-logs`
|
"/api/v1/organization/audit-logs",
|
||||||
: "/api/v1/organization/audit-logs";
|
{
|
||||||
const { data } = await apiRequest.get<{ auditLogs: AuditLog[] }>(auditLogEndpoint, {
|
params: {
|
||||||
params: {
|
...filters,
|
||||||
...filters,
|
offset: pageParam,
|
||||||
offset: pageParam,
|
startDate: filters?.startDate?.toISOString(),
|
||||||
startDate: filters?.startDate?.toISOString(),
|
endDate: filters?.endDate?.toISOString(),
|
||||||
endDate: filters?.endDate?.toISOString()
|
...(filters.eventMetadata && Object.keys(filters.eventMetadata).length
|
||||||
|
? {
|
||||||
|
eventMetadata: Object.entries(filters.eventMetadata)
|
||||||
|
.map(([key, value]) => `${key}=${value}`)
|
||||||
|
.join(",")
|
||||||
|
}
|
||||||
|
: {}),
|
||||||
|
...(filters.eventType?.length ? { eventType: filters.eventType.join(",") } : {}),
|
||||||
|
...(projectId ? { projectId } : {})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
);
|
||||||
return data.auditLogs;
|
return data.auditLogs;
|
||||||
},
|
},
|
||||||
getNextPageParam: (lastPage, pages) =>
|
getNextPageParam: (lastPage, pages) =>
|
||||||
lastPage.length !== 0 ? pages.length * filters.limit : undefined
|
lastPage.length !== 0 ? pages.length * filters.limit : undefined,
|
||||||
|
...options
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,17 @@ import { IdentityTrustedIp } from "../identities/types";
|
|||||||
import { PkiItemType } from "../pkiCollections/constants";
|
import { PkiItemType } from "../pkiCollections/constants";
|
||||||
import { ActorType, EventType, UserAgentType } from "./enums";
|
import { ActorType, EventType, UserAgentType } from "./enums";
|
||||||
|
|
||||||
|
export type TGetAuditLogsFilter = {
|
||||||
|
eventType?: EventType[];
|
||||||
|
userAgentType?: UserAgentType;
|
||||||
|
eventMetadata?: Record<string, string>;
|
||||||
|
actorType?: ActorType;
|
||||||
|
actorId?: string; // user ID format
|
||||||
|
startDate?: Date;
|
||||||
|
endDate?: Date;
|
||||||
|
limit: number;
|
||||||
|
};
|
||||||
|
|
||||||
interface UserActorMetadata {
|
interface UserActorMetadata {
|
||||||
userId: string;
|
userId: string;
|
||||||
email: string;
|
email: string;
|
||||||
@@ -33,7 +44,13 @@ export interface IdentityActor {
|
|||||||
metadata: IdentityActorMetadata;
|
metadata: IdentityActorMetadata;
|
||||||
}
|
}
|
||||||
|
|
||||||
export type Actor = UserActor | ServiceActor | IdentityActor;
|
export interface PlatformActorMetadata {}
|
||||||
|
export interface PlatformActor {
|
||||||
|
type: ActorType.PLATFORM;
|
||||||
|
metadata: PlatformActorMetadata;
|
||||||
|
}
|
||||||
|
|
||||||
|
export type Actor = UserActor | ServiceActor | IdentityActor | PlatformActor;
|
||||||
|
|
||||||
interface GetSecretsEvent {
|
interface GetSecretsEvent {
|
||||||
type: EventType.GET_SECRETS;
|
type: EventType.GET_SECRETS;
|
||||||
@@ -761,6 +778,22 @@ interface GetProjectSlackConfig {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export enum IntegrationSyncedEventTrigger {
|
||||||
|
MANUAL = "manual",
|
||||||
|
AUTO = "auto"
|
||||||
|
}
|
||||||
|
|
||||||
|
interface IntegrationSyncedEvent {
|
||||||
|
type: EventType.INTEGRATION_SYNCED;
|
||||||
|
metadata: {
|
||||||
|
integrationId: string;
|
||||||
|
lastSyncJobId: string;
|
||||||
|
lastUsed: Date;
|
||||||
|
syncMessage: string;
|
||||||
|
isSynced: boolean;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
export type Event =
|
export type Event =
|
||||||
| GetSecretsEvent
|
| GetSecretsEvent
|
||||||
| GetSecretEvent
|
| GetSecretEvent
|
||||||
@@ -838,7 +871,8 @@ export type Event =
|
|||||||
| CreateCertificateTemplateEstConfig
|
| CreateCertificateTemplateEstConfig
|
||||||
| GetCertificateTemplateEstConfig
|
| GetCertificateTemplateEstConfig
|
||||||
| UpdateProjectSlackConfig
|
| UpdateProjectSlackConfig
|
||||||
| GetProjectSlackConfig;
|
| GetProjectSlackConfig
|
||||||
|
| IntegrationSyncedEvent;
|
||||||
|
|
||||||
export type AuditLog = {
|
export type AuditLog = {
|
||||||
id: string;
|
id: string;
|
||||||
@@ -856,12 +890,3 @@ export type AuditLog = {
|
|||||||
slug: string;
|
slug: string;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
export type AuditLogFilters = {
|
|
||||||
eventType?: EventType;
|
|
||||||
userAgentType?: UserAgentType;
|
|
||||||
actor?: string;
|
|
||||||
limit: number;
|
|
||||||
startDate?: Date;
|
|
||||||
endDate?: Date;
|
|
||||||
};
|
|
||||||
|
|||||||
@@ -1,10 +1,9 @@
|
|||||||
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
import { useMutation, useQuery, useQueryClient, UseQueryOptions } from "@tanstack/react-query";
|
||||||
|
|
||||||
import { createNotification } from "@app/components/notifications";
|
import { createNotification } from "@app/components/notifications";
|
||||||
import { apiRequest } from "@app/config/request";
|
import { apiRequest } from "@app/config/request";
|
||||||
|
|
||||||
import { workspaceKeys } from "../workspace";
|
import { workspaceKeys } from "../workspace";
|
||||||
import { TCloudIntegration } from "./types";
|
|
||||||
import { TCloudIntegration, TIntegrationWithEnv } from "./types";
|
import { TCloudIntegration, TIntegrationWithEnv } from "./types";
|
||||||
|
|
||||||
export const integrationQueryKeys = {
|
export const integrationQueryKeys = {
|
||||||
@@ -138,9 +137,21 @@ export const useDeleteIntegration = () => {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
export const useGetIntegration = (integrationId: string) => {
|
export const useGetIntegration = (
|
||||||
|
integrationId: string,
|
||||||
|
options?: Omit<
|
||||||
|
UseQueryOptions<
|
||||||
|
TIntegrationWithEnv,
|
||||||
|
unknown,
|
||||||
|
TIntegrationWithEnv,
|
||||||
|
ReturnType<typeof integrationQueryKeys.getIntegration>
|
||||||
|
>,
|
||||||
|
"queryFn" | "queryKey"
|
||||||
|
>
|
||||||
|
) => {
|
||||||
return useQuery({
|
return useQuery({
|
||||||
enabled: Boolean(integrationId),
|
...options,
|
||||||
|
enabled: Boolean(integrationId && options?.enabled === undefined ? true : options?.enabled),
|
||||||
queryKey: integrationQueryKeys.getIntegration(integrationId),
|
queryKey: integrationQueryKeys.getIntegration(integrationId),
|
||||||
queryFn: () => fetchIntegration(integrationId)
|
queryFn: () => fetchIntegration(integrationId)
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user