mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-09-22 13:39:35 +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(),
|
||||
authMethod: z.string().nullable().optional(),
|
||||
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>;
|
||||
|
||||
@@ -227,8 +227,8 @@ export const registerIdentityRouter = async (server: FastifyZodProvider) => {
|
||||
identity: IdentityOrgMembershipsSchema.extend({
|
||||
metadata: z
|
||||
.object({
|
||||
key: z.string().trim().min(1),
|
||||
id: z.string().trim().min(1),
|
||||
key: z.string().trim().min(1),
|
||||
value: z.string().trim().min(1)
|
||||
})
|
||||
.array()
|
||||
|
||||
@@ -106,18 +106,29 @@ export const identityServiceFactory = ({
|
||||
},
|
||||
tx
|
||||
);
|
||||
|
||||
let insertedMetadata: Array<{
|
||||
id: string;
|
||||
key: string;
|
||||
value: string;
|
||||
}> = [];
|
||||
|
||||
if (metadata && metadata.length) {
|
||||
await identityMetadataDAL.insertMany(
|
||||
metadata.map(({ key, value }) => ({
|
||||
identityId: newIdentity.id,
|
||||
orgId,
|
||||
key,
|
||||
value
|
||||
})),
|
||||
tx
|
||||
);
|
||||
const rowsToInsert = metadata.map(({ key, value }) => ({
|
||||
identityId: newIdentity.id,
|
||||
orgId,
|
||||
key,
|
||||
value
|
||||
}));
|
||||
|
||||
insertedMetadata = await identityMetadataDAL.insertMany(rowsToInsert, tx);
|
||||
}
|
||||
return { ...newIdentity, authMethods: [] };
|
||||
|
||||
return {
|
||||
...newIdentity,
|
||||
authMethods: [],
|
||||
metadata: insertedMetadata
|
||||
};
|
||||
});
|
||||
await licenseService.updateSubscriptionOrgMemberCount(orgId);
|
||||
|
||||
@@ -189,21 +200,31 @@ export const identityServiceFactory = ({
|
||||
tx
|
||||
);
|
||||
}
|
||||
let insertedMetadata: Array<{
|
||||
id: string;
|
||||
key: string;
|
||||
value: string;
|
||||
}> = [];
|
||||
|
||||
if (metadata) {
|
||||
await identityMetadataDAL.delete({ orgId: identityOrgMembership.orgId, identityId: id }, tx);
|
||||
|
||||
if (metadata.length) {
|
||||
await identityMetadataDAL.insertMany(
|
||||
metadata.map(({ key, value }) => ({
|
||||
identityId: newIdentity.id,
|
||||
orgId: identityOrgMembership.orgId,
|
||||
key,
|
||||
value
|
||||
})),
|
||||
tx
|
||||
);
|
||||
const rowsToInsert = metadata.map(({ key, value }) => ({
|
||||
identityId: newIdentity.id,
|
||||
orgId: identityOrgMembership.orgId,
|
||||
key,
|
||||
value
|
||||
}));
|
||||
|
||||
insertedMetadata = await identityMetadataDAL.insertMany(rowsToInsert, tx);
|
||||
}
|
||||
}
|
||||
return newIdentity;
|
||||
|
||||
return {
|
||||
...newIdentity,
|
||||
metadata: insertedMetadata
|
||||
};
|
||||
});
|
||||
|
||||
return { ...identity, orgId: identityOrgMembership.orgId };
|
||||
@@ -224,7 +245,13 @@ export const identityServiceFactory = ({
|
||||
actorOrgId
|
||||
);
|
||||
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 ({
|
||||
|
||||
Reference in New Issue
Block a user