mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-15 08:34:52 +00:00
Complete trusted IPs feature
This commit is contained in:
@@ -17,3 +17,4 @@ export * from "./tags";
|
||||
export * from "./users";
|
||||
export * from "./webhooks";
|
||||
export * from "./workspace";
|
||||
export * from "./trustedIps";
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
||||
|
||||
import { apiRequest } from "@app/config/request";
|
||||
|
||||
import {
|
||||
|
||||
@@ -6,6 +6,7 @@ export type SubscriptionPlan = {
|
||||
customAlerts: boolean;
|
||||
customRateLimits: boolean;
|
||||
pitRecovery: boolean;
|
||||
ipAllowlisting: boolean;
|
||||
rbac: boolean;
|
||||
secretVersioning: boolean;
|
||||
slug: string;
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
export {
|
||||
useGetTrustedIps,
|
||||
useAddTrustedIp,
|
||||
useUpdateTrustedIp,
|
||||
useDeleteTrustedIp
|
||||
} from "./queries";
|
||||
@@ -0,0 +1,106 @@
|
||||
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
||||
import { apiRequest } from "@app/config/request";
|
||||
import {
|
||||
TrustedIp
|
||||
} from "./types";
|
||||
|
||||
const trustedIps = {
|
||||
getTrustedIps: (workspaceId: string) => [{ workspaceId }, "trusted-ips"] as const
|
||||
}
|
||||
|
||||
export const useGetTrustedIps = (workspaceId: string) => {
|
||||
return useQuery({
|
||||
queryKey: trustedIps.getTrustedIps(workspaceId),
|
||||
queryFn: async () => {
|
||||
const { data } = await apiRequest.get<{ trustedIps: TrustedIp[] }>(`/api/v1/workspace/${workspaceId}/trusted-ips`);
|
||||
|
||||
return data.trustedIps;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
export const useAddTrustedIp = () => {
|
||||
const queryClient = useQueryClient();
|
||||
return useMutation({
|
||||
mutationFn: async ({
|
||||
workspaceId,
|
||||
ipAddress,
|
||||
comment,
|
||||
isActive
|
||||
}: {
|
||||
workspaceId: string;
|
||||
ipAddress: string;
|
||||
comment?: string;
|
||||
isActive: boolean;
|
||||
}) => {
|
||||
const { data } = await apiRequest.post(
|
||||
`/api/v1/workspace/${workspaceId}/trusted-ips`,
|
||||
{
|
||||
ipAddress,
|
||||
...(comment ? { comment } : {}),
|
||||
isActive
|
||||
}
|
||||
);
|
||||
|
||||
return data;
|
||||
},
|
||||
onSuccess(_, dto) {
|
||||
queryClient.invalidateQueries(trustedIps.getTrustedIps(dto.workspaceId));
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
export const useUpdateTrustedIp = () => {
|
||||
const queryClient = useQueryClient();
|
||||
return useMutation({
|
||||
mutationFn: async ({
|
||||
workspaceId,
|
||||
trustedIpId,
|
||||
ipAddress,
|
||||
comment,
|
||||
isActive
|
||||
}: {
|
||||
workspaceId: string;
|
||||
trustedIpId: string;
|
||||
ipAddress: string;
|
||||
comment?: string;
|
||||
isActive: boolean;
|
||||
}) => {
|
||||
const { data } = await apiRequest.patch(
|
||||
`/api/v1/workspace/${workspaceId}/trusted-ips/${trustedIpId}`,
|
||||
{
|
||||
ipAddress,
|
||||
...(comment ? { comment } : {}),
|
||||
isActive
|
||||
}
|
||||
);
|
||||
|
||||
return data;
|
||||
},
|
||||
onSuccess(_, dto) {
|
||||
queryClient.invalidateQueries(trustedIps.getTrustedIps(dto.workspaceId));
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
export const useDeleteTrustedIp = () => {
|
||||
const queryClient = useQueryClient();
|
||||
return useMutation({
|
||||
mutationFn: async ({
|
||||
workspaceId,
|
||||
trustedIpId,
|
||||
}: {
|
||||
workspaceId: string;
|
||||
trustedIpId: string;
|
||||
}) => {
|
||||
const { data } = await apiRequest.delete(
|
||||
`/api/v1/workspace/${workspaceId}/trusted-ips/${trustedIpId}`
|
||||
);
|
||||
|
||||
return data;
|
||||
},
|
||||
onSuccess(_, dto) {
|
||||
queryClient.invalidateQueries(trustedIps.getTrustedIps(dto.workspaceId));
|
||||
}
|
||||
});
|
||||
};
|
||||
@@ -0,0 +1,9 @@
|
||||
export type TrustedIp = {
|
||||
_id: string;
|
||||
workspace: string;
|
||||
ipAddress: string;
|
||||
type: "ipv4" | "ipv6";
|
||||
isActive: boolean;
|
||||
comment: string;
|
||||
prefix?: number;
|
||||
};
|
||||
@@ -5,6 +5,7 @@ export {
|
||||
useCreateAPIKey,
|
||||
useDeleteAPIKey,
|
||||
useDeleteOrgMembership,
|
||||
useGetMyIp,
|
||||
useGetMyAPIKeys,
|
||||
useGetMySessions,
|
||||
useGetOrgUsers,
|
||||
|
||||
@@ -25,6 +25,7 @@ const userKeys = {
|
||||
getUser: ["user"] as const,
|
||||
userAction: ["user-action"] as const,
|
||||
getOrgUsers: (orgId: string) => [{ orgId }, "user"],
|
||||
myIp: ["ip"] as const,
|
||||
myAPIKeys: ["api-keys"] as const,
|
||||
mySessions: ["sessions"] as const
|
||||
};
|
||||
@@ -206,6 +207,19 @@ export const useLogoutUser = () =>
|
||||
}
|
||||
});
|
||||
|
||||
export const useGetMyIp = () => {
|
||||
return useQuery({
|
||||
queryKey: userKeys.myIp,
|
||||
queryFn: async () => {
|
||||
const { data } = await apiRequest.get<{ ip: string; }>(
|
||||
"/api/v1/users/me/ip"
|
||||
);
|
||||
return data.ip;
|
||||
},
|
||||
enabled: true
|
||||
});
|
||||
}
|
||||
|
||||
export const useGetMyAPIKeys = () => {
|
||||
return useQuery({
|
||||
queryKey: userKeys.myAPIKeys,
|
||||
|
||||
Reference in New Issue
Block a user