mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-07 05:27:48 +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]),
|
onRequest: verifyAuth([AuthMode.JWT]),
|
||||||
schema: {
|
schema: {
|
||||||
body: z.object({
|
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: {
|
response: {
|
||||||
200: z.object({
|
200: z.object({
|
||||||
valid: z.boolean(),
|
valid: z.boolean(),
|
||||||
organizationInfo: z.object({
|
organizationInfo: z
|
||||||
|
.object({
|
||||||
id: z.number(),
|
id: z.number(),
|
||||||
login: z.string(),
|
login: z.string(),
|
||||||
name: z.string(),
|
name: z.string(),
|
||||||
publicRepos: z.number().optional(),
|
publicRepos: z.number().optional(),
|
||||||
privateRepos: z.number().optional()
|
privateRepos: z.number().optional()
|
||||||
}).optional()
|
})
|
||||||
|
.optional()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -330,8 +330,8 @@ export const githubOrgSyncServiceFactory = ({
|
|||||||
const removeFromTeams = infisicalUserGroups.filter((el) => !githubUserTeamSet.has(el.groupName));
|
const removeFromTeams = infisicalUserGroups.filter((el) => !githubUserTeamSet.has(el.groupName));
|
||||||
|
|
||||||
if (newTeams.length || updateTeams.length || removeFromTeams.length) {
|
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(
|
const newGroups = await groupDAL.insertMany(
|
||||||
newTeams.map((newGroupName) => ({
|
newTeams.map((newGroupName) => ({
|
||||||
name: newGroupName,
|
name: newGroupName,
|
||||||
@@ -348,9 +348,11 @@ export const githubOrgSyncServiceFactory = ({
|
|||||||
})),
|
})),
|
||||||
tx
|
tx
|
||||||
);
|
);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (updateTeams.length) {
|
if (updateTeams.length) {
|
||||||
|
await groupDAL.transaction(async (tx) => {
|
||||||
await userGroupMembershipDAL.insertMany(
|
await userGroupMembershipDAL.insertMany(
|
||||||
updateTeams.map((el) => ({
|
updateTeams.map((el) => ({
|
||||||
groupId: githubUserTeamOnInfisicalGroupByName[el][0].id,
|
groupId: githubUserTeamOnInfisicalGroupByName[el][0].id,
|
||||||
@@ -358,16 +360,18 @@ export const githubOrgSyncServiceFactory = ({
|
|||||||
})),
|
})),
|
||||||
tx
|
tx
|
||||||
);
|
);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (removeFromTeams.length) {
|
if (removeFromTeams.length) {
|
||||||
|
await groupDAL.transaction(async (tx) => {
|
||||||
await userGroupMembershipDAL.delete(
|
await userGroupMembershipDAL.delete(
|
||||||
{ userId, $in: { groupId: removeFromTeams.map((el) => el.groupId) } },
|
{ userId, $in: { groupId: removeFromTeams.map((el) => el.groupId) } },
|
||||||
tx
|
tx
|
||||||
);
|
);
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const validateGithubToken = async ({ orgPermission, githubOrgAccessToken }: TValidateGithubTokenDTO) => {
|
const validateGithubToken = async ({ orgPermission, githubOrgAccessToken }: TValidateGithubTokenDTO) => {
|
||||||
@@ -683,7 +687,6 @@ export const githubOrgSyncServiceFactory = ({
|
|||||||
const removeFromTeams = infisicalUserGroups.filter((el) => !githubUserTeamSet.has(el.groupName));
|
const removeFromTeams = infisicalUserGroups.filter((el) => !githubUserTeamSet.has(el.groupName));
|
||||||
|
|
||||||
if (newTeams.length || updateTeams.length || removeFromTeams.length) {
|
if (newTeams.length || updateTeams.length || removeFromTeams.length) {
|
||||||
return await groupDAL.transaction(async (tx) => {
|
|
||||||
const result = {
|
const result = {
|
||||||
createdTeams: [] as string[],
|
createdTeams: [] as string[],
|
||||||
updatedTeams: [] as string[],
|
updatedTeams: [] as string[],
|
||||||
@@ -692,6 +695,7 @@ export const githubOrgSyncServiceFactory = ({
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
if (newTeams.length) {
|
if (newTeams.length) {
|
||||||
|
await groupDAL.transaction(async (tx) => {
|
||||||
logger.info({ userId, githubUsername, newTeams, orgId }, "Creating new teams for user");
|
logger.info({ userId, githubUsername, newTeams, orgId }, "Creating new teams for user");
|
||||||
|
|
||||||
const newGroups = await groupDAL.insertMany(
|
const newGroups = await groupDAL.insertMany(
|
||||||
@@ -711,11 +715,13 @@ export const githubOrgSyncServiceFactory = ({
|
|||||||
})),
|
})),
|
||||||
tx
|
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");
|
logger.info({ userId, githubUsername, updateTeams, orgId }, "Adding user to existing teams");
|
||||||
|
|
||||||
await userGroupMembershipDAL.insertMany(
|
await userGroupMembershipDAL.insertMany(
|
||||||
@@ -725,11 +731,13 @@ export const githubOrgSyncServiceFactory = ({
|
|||||||
})),
|
})),
|
||||||
tx
|
tx
|
||||||
);
|
);
|
||||||
|
});
|
||||||
|
|
||||||
result.updatedTeams = updateTeams;
|
result.updatedTeams = updateTeams;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (removeFromTeams.length) {
|
if (removeFromTeams.length) {
|
||||||
|
await groupDAL.transaction(async (tx) => {
|
||||||
logger.info(
|
logger.info(
|
||||||
{ userId, githubUsername, removeFromTeams: removeFromTeams.map((t) => t.groupName), orgId },
|
{ userId, githubUsername, removeFromTeams: removeFromTeams.map((t) => t.groupName), orgId },
|
||||||
"Removing user from teams"
|
"Removing user from teams"
|
||||||
@@ -739,6 +747,7 @@ export const githubOrgSyncServiceFactory = ({
|
|||||||
{ userId, $in: { groupId: removeFromTeams.map((el) => el.groupId) } },
|
{ userId, $in: { groupId: removeFromTeams.map((el) => el.groupId) } },
|
||||||
tx
|
tx
|
||||||
);
|
);
|
||||||
|
});
|
||||||
|
|
||||||
result.removedMemberships = removeFromTeams.length;
|
result.removedMemberships = removeFromTeams.length;
|
||||||
}
|
}
|
||||||
@@ -748,7 +757,6 @@ export const githubOrgSyncServiceFactory = ({
|
|||||||
logger.error(error, `Failed to update team memberships for user ${userId} (${githubUsername})`);
|
logger.error(error, `Failed to update team memberships for user ${userId} (${githubUsername})`);
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
+8
-4
@@ -130,7 +130,7 @@ export const OrgGithubSyncSection = () => {
|
|||||||
text: "Please enter a GitHub access token",
|
text: "Please enter a GitHub access token",
|
||||||
type: "error"
|
type: "error"
|
||||||
});
|
});
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
setIsValidatingToken(true);
|
setIsValidatingToken(true);
|
||||||
@@ -147,6 +147,8 @@ export const OrgGithubSyncSection = () => {
|
|||||||
type: "success"
|
type: "success"
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return result.valid;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
const errorMessage =
|
const errorMessage =
|
||||||
(error as any)?.response?.data?.message ||
|
(error as any)?.response?.data?.message ||
|
||||||
@@ -157,6 +159,7 @@ export const OrgGithubSyncSection = () => {
|
|||||||
type: "error"
|
type: "error"
|
||||||
});
|
});
|
||||||
setTokenValidationResult({ valid: false });
|
setTokenValidationResult({ valid: false });
|
||||||
|
return false;
|
||||||
} finally {
|
} finally {
|
||||||
setIsValidatingToken(false);
|
setIsValidatingToken(false);
|
||||||
}
|
}
|
||||||
@@ -171,9 +174,10 @@ export const OrgGithubSyncSection = () => {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!tokenValidationResult?.valid) {
|
let isTokenValid = tokenValidationResult?.valid ?? false;
|
||||||
await validateToken();
|
if (!isTokenValid) {
|
||||||
if (!tokenValidationResult?.valid) {
|
isTokenValid = await validateToken();
|
||||||
|
if (!isTokenValid) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user