mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-07 13:27:46 +00:00
feat(infisical-pg): resolved missing integration auth api
This commit is contained in:
@@ -1,3 +1,2 @@
|
|||||||
.eslintrc.js
|
|
||||||
vitest-environment-infisical.ts
|
vitest-environment-infisical.ts
|
||||||
vitest.config.ts
|
vitest.config.ts
|
||||||
|
|||||||
@@ -59,6 +59,44 @@ export const registerIntegrationAuthRouter = async (server: FastifyZodProvider)
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
server.route({
|
||||||
|
url: "/",
|
||||||
|
method: "DELETE",
|
||||||
|
onRequest: verifyAuth([AuthMode.JWT]),
|
||||||
|
schema: {
|
||||||
|
querystring: z.object({
|
||||||
|
integration: z.string().trim(),
|
||||||
|
projectId: z.string().trim()
|
||||||
|
}),
|
||||||
|
response: {
|
||||||
|
200: z.object({
|
||||||
|
integrationAuth: integrationAuthPubSchema.array()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
},
|
||||||
|
handler: async (req) => {
|
||||||
|
const integrationAuth = await server.services.integrationAuth.deleteIntegrationAuths({
|
||||||
|
actorId: req.permission.id,
|
||||||
|
actor: req.permission.type,
|
||||||
|
integration: req.query.integration,
|
||||||
|
projectId: req.query.projectId
|
||||||
|
});
|
||||||
|
|
||||||
|
await server.services.auditLog.createAuditLog({
|
||||||
|
...req.auditLogInfo,
|
||||||
|
projectId: req.query.projectId,
|
||||||
|
event: {
|
||||||
|
type: EventType.UNAUTHORIZE_INTEGRATION,
|
||||||
|
metadata: {
|
||||||
|
integration: req.query.integration
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return { integrationAuth };
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
server.route({
|
server.route({
|
||||||
url: "/:integrationAuthId",
|
url: "/:integrationAuthId",
|
||||||
method: "DELETE",
|
method: "DELETE",
|
||||||
@@ -74,7 +112,7 @@ export const registerIntegrationAuthRouter = async (server: FastifyZodProvider)
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
handler: async (req) => {
|
handler: async (req) => {
|
||||||
const integrationAuth = await server.services.integrationAuth.deleteIntegrationAuth({
|
const integrationAuth = await server.services.integrationAuth.deleteIntegrationAuthById({
|
||||||
actorId: req.permission.id,
|
actorId: req.permission.id,
|
||||||
actor: req.permission.type,
|
actor: req.permission.type,
|
||||||
id: req.params.integrationAuthId
|
id: req.params.integrationAuthId
|
||||||
|
|||||||
@@ -155,7 +155,7 @@ export const registerSecretRouter = async (server: FastifyZodProvider) => {
|
|||||||
event: {
|
event: {
|
||||||
type: EventType.GET_SECRET,
|
type: EventType.GET_SECRET,
|
||||||
metadata: {
|
metadata: {
|
||||||
environment: req.query.environment,
|
environment,
|
||||||
secretPath: req.query.secretPath,
|
secretPath: req.query.secretPath,
|
||||||
secretId: secret.id,
|
secretId: secret.id,
|
||||||
secretKey: req.params.secretName,
|
secretKey: req.params.secretName,
|
||||||
|
|||||||
@@ -27,7 +27,8 @@ import { TIntegrationAuthDalFactory } from "./integration-auth-dal";
|
|||||||
import {
|
import {
|
||||||
TBitbucketWorkspace,
|
TBitbucketWorkspace,
|
||||||
TChecklyGroups,
|
TChecklyGroups,
|
||||||
TDeleteIntegrationAuthDTO,
|
TDeleteIntegrationAuthByIdDTO,
|
||||||
|
TDeleteIntegrationAuthsDTO,
|
||||||
TGetIntegrationAuthDTO,
|
TGetIntegrationAuthDTO,
|
||||||
TGetIntegrationAuthTeamCityBuildConfigDTO,
|
TGetIntegrationAuthTeamCityBuildConfigDTO,
|
||||||
TIntegrationAuthAppsDTO,
|
TIntegrationAuthAppsDTO,
|
||||||
@@ -966,7 +967,27 @@ export const integrationAuthServiceFactory = ({
|
|||||||
return [];
|
return [];
|
||||||
};
|
};
|
||||||
|
|
||||||
const deleteIntegrationAuth = async ({ id, actorId, actor }: TDeleteIntegrationAuthDTO) => {
|
const deleteIntegrationAuths = async ({
|
||||||
|
projectId,
|
||||||
|
integration,
|
||||||
|
actor,
|
||||||
|
actorId
|
||||||
|
}: TDeleteIntegrationAuthsDTO) => {
|
||||||
|
const { permission } = await permissionService.getProjectPermission(actor, actorId, projectId);
|
||||||
|
ForbiddenError.from(permission).throwUnlessCan(
|
||||||
|
ProjectPermissionActions.Delete,
|
||||||
|
ProjectPermissionSub.Integrations
|
||||||
|
);
|
||||||
|
|
||||||
|
const integrations = await integrationAuthDal.delete({ integration, projectId });
|
||||||
|
return integrations;
|
||||||
|
};
|
||||||
|
|
||||||
|
const deleteIntegrationAuthById = async ({
|
||||||
|
id,
|
||||||
|
actorId,
|
||||||
|
actor
|
||||||
|
}: TDeleteIntegrationAuthByIdDTO) => {
|
||||||
const integrationAuth = await integrationAuthDal.findById(id);
|
const integrationAuth = await integrationAuthDal.findById(id);
|
||||||
if (!integrationAuth) throw new BadRequestError({ message: "Failed to find integration" });
|
if (!integrationAuth) throw new BadRequestError({ message: "Failed to find integration" });
|
||||||
|
|
||||||
@@ -996,7 +1017,8 @@ export const integrationAuthServiceFactory = ({
|
|||||||
getIntegrationAuth,
|
getIntegrationAuth,
|
||||||
oauthExchange,
|
oauthExchange,
|
||||||
saveIntegrationToken,
|
saveIntegrationToken,
|
||||||
deleteIntegrationAuth,
|
deleteIntegrationAuthById,
|
||||||
|
deleteIntegrationAuths,
|
||||||
getIntegrationAuthTeams,
|
getIntegrationAuthTeams,
|
||||||
getIntegrationApps,
|
getIntegrationApps,
|
||||||
getVercelBranches,
|
getVercelBranches,
|
||||||
|
|||||||
@@ -19,6 +19,11 @@ export type TSaveIntegrationAccessTokenDTO = {
|
|||||||
refreshToken?: string;
|
refreshToken?: string;
|
||||||
} & TProjectPermission;
|
} & TProjectPermission;
|
||||||
|
|
||||||
|
export type TDeleteIntegrationAuthsDTO = TProjectPermission & {
|
||||||
|
integration: string;
|
||||||
|
projectId: string;
|
||||||
|
};
|
||||||
|
|
||||||
export type TIntegrationAuthAppsDTO = {
|
export type TIntegrationAuthAppsDTO = {
|
||||||
id: string;
|
id: string;
|
||||||
teamId?: string;
|
teamId?: string;
|
||||||
@@ -76,7 +81,7 @@ export type TIntegrationAuthNorthflankSecretGroupDTO = {
|
|||||||
appId: string;
|
appId: string;
|
||||||
} & Omit<TProjectPermission, "projectId">;
|
} & Omit<TProjectPermission, "projectId">;
|
||||||
|
|
||||||
export type TDeleteIntegrationAuthDTO = {
|
export type TDeleteIntegrationAuthByIdDTO = {
|
||||||
id: string;
|
id: string;
|
||||||
} & Omit<TProjectPermission, "projectId">;
|
} & Omit<TProjectPermission, "projectId">;
|
||||||
|
|
||||||
|
|||||||
@@ -37,10 +37,9 @@ const integrationAuthKeys = {
|
|||||||
}: {
|
}: {
|
||||||
integrationAuthId: string;
|
integrationAuthId: string;
|
||||||
accountId: string;
|
accountId: string;
|
||||||
}) =>
|
}) => [{ integrationAuthId, accountId }, "integrationAuthChecklyGroups"] as const,
|
||||||
[{ integrationAuthId, accountId }, "integrationAuthChecklyGroups"] as const,
|
|
||||||
getIntegrationAuthQoveryOrgs: (integrationAuthId: string) =>
|
getIntegrationAuthQoveryOrgs: (integrationAuthId: string) =>
|
||||||
[{ integrationAuthId }, "integrationAuthQoveryOrgs"] as const,
|
[{ integrationAuthId }, "integrationAuthQoveryOrgs"] as const,
|
||||||
getIntegrationAuthQoveryProjects: ({
|
getIntegrationAuthQoveryProjects: ({
|
||||||
integrationAuthId,
|
integrationAuthId,
|
||||||
orgId
|
orgId
|
||||||
@@ -93,7 +92,7 @@ const integrationAuthKeys = {
|
|||||||
}: {
|
}: {
|
||||||
integrationAuthId: string;
|
integrationAuthId: string;
|
||||||
appId: string;
|
appId: string;
|
||||||
}) => [{ integrationAuthId, appId }, "integrationAuthTeamCityBranchConfigs"] as const,
|
}) => [{ integrationAuthId, appId }, "integrationAuthTeamCityBranchConfigs"] as const
|
||||||
};
|
};
|
||||||
|
|
||||||
const fetchIntegrationAuthById = async (integrationAuthId: string) => {
|
const fetchIntegrationAuthById = async (integrationAuthId: string) => {
|
||||||
@@ -112,12 +111,12 @@ const fetchIntegrationAuthApps = async ({
|
|||||||
teamId?: string;
|
teamId?: string;
|
||||||
workspaceSlug?: string;
|
workspaceSlug?: string;
|
||||||
}) => {
|
}) => {
|
||||||
const params: Record<string, string> = {}
|
const params: Record<string, string> = {};
|
||||||
if (teamId) {
|
if (teamId) {
|
||||||
params.teamId = teamId
|
params.teamId = teamId;
|
||||||
}
|
}
|
||||||
if (workspaceSlug) {
|
if (workspaceSlug) {
|
||||||
params.workspaceSlug = workspaceSlug
|
params.workspaceSlug = workspaceSlug;
|
||||||
}
|
}
|
||||||
|
|
||||||
const searchParams = new URLSearchParams(params);
|
const searchParams = new URLSearchParams(params);
|
||||||
@@ -335,7 +334,9 @@ const fetchIntegrationAuthRailwayServices = async ({
|
|||||||
};
|
};
|
||||||
|
|
||||||
const fetchIntegrationAuthBitBucketWorkspaces = async (integrationAuthId: string) => {
|
const fetchIntegrationAuthBitBucketWorkspaces = async (integrationAuthId: string) => {
|
||||||
const { data: { workspaces } } = await apiRequest.get<{ workspaces: BitBucketWorkspace[] }>(
|
const {
|
||||||
|
data: { workspaces }
|
||||||
|
} = await apiRequest.get<{ workspaces: BitBucketWorkspace[] }>(
|
||||||
`/api/v1/integration-auth/${integrationAuthId}/bitbucket/workspaces`
|
`/api/v1/integration-auth/${integrationAuthId}/bitbucket/workspaces`
|
||||||
);
|
);
|
||||||
return workspaces;
|
return workspaces;
|
||||||
@@ -396,7 +397,7 @@ export const useGetIntegrationAuthById = (integrationAuthId: string) => {
|
|||||||
export const useGetIntegrationAuthApps = ({
|
export const useGetIntegrationAuthApps = ({
|
||||||
integrationAuthId,
|
integrationAuthId,
|
||||||
teamId,
|
teamId,
|
||||||
workspaceSlug,
|
workspaceSlug
|
||||||
}: {
|
}: {
|
||||||
integrationAuthId: string;
|
integrationAuthId: string;
|
||||||
teamId?: string;
|
teamId?: string;
|
||||||
@@ -455,10 +456,11 @@ export const useGetIntegrationAuthChecklyGroups = ({
|
|||||||
integrationAuthId,
|
integrationAuthId,
|
||||||
accountId
|
accountId
|
||||||
}),
|
}),
|
||||||
queryFn: () => fetchIntegrationAuthChecklyGroups({
|
queryFn: () =>
|
||||||
integrationAuthId,
|
fetchIntegrationAuthChecklyGroups({
|
||||||
accountId
|
integrationAuthId,
|
||||||
}),
|
accountId
|
||||||
|
}),
|
||||||
enabled: true
|
enabled: true
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
@@ -466,8 +468,7 @@ export const useGetIntegrationAuthChecklyGroups = ({
|
|||||||
export const useGetIntegrationAuthQoveryOrgs = (integrationAuthId: string) => {
|
export const useGetIntegrationAuthQoveryOrgs = (integrationAuthId: string) => {
|
||||||
return useQuery({
|
return useQuery({
|
||||||
queryKey: integrationAuthKeys.getIntegrationAuthQoveryOrgs(integrationAuthId),
|
queryKey: integrationAuthKeys.getIntegrationAuthQoveryOrgs(integrationAuthId),
|
||||||
queryFn: () =>
|
queryFn: () => fetchIntegrationAuthQoveryOrgs(integrationAuthId),
|
||||||
fetchIntegrationAuthQoveryOrgs(integrationAuthId),
|
|
||||||
enabled: true
|
enabled: true
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
@@ -622,10 +623,11 @@ export const useGetIntegrationAuthTeamCityBuildConfigs = ({
|
|||||||
integrationAuthId,
|
integrationAuthId,
|
||||||
appId
|
appId
|
||||||
}),
|
}),
|
||||||
queryFn: () => fetchIntegrationAuthTeamCityBuildConfigs({
|
queryFn: () =>
|
||||||
integrationAuthId,
|
fetchIntegrationAuthTeamCityBuildConfigs({
|
||||||
appId
|
integrationAuthId,
|
||||||
}),
|
appId
|
||||||
|
}),
|
||||||
enabled: true
|
enabled: true
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
@@ -645,7 +647,9 @@ export const useAuthorizeIntegration = () => {
|
|||||||
integration: string;
|
integration: string;
|
||||||
url?: string;
|
url?: string;
|
||||||
}) => {
|
}) => {
|
||||||
const { data: { integrationAuth } } = await apiRequest.post("/api/v1/integration-auth/oauth-token", {
|
const {
|
||||||
|
data: { integrationAuth }
|
||||||
|
} = await apiRequest.post("/api/v1/integration-auth/oauth-token", {
|
||||||
workspaceId,
|
workspaceId,
|
||||||
code,
|
code,
|
||||||
integration,
|
integration,
|
||||||
@@ -681,7 +685,9 @@ export const useSaveIntegrationAccessToken = () => {
|
|||||||
url?: string;
|
url?: string;
|
||||||
namespace?: string;
|
namespace?: string;
|
||||||
}) => {
|
}) => {
|
||||||
const { data: { integrationAuth } } = await apiRequest.post("/api/v1/integration-auth/access-token", {
|
const {
|
||||||
|
data: { integrationAuth }
|
||||||
|
} = await apiRequest.post("/api/v1/integration-auth/access-token", {
|
||||||
workspaceId,
|
workspaceId,
|
||||||
integration,
|
integration,
|
||||||
refreshToken,
|
refreshToken,
|
||||||
@@ -703,10 +709,13 @@ export const useDeleteIntegrationAuths = () => {
|
|||||||
const queryClient = useQueryClient();
|
const queryClient = useQueryClient();
|
||||||
|
|
||||||
return useMutation<{}, {}, { integration: string; workspaceId: string }>({
|
return useMutation<{}, {}, { integration: string; workspaceId: string }>({
|
||||||
mutationFn: ({ integration, workspaceId }) => apiRequest.delete(`/api/v1/integration-auth?${new URLSearchParams({
|
mutationFn: ({ integration, workspaceId }) =>
|
||||||
integration,
|
apiRequest.delete(
|
||||||
workspaceId
|
`/api/v1/integration-auth?${new URLSearchParams({
|
||||||
})}`),
|
integration,
|
||||||
|
projectId: workspaceId
|
||||||
|
})}`
|
||||||
|
),
|
||||||
onSuccess: (_, { workspaceId }) => {
|
onSuccess: (_, { workspaceId }) => {
|
||||||
queryClient.invalidateQueries(workspaceKeys.getWorkspaceAuthorization(workspaceId));
|
queryClient.invalidateQueries(workspaceKeys.getWorkspaceAuthorization(workspaceId));
|
||||||
queryClient.invalidateQueries(workspaceKeys.getWorkspaceIntegrations(workspaceId));
|
queryClient.invalidateQueries(workspaceKeys.getWorkspaceIntegrations(workspaceId));
|
||||||
@@ -714,7 +723,8 @@ export const useDeleteIntegrationAuths = () => {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
export const useDeleteIntegrationAuth = () => { // not used
|
export const useDeleteIntegrationAuth = () => {
|
||||||
|
// not used
|
||||||
const queryClient = useQueryClient();
|
const queryClient = useQueryClient();
|
||||||
|
|
||||||
return useMutation<{}, {}, { id: string; workspaceId: string }>({
|
return useMutation<{}, {}, { id: string; workspaceId: string }>({
|
||||||
@@ -725,4 +735,3 @@ export const useDeleteIntegrationAuth = () => { // not used
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user