mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-07 12:27:28 +00:00
feat: moved trusted ips anmd assume privilege to new /projects
This commit is contained in:
@@ -52,8 +52,6 @@ export const registerV1EERoutes = async (server: FastifyZodProvider) => {
|
|||||||
async (projectRouter) => {
|
async (projectRouter) => {
|
||||||
await projectRouter.register(registerDepreciatedProjectRoleRouter);
|
await projectRouter.register(registerDepreciatedProjectRoleRouter);
|
||||||
await projectRouter.register(registerProjectRouter);
|
await projectRouter.register(registerProjectRouter);
|
||||||
await projectRouter.register(registerTrustedIpRouter);
|
|
||||||
await projectRouter.register(registerAssumePrivilegeRouter);
|
|
||||||
},
|
},
|
||||||
{ prefix: "/workspace" }
|
{ prefix: "/workspace" }
|
||||||
);
|
);
|
||||||
@@ -61,6 +59,8 @@ export const registerV1EERoutes = async (server: FastifyZodProvider) => {
|
|||||||
await server.register(
|
await server.register(
|
||||||
async (projectRouter) => {
|
async (projectRouter) => {
|
||||||
await projectRouter.register(registerProjectRoleRouter);
|
await projectRouter.register(registerProjectRoleRouter);
|
||||||
|
await projectRouter.register(registerTrustedIpRouter);
|
||||||
|
await projectRouter.register(registerAssumePrivilegeRouter);
|
||||||
},
|
},
|
||||||
{ prefix: "/projects" }
|
{ prefix: "/projects" }
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -9,13 +9,13 @@ import { AuthMode } from "@app/services/auth/auth-type";
|
|||||||
export const registerTrustedIpRouter = async (server: FastifyZodProvider) => {
|
export const registerTrustedIpRouter = async (server: FastifyZodProvider) => {
|
||||||
server.route({
|
server.route({
|
||||||
method: "GET",
|
method: "GET",
|
||||||
url: "/:workspaceId/trusted-ips",
|
url: "/:projectId/trusted-ips",
|
||||||
config: {
|
config: {
|
||||||
rateLimit: readLimit
|
rateLimit: readLimit
|
||||||
},
|
},
|
||||||
schema: {
|
schema: {
|
||||||
params: z.object({
|
params: z.object({
|
||||||
workspaceId: z.string().trim()
|
projectId: z.string().trim()
|
||||||
}),
|
}),
|
||||||
response: {
|
response: {
|
||||||
200: z.object({
|
200: z.object({
|
||||||
@@ -27,7 +27,7 @@ export const registerTrustedIpRouter = async (server: FastifyZodProvider) => {
|
|||||||
handler: async (req) => {
|
handler: async (req) => {
|
||||||
const trustedIps = await server.services.trustedIp.listIpsByProjectId({
|
const trustedIps = await server.services.trustedIp.listIpsByProjectId({
|
||||||
actorAuthMethod: req.permission.authMethod,
|
actorAuthMethod: req.permission.authMethod,
|
||||||
projectId: req.params.workspaceId,
|
projectId: req.params.projectId,
|
||||||
actor: req.permission.type,
|
actor: req.permission.type,
|
||||||
actorId: req.permission.id,
|
actorId: req.permission.id,
|
||||||
actorOrgId: req.permission.orgId
|
actorOrgId: req.permission.orgId
|
||||||
@@ -38,13 +38,13 @@ export const registerTrustedIpRouter = async (server: FastifyZodProvider) => {
|
|||||||
|
|
||||||
server.route({
|
server.route({
|
||||||
method: "POST",
|
method: "POST",
|
||||||
url: "/:workspaceId/trusted-ips",
|
url: "/:projectId/trusted-ips",
|
||||||
config: {
|
config: {
|
||||||
rateLimit: writeLimit
|
rateLimit: writeLimit
|
||||||
},
|
},
|
||||||
schema: {
|
schema: {
|
||||||
params: z.object({
|
params: z.object({
|
||||||
workspaceId: z.string().trim()
|
projectId: z.string().trim()
|
||||||
}),
|
}),
|
||||||
body: z.object({
|
body: z.object({
|
||||||
ipAddress: z.string().trim(),
|
ipAddress: z.string().trim(),
|
||||||
@@ -61,7 +61,7 @@ export const registerTrustedIpRouter = async (server: FastifyZodProvider) => {
|
|||||||
handler: async (req) => {
|
handler: async (req) => {
|
||||||
const { trustedIp, project } = await server.services.trustedIp.addProjectIp({
|
const { trustedIp, project } = await server.services.trustedIp.addProjectIp({
|
||||||
actorAuthMethod: req.permission.authMethod,
|
actorAuthMethod: req.permission.authMethod,
|
||||||
projectId: req.params.workspaceId,
|
projectId: req.params.projectId,
|
||||||
actor: req.permission.type,
|
actor: req.permission.type,
|
||||||
actorId: req.permission.id,
|
actorId: req.permission.id,
|
||||||
actorOrgId: req.permission.orgId,
|
actorOrgId: req.permission.orgId,
|
||||||
@@ -86,13 +86,13 @@ export const registerTrustedIpRouter = async (server: FastifyZodProvider) => {
|
|||||||
|
|
||||||
server.route({
|
server.route({
|
||||||
method: "PATCH",
|
method: "PATCH",
|
||||||
url: "/:workspaceId/trusted-ips/:trustedIpId",
|
url: "/:projectId/trusted-ips/:trustedIpId",
|
||||||
config: {
|
config: {
|
||||||
rateLimit: writeLimit
|
rateLimit: writeLimit
|
||||||
},
|
},
|
||||||
schema: {
|
schema: {
|
||||||
params: z.object({
|
params: z.object({
|
||||||
workspaceId: z.string().trim(),
|
projectId: z.string().trim(),
|
||||||
trustedIpId: z.string().trim()
|
trustedIpId: z.string().trim()
|
||||||
}),
|
}),
|
||||||
body: z.object({
|
body: z.object({
|
||||||
@@ -108,7 +108,7 @@ export const registerTrustedIpRouter = async (server: FastifyZodProvider) => {
|
|||||||
onRequest: verifyAuth([AuthMode.JWT]),
|
onRequest: verifyAuth([AuthMode.JWT]),
|
||||||
handler: async (req) => {
|
handler: async (req) => {
|
||||||
const { trustedIp, project } = await server.services.trustedIp.updateProjectIp({
|
const { trustedIp, project } = await server.services.trustedIp.updateProjectIp({
|
||||||
projectId: req.params.workspaceId,
|
projectId: req.params.projectId,
|
||||||
actor: req.permission.type,
|
actor: req.permission.type,
|
||||||
actorId: req.permission.id,
|
actorId: req.permission.id,
|
||||||
actorAuthMethod: req.permission.authMethod,
|
actorAuthMethod: req.permission.authMethod,
|
||||||
@@ -135,13 +135,13 @@ export const registerTrustedIpRouter = async (server: FastifyZodProvider) => {
|
|||||||
|
|
||||||
server.route({
|
server.route({
|
||||||
method: "DELETE",
|
method: "DELETE",
|
||||||
url: "/:workspaceId/trusted-ips/:trustedIpId",
|
url: "/:projectId/trusted-ips/:trustedIpId",
|
||||||
config: {
|
config: {
|
||||||
rateLimit: writeLimit
|
rateLimit: writeLimit
|
||||||
},
|
},
|
||||||
schema: {
|
schema: {
|
||||||
params: z.object({
|
params: z.object({
|
||||||
workspaceId: z.string().trim(),
|
projectId: z.string().trim(),
|
||||||
trustedIpId: z.string().trim()
|
trustedIpId: z.string().trim()
|
||||||
}),
|
}),
|
||||||
response: {
|
response: {
|
||||||
@@ -153,7 +153,7 @@ export const registerTrustedIpRouter = async (server: FastifyZodProvider) => {
|
|||||||
onRequest: verifyAuth([AuthMode.JWT]),
|
onRequest: verifyAuth([AuthMode.JWT]),
|
||||||
handler: async (req) => {
|
handler: async (req) => {
|
||||||
const { trustedIp, project } = await server.services.trustedIp.deleteProjectIp({
|
const { trustedIp, project } = await server.services.trustedIp.deleteProjectIp({
|
||||||
projectId: req.params.workspaceId,
|
projectId: req.params.projectId,
|
||||||
actor: req.permission.type,
|
actor: req.permission.type,
|
||||||
actorId: req.permission.id,
|
actorId: req.permission.id,
|
||||||
actorAuthMethod: req.permission.authMethod,
|
actorAuthMethod: req.permission.authMethod,
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ export const useAssumeProjectPrivileges = () =>
|
|||||||
useMutation({
|
useMutation({
|
||||||
mutationFn: async ({ projectId, actorId, actorType }: TProjectAssumePrivilegesDTO) => {
|
mutationFn: async ({ projectId, actorId, actorType }: TProjectAssumePrivilegesDTO) => {
|
||||||
const { data } = await apiRequest.post<{ message: string }>(
|
const { data } = await apiRequest.post<{ message: string }>(
|
||||||
`/api/v1/workspace/${projectId}/assume-privileges`,
|
`/api/v1/projects/${projectId}/assume-privileges`,
|
||||||
{ actorId, actorType }
|
{ actorId, actorType }
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -20,7 +20,7 @@ export const useRemoveAssumeProjectPrivilege = () =>
|
|||||||
useMutation({
|
useMutation({
|
||||||
mutationFn: async ({ projectId }: { projectId: string }) => {
|
mutationFn: async ({ projectId }: { projectId: string }) => {
|
||||||
const { data } = await apiRequest.delete<{ message: string }>(
|
const { data } = await apiRequest.delete<{ message: string }>(
|
||||||
`/api/v1/workspace/${projectId}/assume-privileges`
|
`/api/v1/projects/${projectId}/assume-privileges`
|
||||||
);
|
);
|
||||||
|
|
||||||
return data;
|
return data;
|
||||||
|
|||||||
@@ -5,15 +5,15 @@ import { apiRequest } from "@app/config/request";
|
|||||||
import { TrustedIp } from "./types";
|
import { TrustedIp } from "./types";
|
||||||
|
|
||||||
const trustedIps = {
|
const trustedIps = {
|
||||||
getTrustedIps: (workspaceId: string) => [{ workspaceId }, "trusted-ips"] as const
|
getTrustedIps: (projectId: string) => [{ projectId }, "trusted-ips"] as const
|
||||||
};
|
};
|
||||||
|
|
||||||
export const useGetTrustedIps = (workspaceId: string) => {
|
export const useGetTrustedIps = (projectId: string) => {
|
||||||
return useQuery({
|
return useQuery({
|
||||||
queryKey: trustedIps.getTrustedIps(workspaceId),
|
queryKey: trustedIps.getTrustedIps(projectId),
|
||||||
queryFn: async () => {
|
queryFn: async () => {
|
||||||
const { data } = await apiRequest.get<{ trustedIps: TrustedIp[] }>(
|
const { data } = await apiRequest.get<{ trustedIps: TrustedIp[] }>(
|
||||||
`/api/v1/workspace/${workspaceId}/trusted-ips`
|
`/api/v1/projects/${projectId}/trusted-ips`
|
||||||
);
|
);
|
||||||
|
|
||||||
return data.trustedIps;
|
return data.trustedIps;
|
||||||
@@ -25,17 +25,17 @@ export const useAddTrustedIp = () => {
|
|||||||
const queryClient = useQueryClient();
|
const queryClient = useQueryClient();
|
||||||
return useMutation({
|
return useMutation({
|
||||||
mutationFn: async ({
|
mutationFn: async ({
|
||||||
workspaceId,
|
projectId,
|
||||||
ipAddress,
|
ipAddress,
|
||||||
comment,
|
comment,
|
||||||
isActive
|
isActive
|
||||||
}: {
|
}: {
|
||||||
workspaceId: string;
|
projectId: string;
|
||||||
ipAddress: string;
|
ipAddress: string;
|
||||||
comment?: string;
|
comment?: string;
|
||||||
isActive: boolean;
|
isActive: boolean;
|
||||||
}) => {
|
}) => {
|
||||||
const { data } = await apiRequest.post(`/api/v1/workspace/${workspaceId}/trusted-ips`, {
|
const { data } = await apiRequest.post(`/api/v1/projects/${projectId}/trusted-ips`, {
|
||||||
ipAddress,
|
ipAddress,
|
||||||
...(comment ? { comment } : {}),
|
...(comment ? { comment } : {}),
|
||||||
isActive
|
isActive
|
||||||
@@ -44,7 +44,7 @@ export const useAddTrustedIp = () => {
|
|||||||
return data;
|
return data;
|
||||||
},
|
},
|
||||||
onSuccess(_, dto) {
|
onSuccess(_, dto) {
|
||||||
queryClient.invalidateQueries({ queryKey: trustedIps.getTrustedIps(dto.workspaceId) });
|
queryClient.invalidateQueries({ queryKey: trustedIps.getTrustedIps(dto.projectId) });
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
@@ -53,20 +53,20 @@ export const useUpdateTrustedIp = () => {
|
|||||||
const queryClient = useQueryClient();
|
const queryClient = useQueryClient();
|
||||||
return useMutation({
|
return useMutation({
|
||||||
mutationFn: async ({
|
mutationFn: async ({
|
||||||
workspaceId,
|
projectId,
|
||||||
trustedIpId,
|
trustedIpId,
|
||||||
ipAddress,
|
ipAddress,
|
||||||
comment,
|
comment,
|
||||||
isActive
|
isActive
|
||||||
}: {
|
}: {
|
||||||
workspaceId: string;
|
projectId: string;
|
||||||
trustedIpId: string;
|
trustedIpId: string;
|
||||||
ipAddress: string;
|
ipAddress: string;
|
||||||
comment?: string;
|
comment?: string;
|
||||||
isActive: boolean;
|
isActive: boolean;
|
||||||
}) => {
|
}) => {
|
||||||
const { data } = await apiRequest.patch(
|
const { data } = await apiRequest.patch(
|
||||||
`/api/v1/workspace/${workspaceId}/trusted-ips/${trustedIpId}`,
|
`/api/v1/projects/${projectId}/trusted-ips/${trustedIpId}`,
|
||||||
{
|
{
|
||||||
ipAddress,
|
ipAddress,
|
||||||
...(comment ? { comment } : {}),
|
...(comment ? { comment } : {}),
|
||||||
@@ -77,7 +77,7 @@ export const useUpdateTrustedIp = () => {
|
|||||||
return data;
|
return data;
|
||||||
},
|
},
|
||||||
onSuccess(_, dto) {
|
onSuccess(_, dto) {
|
||||||
queryClient.invalidateQueries({ queryKey: trustedIps.getTrustedIps(dto.workspaceId) });
|
queryClient.invalidateQueries({ queryKey: trustedIps.getTrustedIps(dto.projectId) });
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
@@ -85,21 +85,15 @@ export const useUpdateTrustedIp = () => {
|
|||||||
export const useDeleteTrustedIp = () => {
|
export const useDeleteTrustedIp = () => {
|
||||||
const queryClient = useQueryClient();
|
const queryClient = useQueryClient();
|
||||||
return useMutation({
|
return useMutation({
|
||||||
mutationFn: async ({
|
mutationFn: async ({ projectId, trustedIpId }: { projectId: string; trustedIpId: string }) => {
|
||||||
workspaceId,
|
|
||||||
trustedIpId
|
|
||||||
}: {
|
|
||||||
workspaceId: string;
|
|
||||||
trustedIpId: string;
|
|
||||||
}) => {
|
|
||||||
const { data } = await apiRequest.delete(
|
const { data } = await apiRequest.delete(
|
||||||
`/api/v1/workspace/${workspaceId}/trusted-ips/${trustedIpId}`
|
`/api/v1/projects/${projectId}/trusted-ips/${trustedIpId}`
|
||||||
);
|
);
|
||||||
|
|
||||||
return data;
|
return data;
|
||||||
},
|
},
|
||||||
onSuccess(_, dto) {
|
onSuccess(_, dto) {
|
||||||
queryClient.invalidateQueries({ queryKey: trustedIps.getTrustedIps(dto.workspaceId) });
|
queryClient.invalidateQueries({ queryKey: trustedIps.getTrustedIps(dto.projectId) });
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user