mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-15 21:40:31 +00:00
Finish basic scaffolding for service token v3
This commit is contained in:
@@ -1 +1,8 @@
|
||||
export { useCreateServiceToken, useDeleteServiceToken, useGetUserWsServiceTokens } from "./queries";
|
||||
export {
|
||||
useCreateServiceToken,
|
||||
useDeleteServiceToken,
|
||||
useGetUserWsServiceTokens,
|
||||
useCreateServiceTokenV3,
|
||||
useUpdateServiceTokenV3,
|
||||
useDeleteServiceTokenV3
|
||||
} from "./queries";
|
||||
|
||||
@@ -6,8 +6,14 @@ import {
|
||||
CreateServiceTokenDTO,
|
||||
CreateServiceTokenRes,
|
||||
DeleteServiceTokenRes,
|
||||
ServiceToken
|
||||
ServiceToken,
|
||||
ServiceTokenDataV3,
|
||||
CreateServiceTokenDataV3DTO,
|
||||
CreateServiceTokenDataV3Res,
|
||||
UpdateServiceTokenDataV3DTO,
|
||||
DeleteServiceTokenDataV3DTO
|
||||
} from "./types";
|
||||
import { workspaceKeys } from "../workspace/queries";
|
||||
|
||||
const serviceTokenKeys = {
|
||||
getAllWorkspaceServiceToken: (workspaceID: string) => [{ workspaceID }, "service-tokens"] as const
|
||||
@@ -32,12 +38,11 @@ export const useGetUserWsServiceTokens = ({ workspaceID }: UseGetWorkspaceServic
|
||||
}
|
||||
|
||||
// mutation
|
||||
export const useCreateServiceToken = () => {
|
||||
export const useCreateServiceToken = () => { // TODO: deprecate
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
return useMutation<CreateServiceTokenRes, {}, CreateServiceTokenDTO>({
|
||||
mutationFn: async (body) => {
|
||||
console.log("useCreateServiceToken");
|
||||
const { data } = await apiRequest.post("/api/v2/service-token/", body);
|
||||
data.serviceToken += `.${body.randomBytes}`;
|
||||
return data;
|
||||
@@ -62,3 +67,55 @@ export const useDeleteServiceToken = () => {
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
export const useCreateServiceTokenV3 = () => {
|
||||
const queryClient = useQueryClient();
|
||||
return useMutation<CreateServiceTokenDataV3Res, {}, CreateServiceTokenDataV3DTO>({
|
||||
mutationFn: async (body) => {
|
||||
const { data } = await apiRequest.post("/api/v3/service-token/", body);
|
||||
return data;
|
||||
},
|
||||
onSuccess: ({ serviceTokenData }) => {
|
||||
queryClient.invalidateQueries(workspaceKeys.getWorkspaceServiceTokenDataV3(serviceTokenData.workspace));
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
export const useUpdateServiceTokenV3 = () => {
|
||||
const queryClient = useQueryClient();
|
||||
return useMutation<ServiceTokenDataV3, {}, UpdateServiceTokenDataV3DTO>({
|
||||
mutationFn: async ({
|
||||
serviceTokenDataId,
|
||||
name,
|
||||
isActive
|
||||
}) => {
|
||||
const { data: { serviceTokenData } } = await apiRequest.patch(`/api/v3/service-token/${serviceTokenDataId}`, {
|
||||
name,
|
||||
isActive
|
||||
});
|
||||
|
||||
return serviceTokenData;
|
||||
},
|
||||
onSuccess: ({ workspace }) => {
|
||||
queryClient.invalidateQueries(workspaceKeys.getWorkspaceServiceTokenDataV3(workspace));
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
export const useDeleteServiceTokenV3 = () => {
|
||||
const queryClient = useQueryClient();
|
||||
return useMutation<ServiceTokenDataV3, {}, DeleteServiceTokenDataV3DTO>({
|
||||
mutationFn: async ({
|
||||
serviceTokenDataId
|
||||
}) => {
|
||||
console.log("useDeleteServiceTokenV3");
|
||||
const { data: { serviceTokenData } } = await apiRequest.delete(`/api/v3/service-token/${serviceTokenDataId}`);
|
||||
console.log("useDeleteServiceTokenV3 serviceTokenData: ", serviceTokenData);
|
||||
return serviceTokenData;
|
||||
},
|
||||
onSuccess: ({ workspace }) => {
|
||||
console.log("useDeleteServiceTokenV3 onSuccess: ", workspace);
|
||||
queryClient.invalidateQueries(workspaceKeys.getWorkspaceServiceTokenDataV3(workspace));
|
||||
}
|
||||
});
|
||||
};
|
||||
@@ -33,3 +33,38 @@ export type CreateServiceTokenRes = {
|
||||
};
|
||||
|
||||
export type DeleteServiceTokenRes = { serviceTokenData: ServiceToken };
|
||||
|
||||
// --- v3
|
||||
|
||||
export type ServiceTokenDataV3 = {
|
||||
_id: string;
|
||||
name: string;
|
||||
workspace: string;
|
||||
isActive: boolean;
|
||||
lastUsed?: string;
|
||||
createdAt: string;
|
||||
updatedAt: string;
|
||||
};
|
||||
|
||||
// TODO: add scopes
|
||||
// TODO: encrypted key info
|
||||
export type CreateServiceTokenDataV3DTO = {
|
||||
name: string;
|
||||
workspaceId: string;
|
||||
publicKey: string;
|
||||
}
|
||||
|
||||
export type CreateServiceTokenDataV3Res = {
|
||||
serviceToken: string;
|
||||
serviceTokenData: ServiceTokenDataV3;
|
||||
}
|
||||
|
||||
export type UpdateServiceTokenDataV3DTO = {
|
||||
serviceTokenDataId: string;
|
||||
name?: string;
|
||||
isActive?: boolean;
|
||||
}
|
||||
|
||||
export type DeleteServiceTokenDataV3DTO = {
|
||||
serviceTokenDataId: string;
|
||||
}
|
||||
Reference in New Issue
Block a user