mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-09-22 13:39:35 +00:00
Lint fix and greptile comments addressed
This commit is contained in:
@@ -179,18 +179,20 @@ export const registerGithubOrgSyncRouter = async (server: FastifyZodProvider) =>
|
||||
onRequest: verifyAuth([AuthMode.JWT]),
|
||||
schema: {
|
||||
body: z.object({
|
||||
githubOrgAccessToken: z.string().trim().min(1, "GitHub access token is required")
|
||||
githubOrgAccessToken: z.string().trim().min(1, "GitHub access token is required").max(1000)
|
||||
}),
|
||||
response: {
|
||||
200: z.object({
|
||||
valid: z.boolean(),
|
||||
organizationInfo: z.object({
|
||||
id: z.number(),
|
||||
login: z.string(),
|
||||
name: z.string(),
|
||||
publicRepos: z.number().optional(),
|
||||
privateRepos: z.number().optional()
|
||||
}).optional()
|
||||
organizationInfo: z
|
||||
.object({
|
||||
id: z.number(),
|
||||
login: z.string(),
|
||||
name: z.string(),
|
||||
publicRepos: z.number().optional(),
|
||||
privateRepos: z.number().optional()
|
||||
})
|
||||
.optional()
|
||||
})
|
||||
}
|
||||
},
|
||||
|
||||
@@ -330,8 +330,8 @@ export const githubOrgSyncServiceFactory = ({
|
||||
const removeFromTeams = infisicalUserGroups.filter((el) => !githubUserTeamSet.has(el.groupName));
|
||||
|
||||
if (newTeams.length || updateTeams.length || removeFromTeams.length) {
|
||||
await groupDAL.transaction(async (tx) => {
|
||||
if (newTeams.length) {
|
||||
if (newTeams.length) {
|
||||
await groupDAL.transaction(async (tx) => {
|
||||
const newGroups = await groupDAL.insertMany(
|
||||
newTeams.map((newGroupName) => ({
|
||||
name: newGroupName,
|
||||
@@ -348,9 +348,11 @@ export const githubOrgSyncServiceFactory = ({
|
||||
})),
|
||||
tx
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (updateTeams.length) {
|
||||
if (updateTeams.length) {
|
||||
await groupDAL.transaction(async (tx) => {
|
||||
await userGroupMembershipDAL.insertMany(
|
||||
updateTeams.map((el) => ({
|
||||
groupId: githubUserTeamOnInfisicalGroupByName[el][0].id,
|
||||
@@ -358,15 +360,17 @@ export const githubOrgSyncServiceFactory = ({
|
||||
})),
|
||||
tx
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (removeFromTeams.length) {
|
||||
if (removeFromTeams.length) {
|
||||
await groupDAL.transaction(async (tx) => {
|
||||
await userGroupMembershipDAL.delete(
|
||||
{ userId, $in: { groupId: removeFromTeams.map((el) => el.groupId) } },
|
||||
tx
|
||||
);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -683,15 +687,15 @@ export const githubOrgSyncServiceFactory = ({
|
||||
const removeFromTeams = infisicalUserGroups.filter((el) => !githubUserTeamSet.has(el.groupName));
|
||||
|
||||
if (newTeams.length || updateTeams.length || removeFromTeams.length) {
|
||||
return await groupDAL.transaction(async (tx) => {
|
||||
const result = {
|
||||
createdTeams: [] as string[],
|
||||
updatedTeams: [] as string[],
|
||||
removedMemberships: 0
|
||||
};
|
||||
const result = {
|
||||
createdTeams: [] as string[],
|
||||
updatedTeams: [] as string[],
|
||||
removedMemberships: 0
|
||||
};
|
||||
|
||||
try {
|
||||
if (newTeams.length) {
|
||||
try {
|
||||
if (newTeams.length) {
|
||||
await groupDAL.transaction(async (tx) => {
|
||||
logger.info({ userId, githubUsername, newTeams, orgId }, "Creating new teams for user");
|
||||
|
||||
const newGroups = await groupDAL.insertMany(
|
||||
@@ -711,11 +715,13 @@ export const githubOrgSyncServiceFactory = ({
|
||||
})),
|
||||
tx
|
||||
);
|
||||
});
|
||||
|
||||
result.createdTeams = newTeams;
|
||||
}
|
||||
result.createdTeams = newTeams;
|
||||
}
|
||||
|
||||
if (updateTeams.length) {
|
||||
if (updateTeams.length) {
|
||||
await groupDAL.transaction(async (tx) => {
|
||||
logger.info({ userId, githubUsername, updateTeams, orgId }, "Adding user to existing teams");
|
||||
|
||||
await userGroupMembershipDAL.insertMany(
|
||||
@@ -725,11 +731,13 @@ export const githubOrgSyncServiceFactory = ({
|
||||
})),
|
||||
tx
|
||||
);
|
||||
});
|
||||
|
||||
result.updatedTeams = updateTeams;
|
||||
}
|
||||
result.updatedTeams = updateTeams;
|
||||
}
|
||||
|
||||
if (removeFromTeams.length) {
|
||||
if (removeFromTeams.length) {
|
||||
await groupDAL.transaction(async (tx) => {
|
||||
logger.info(
|
||||
{ userId, githubUsername, removeFromTeams: removeFromTeams.map((t) => t.groupName), orgId },
|
||||
"Removing user from teams"
|
||||
@@ -739,16 +747,16 @@ export const githubOrgSyncServiceFactory = ({
|
||||
{ userId, $in: { groupId: removeFromTeams.map((el) => el.groupId) } },
|
||||
tx
|
||||
);
|
||||
});
|
||||
|
||||
result.removedMemberships = removeFromTeams.length;
|
||||
}
|
||||
|
||||
return result;
|
||||
} catch (error) {
|
||||
logger.error(error, `Failed to update team memberships for user ${userId} (${githubUsername})`);
|
||||
throw error;
|
||||
result.removedMemberships = removeFromTeams.length;
|
||||
}
|
||||
});
|
||||
|
||||
return result;
|
||||
} catch (error) {
|
||||
logger.error(error, `Failed to update team memberships for user ${userId} (${githubUsername})`);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
@@ -130,7 +130,7 @@ export const OrgGithubSyncSection = () => {
|
||||
text: "Please enter a GitHub access token",
|
||||
type: "error"
|
||||
});
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
setIsValidatingToken(true);
|
||||
@@ -147,6 +147,8 @@ export const OrgGithubSyncSection = () => {
|
||||
type: "success"
|
||||
});
|
||||
}
|
||||
|
||||
return result.valid;
|
||||
} catch (error) {
|
||||
const errorMessage =
|
||||
(error as any)?.response?.data?.message ||
|
||||
@@ -157,6 +159,7 @@ export const OrgGithubSyncSection = () => {
|
||||
type: "error"
|
||||
});
|
||||
setTokenValidationResult({ valid: false });
|
||||
return false;
|
||||
} finally {
|
||||
setIsValidatingToken(false);
|
||||
}
|
||||
@@ -171,9 +174,10 @@ export const OrgGithubSyncSection = () => {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!tokenValidationResult?.valid) {
|
||||
await validateToken();
|
||||
if (!tokenValidationResult?.valid) {
|
||||
let isTokenValid = tokenValidationResult?.valid ?? false;
|
||||
if (!isTokenValid) {
|
||||
isTokenValid = await validateToken();
|
||||
if (!isTokenValid) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user