mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-07 19:28:09 +00:00
Return metadata with identity post endpoints
This commit is contained in:
@@ -12,7 +12,8 @@ export const IdentitiesSchema = z.object({
|
|||||||
name: z.string(),
|
name: z.string(),
|
||||||
authMethod: z.string().nullable().optional(),
|
authMethod: z.string().nullable().optional(),
|
||||||
createdAt: z.date(),
|
createdAt: z.date(),
|
||||||
updatedAt: z.date()
|
updatedAt: z.date(),
|
||||||
|
metadata: z.object({ id: z.string(), key: z.string(), value: z.string() }).array().optional()
|
||||||
});
|
});
|
||||||
|
|
||||||
export type TIdentities = z.infer<typeof IdentitiesSchema>;
|
export type TIdentities = z.infer<typeof IdentitiesSchema>;
|
||||||
|
|||||||
@@ -227,8 +227,8 @@ export const registerIdentityRouter = async (server: FastifyZodProvider) => {
|
|||||||
identity: IdentityOrgMembershipsSchema.extend({
|
identity: IdentityOrgMembershipsSchema.extend({
|
||||||
metadata: z
|
metadata: z
|
||||||
.object({
|
.object({
|
||||||
key: z.string().trim().min(1),
|
|
||||||
id: z.string().trim().min(1),
|
id: z.string().trim().min(1),
|
||||||
|
key: z.string().trim().min(1),
|
||||||
value: z.string().trim().min(1)
|
value: z.string().trim().min(1)
|
||||||
})
|
})
|
||||||
.array()
|
.array()
|
||||||
|
|||||||
@@ -106,18 +106,29 @@ export const identityServiceFactory = ({
|
|||||||
},
|
},
|
||||||
tx
|
tx
|
||||||
);
|
);
|
||||||
|
|
||||||
|
let insertedMetadata: Array<{
|
||||||
|
id: string;
|
||||||
|
key: string;
|
||||||
|
value: string;
|
||||||
|
}> = [];
|
||||||
|
|
||||||
if (metadata && metadata.length) {
|
if (metadata && metadata.length) {
|
||||||
await identityMetadataDAL.insertMany(
|
const rowsToInsert = metadata.map(({ key, value }) => ({
|
||||||
metadata.map(({ key, value }) => ({
|
identityId: newIdentity.id,
|
||||||
identityId: newIdentity.id,
|
orgId,
|
||||||
orgId,
|
key,
|
||||||
key,
|
value
|
||||||
value
|
}));
|
||||||
})),
|
|
||||||
tx
|
insertedMetadata = await identityMetadataDAL.insertMany(rowsToInsert, tx);
|
||||||
);
|
|
||||||
}
|
}
|
||||||
return { ...newIdentity, authMethods: [] };
|
|
||||||
|
return {
|
||||||
|
...newIdentity,
|
||||||
|
authMethods: [],
|
||||||
|
metadata: insertedMetadata
|
||||||
|
};
|
||||||
});
|
});
|
||||||
await licenseService.updateSubscriptionOrgMemberCount(orgId);
|
await licenseService.updateSubscriptionOrgMemberCount(orgId);
|
||||||
|
|
||||||
@@ -189,21 +200,31 @@ export const identityServiceFactory = ({
|
|||||||
tx
|
tx
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
let insertedMetadata: Array<{
|
||||||
|
id: string;
|
||||||
|
key: string;
|
||||||
|
value: string;
|
||||||
|
}> = [];
|
||||||
|
|
||||||
if (metadata) {
|
if (metadata) {
|
||||||
await identityMetadataDAL.delete({ orgId: identityOrgMembership.orgId, identityId: id }, tx);
|
await identityMetadataDAL.delete({ orgId: identityOrgMembership.orgId, identityId: id }, tx);
|
||||||
|
|
||||||
if (metadata.length) {
|
if (metadata.length) {
|
||||||
await identityMetadataDAL.insertMany(
|
const rowsToInsert = metadata.map(({ key, value }) => ({
|
||||||
metadata.map(({ key, value }) => ({
|
identityId: newIdentity.id,
|
||||||
identityId: newIdentity.id,
|
orgId: identityOrgMembership.orgId,
|
||||||
orgId: identityOrgMembership.orgId,
|
key,
|
||||||
key,
|
value
|
||||||
value
|
}));
|
||||||
})),
|
|
||||||
tx
|
insertedMetadata = await identityMetadataDAL.insertMany(rowsToInsert, tx);
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return newIdentity;
|
|
||||||
|
return {
|
||||||
|
...newIdentity,
|
||||||
|
metadata: insertedMetadata
|
||||||
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
return { ...identity, orgId: identityOrgMembership.orgId };
|
return { ...identity, orgId: identityOrgMembership.orgId };
|
||||||
@@ -224,7 +245,13 @@ export const identityServiceFactory = ({
|
|||||||
actorOrgId
|
actorOrgId
|
||||||
);
|
);
|
||||||
ForbiddenError.from(permission).throwUnlessCan(OrgPermissionIdentityActions.Read, OrgPermissionSubjects.Identity);
|
ForbiddenError.from(permission).throwUnlessCan(OrgPermissionIdentityActions.Read, OrgPermissionSubjects.Identity);
|
||||||
return identity;
|
|
||||||
|
const metadata = await identityMetadataDAL.find({
|
||||||
|
identityId: id,
|
||||||
|
orgId: identity.orgId
|
||||||
|
});
|
||||||
|
|
||||||
|
return { ...identity, metadata };
|
||||||
};
|
};
|
||||||
|
|
||||||
const deleteIdentity = async ({
|
const deleteIdentity = async ({
|
||||||
|
|||||||
Reference in New Issue
Block a user