Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.
TypeScript acmeagentsai-agentscertificate-managementdevsecopsenvironment-variableskubernetesopen-sourcepampkipostgresprivate-caprivileged-access-managementsecret-managementsecret-managersecretssecrets-managementsecuritysecurity-toolsvault
refac: make schema easier to check the weekly change
adilson9d693307019f
diff --git a/backend/src/ee/services/audit-log/audit-log-types.ts b/backend/src/ee/services/audit-log/audit-log-types.tsindex f06194ceb9..04bdca27b9 100644--- a/backend/src/ee/services/audit-log/audit-log-types.ts+++ b/backend/src/ee/services/audit-log/audit-log-types.ts@@ -5509,7 +5509,7 @@ interface ViewSecretManagementInsightsOrgAuthMethodDistributionEvent {interface ViewSecretManagementInsightsStaticSecretUsageEvent {type: EventType.VIEW_INSIGHTS_SECRETS_MANAGEMENT_STATIC_SECRET_USAGE;metadata: {- totalSecrets: number;+ totalSecretsCreated: number;};}diff --git a/backend/src/ee/services/insights/insights-schemas.ts b/backend/src/ee/services/insights/insights-schemas.tsindex 8623e19421..8d86036fa6 100644--- a/backend/src/ee/services/insights/insights-schemas.ts+++ b/backend/src/ee/services/insights/insights-schemas.ts@@ -3,27 +3,27 @@ import { z } from "zod";import { IdentityAuthMethod } from "@app/db/schemas";import { INSIGHTS } from "@app/lib/api-docs";-export const SecretsUsageInsightsSchema = z.object({- activeLeases: z.number().int().describe(INSIGHTS.GET_SECRETS_USAGE_INSIGHTS.activeLeases),- users: z.number().int().describe(INSIGHTS.GET_SECRETS_USAGE_INSIGHTS.users),- identities: z.number().int().describe(INSIGHTS.GET_SECRETS_USAGE_INSIGHTS.identities)+export const SecretsSummarySchema = z.object({+ activeLeases: z.number().int().describe(INSIGHTS.GET_SECRETS_SUMMARY.activeLeases),+ users: z.number().int().describe(INSIGHTS.GET_SECRETS_SUMMARY.users),+ identities: z.number().int().describe(INSIGHTS.GET_SECRETS_SUMMARY.identities)});export const SecretsProjectWarningSchema = z.object({- projectId: z.string().uuid().describe(INSIGHTS.GET_SECRETS_PROJECT_WARNINGS.projectId),- projectName: z.string().describe(INSIGHTS.GET_SECRETS_PROJECT_WARNINGS.projectName),- projectSlug: z.string().describe(INSIGHTS.GET_SECRETS_PROJECT_WARNINGS.projectSlug),- totalSecrets: z.number().int().describe(INSIGHTS.GET_SECRETS_PROJECT_WARNINGS.totalSecrets),- severityScore: z.number().int().describe(INSIGHTS.GET_SECRETS_PROJECT_WARNINGS.severityScore),+ projectId: z.string().uuid().describe(INSIGHTS.GET_SECRETS_PROJECT.projectId),+ projectName: z.string().describe(INSIGHTS.GET_SECRETS_PROJECT.projectName),+ projectSlug: z.string().describe(INSIGHTS.GET_SECRETS_PROJECT.projectSlug),+ totalSecrets: z.number().int().describe(INSIGHTS.GET_SECRETS_PROJECT.totalSecrets),+ severityScore: z.number().int().describe(INSIGHTS.GET_SECRETS_PROJECT.severityScore),warnings: z.object({- duplicatedSecrets: z.number().int().nullable().describe(INSIGHTS.GET_SECRETS_PROJECT_WARNINGS.duplicatedSecrets),- staleSecrets: z.number().int().describe(INSIGHTS.GET_SECRETS_PROJECT_WARNINGS.staleSecrets),- failedRotations: z.number().int().describe(INSIGHTS.GET_SECRETS_PROJECT_WARNINGS.failedRotations),- failedSyncs: z.number().int().describe(INSIGHTS.GET_SECRETS_PROJECT_WARNINGS.failedSyncs),- orphanedLeases: z.number().int().describe(INSIGHTS.GET_SECRETS_PROJECT_WARNINGS.orphanedLeases)+ duplicatedSecrets: z.number().int().nullable().describe(INSIGHTS.GET_SECRETS_PROJECT.duplicatedSecrets),+ staleSecrets: z.number().int().describe(INSIGHTS.GET_SECRETS_PROJECT.staleSecrets),+ failedRotations: z.number().int().describe(INSIGHTS.GET_SECRETS_PROJECT.failedRotations),+ failedSyncs: z.number().int().describe(INSIGHTS.GET_SECRETS_PROJECT.failedSyncs),+ orphanedLeases: z.number().int().describe(INSIGHTS.GET_SECRETS_PROJECT.orphanedLeases)})- .describe(INSIGHTS.GET_SECRETS_PROJECT_WARNINGS.warnings)+ .describe(INSIGHTS.GET_SECRETS_PROJECT.warnings)});export const OrgSecretsAccessVolumeSchema = z.object({@@ -61,10 +61,10 @@ export const StaticSecretsUsageSchema = z.object({.describe(INSIGHTS.GET_STATIC_SECRETS_USAGE.weeks)});-export const SecretsProjectWarningsSchema = z.object({+export const SecretsProjectsSchema = z.object({projects: SecretsProjectWarningSchema.array(),- totalProjects: z.number().int().describe(INSIGHTS.GET_SECRETS_PROJECT_WARNINGS.totalProjects),- projectsWithIssues: z.number().int().describe(INSIGHTS.GET_SECRETS_PROJECT_WARNINGS.projectsWithIssues),- offset: z.number().int().describe(INSIGHTS.GET_SECRETS_PROJECT_WARNINGS.offset),- limit: z.number().int().describe(INSIGHTS.GET_SECRETS_PROJECT_WARNINGS.limit)+ totalProjects: z.number().int().describe(INSIGHTS.GET_SECRETS_PROJECTS.totalProjects),+ projectsWithIssues: z.number().int().describe(INSIGHTS.GET_SECRETS_PROJECTS.projectsWithIssues),+ offset: z.number().int().describe(INSIGHTS.GET_SECRETS_PROJECTS.offset),+ limit: z.number().int().describe(INSIGHTS.GET_SECRETS_PROJECTS.limit)});diff --git a/backend/src/ee/services/insights/insights-service.ts b/backend/src/ee/services/insights/insights-service.tsindex dd7809adb5..88453c575a 100644--- a/backend/src/ee/services/insights/insights-service.ts+++ b/backend/src/ee/services/insights/insights-service.ts@@ -738,8 +738,11 @@ export const insightsServiceFactory = ({});};- // How many static secrets the org held at the end of each of the last 12 weeks, as a running- // total rather than per-week additions.+ // How many static secrets the org created in each of the last 12 UTC calendar weeks.+ //+ // Deleting a secret is a hard delete with no tombstone, so a week can only be counted from the+ // createdAt of secrets that still exist. Past weeks therefore understate what was created then+ // and drift lower as those secrets are deleted.const getStaticSecretsUsage = async (dto: TGetStaticSecretsUsageDTO): Promise<TStaticSecretsUsage> => {await checkSecretsProductInsightsPermission(permissionService,@@ -776,18 +779,14 @@ export const insightsServiceFactory = ({const creationsByWeek = new Map(priorWeeks.map((row) => [row.weekStart, row.count]));creationsByWeek.set(currentWeekStartStr, createdThisWeek);- let runningTotal = 0;-+ // Weeks the org created nothing in are absent from the query, so they are filled with zero+ // here rather than being skipped, keeping the series at one entry per week.return {- weeks: weekStarts.map((weekStart) => {- runningTotal += creationsByWeek.get(weekStart) ?? 0;-- return {- weekStart,- totalSecrets: runningTotal,- isPartial: weekStart === currentWeekStartStr- };- })+ weeks: weekStarts.map((weekStart) => ({+ weekStart,+ totalSecrets: creationsByWeek.get(weekStart) ?? 0,+ isPartial: weekStart === currentWeekStartStr+ }))};};