Skip to content

Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.

misc: addressed schema response ordering issue

Sheen Capadnganefbd7b9f41d9
diff --git a/backend/src/ee/routes/v1/pam-account-routers/pam-account-router.ts b/backend/src/ee/routes/v1/pam-account-routers/pam-account-router.ts
index 8543e7933d..0938aeae1d 100644
--- a/backend/src/ee/routes/v1/pam-account-routers/pam-account-router.ts
+++ b/backend/src/ee/routes/v1/pam-account-routers/pam-account-router.ts
@@ -17,8 +17,7 @@ import { readLimit, writeLimit } from "@app/server/config/rateLimiter";
import { verifyAuth } from "@app/server/plugins/auth/verify-auth";
import { AuthMode } from "@app/services/auth/auth-type";
-const SanitizedAccountSchema = z.union([
- // ORDER MATTERS
+const SanitizedAccountSchema = z.discriminatedUnion("resourceType", [
SanitizedKubernetesAccountWithResourceSchema,
SanitizedSSHAccountWithResourceSchema,
SanitizedPostgresAccountWithResourceSchema,
diff --git a/backend/src/ee/services/pam-account/pam-account-service.ts b/backend/src/ee/services/pam-account/pam-account-service.ts
index 52c14b741a..7765685346 100644
--- a/backend/src/ee/services/pam-account/pam-account-service.ts
+++ b/backend/src/ee/services/pam-account/pam-account-service.ts
@@ -199,6 +199,7 @@ export const pamAccountServiceFactory = ({
return {
...(await decryptAccount(account, resource.projectId, kmsService)),
+ resourceType: resource.resourceType,
resource: {
id: resource.id,
name: resource.name,
@@ -426,6 +427,7 @@ export const pamAccountServiceFactory = ({
resource: Pick<TPamResources, "id" | "name" | "resourceType"> & { rotationCredentialsConfigured: boolean };
credentials: TPamAccountCredentials;
lastRotationMessage: string | null;
+ resourceType: string;
}
> = [];
@@ -445,6 +447,7 @@ export const pamAccountServiceFactory = ({
decryptedAndPermittedAccounts.push({
...decryptedAccount,
+ resourceType: account.resource.resourceType,
resource: {
id: account.resource.id,
name: account.resource.name,
@@ -486,6 +489,7 @@ export const pamAccountServiceFactory = ({
return {
...decryptedAccount,
+ resourceType: accountWithResource.resource.resourceType,
resource: {
id: accountWithResource.resource.id,
name: accountWithResource.resource.name,
diff --git a/backend/src/ee/services/pam-resource/aws-iam/aws-iam-resource-schemas.ts b/backend/src/ee/services/pam-resource/aws-iam/aws-iam-resource-schemas.ts
index 2762977eba..cbb1df1a7b 100644
--- a/backend/src/ee/services/pam-resource/aws-iam/aws-iam-resource-schemas.ts
+++ b/backend/src/ee/services/pam-resource/aws-iam/aws-iam-resource-schemas.ts
@@ -74,6 +74,7 @@ export const UpdateAwsIamAccountSchema = BaseUpdatePamAccountSchema.extend({
});
export const SanitizedAwsIamAccountWithResourceSchema = BasePamAccountSchemaWithResource.extend({
+ resourceType: z.literal(PamResource.AwsIam),
credentials: AwsIamAccountCredentialsSchema.pick({
targetRoleArn: true,
defaultSessionDuration: true
diff --git a/backend/src/ee/services/pam-resource/kubernetes/kubernetes-resource-schemas.ts b/backend/src/ee/services/pam-resource/kubernetes/kubernetes-resource-schemas.ts
index 2a0f06d0e5..aa60e91fb4 100644
--- a/backend/src/ee/services/pam-resource/kubernetes/kubernetes-resource-schemas.ts
+++ b/backend/src/ee/services/pam-resource/kubernetes/kubernetes-resource-schemas.ts
@@ -81,6 +81,7 @@ export const UpdateKubernetesAccountSchema = BaseUpdatePamAccountSchema.extend({
});
export const SanitizedKubernetesAccountWithResourceSchema = BasePamAccountSchemaWithResource.extend({
+ resourceType: z.literal(PamResource.Kubernetes),
credentials: z.discriminatedUnion("authMethod", [
z.object({
authMethod: z.literal(KubernetesAuthMethod.ServiceAccountToken)
diff --git a/backend/src/ee/services/pam-resource/mysql/mysql-resource-schemas.ts b/backend/src/ee/services/pam-resource/mysql/mysql-resource-schemas.ts
index cb12a4c8cc..61a88246cd 100644
--- a/backend/src/ee/services/pam-resource/mysql/mysql-resource-schemas.ts
+++ b/backend/src/ee/services/pam-resource/mysql/mysql-resource-schemas.ts
@@ -67,6 +67,7 @@ export const UpdateMySQLAccountSchema = BaseUpdatePamAccountSchema.extend({
});
export const SanitizedMySQLAccountWithResourceSchema = BasePamAccountSchemaWithResource.extend({
+ resourceType: z.literal(PamResource.MySQL),
credentials: MySQLAccountCredentialsSchema.pick({
username: true
})
diff --git a/backend/src/ee/services/pam-resource/postgres/postgres-resource-schemas.ts b/backend/src/ee/services/pam-resource/postgres/postgres-resource-schemas.ts
index fd58484f71..554a414c9a 100644
--- a/backend/src/ee/services/pam-resource/postgres/postgres-resource-schemas.ts
+++ b/backend/src/ee/services/pam-resource/postgres/postgres-resource-schemas.ts
@@ -64,6 +64,7 @@ export const UpdatePostgresAccountSchema = BaseUpdatePamAccountSchema.extend({
});
export const SanitizedPostgresAccountWithResourceSchema = BasePamAccountSchemaWithResource.extend({
+ resourceType: z.literal(PamResource.Postgres),
credentials: PostgresAccountCredentialsSchema.pick({
username: true
})
diff --git a/backend/src/ee/services/pam-resource/redis/redis-resource-schemas.ts b/backend/src/ee/services/pam-resource/redis/redis-resource-schemas.ts
index ada0530b4b..99c578e730 100644
--- a/backend/src/ee/services/pam-resource/redis/redis-resource-schemas.ts
+++ b/backend/src/ee/services/pam-resource/redis/redis-resource-schemas.ts
@@ -83,6 +83,7 @@ export const UpdateRedisAccountSchema = BaseUpdatePamAccountSchema.extend({
});
export const SanitizedRedisAccountWithResourceSchema = BasePamAccountSchemaWithResource.extend({
+ resourceType: z.literal(PamResource.Redis),
credentials: RedisAccountCredentialsSchema.pick({
username: true
})
diff --git a/backend/src/ee/services/pam-resource/ssh/ssh-resource-schemas.ts b/backend/src/ee/services/pam-resource/ssh/ssh-resource-schemas.ts
index 192c1a2bc6..b44d5c2cf4 100644
--- a/backend/src/ee/services/pam-resource/ssh/ssh-resource-schemas.ts
+++ b/backend/src/ee/services/pam-resource/ssh/ssh-resource-schemas.ts
@@ -114,6 +114,7 @@ export const UpdateSSHAccountSchema = BaseUpdatePamAccountSchema.extend({
});
export const SanitizedSSHAccountWithResourceSchema = BasePamAccountSchemaWithResource.extend({
+ resourceType: z.literal(PamResource.SSH),
credentials: z.discriminatedUnion("authMethod", [
z.object({
authMethod: z.literal(SSHAuthMethod.Password),