Update ST V3 to machine identity

This commit is contained in:
Tuan Dang
2023-11-24 19:19:31 +07:00
parent 41c41a647f
commit 595a26a366
71 changed files with 651 additions and 697 deletions
@@ -1,8 +1,5 @@
export {
useCreateServiceToken,
useCreateServiceTokenV3,
useDeleteServiceToken,
useDeleteServiceTokenV3,
useGetUserWsServiceTokens,
useUpdateServiceTokenV3
} from "./queries";
@@ -2,17 +2,12 @@ import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
import { apiRequest } from "@app/config/request";
import { organizationKeys } from "../organization/queries";
import {
CreateServiceTokenDataV3DTO,
CreateServiceTokenDataV3Res,
CreateServiceTokenDTO,
CreateServiceTokenRes,
DeleteServiceTokenDataV3DTO,
DeleteServiceTokenRes,
ServiceToken,
ServiceTokenDataV3,
UpdateServiceTokenDataV3DTO} from "./types";
ServiceToken
} from "./types";
const serviceTokenKeys = {
getAllWorkspaceServiceToken: (workspaceID: string) => [{ workspaceID }, "service-tokens"] as const
@@ -64,63 +59,4 @@ export const useDeleteServiceToken = () => {
queryClient.invalidateQueries(serviceTokenKeys.getAllWorkspaceServiceToken(workspace));
}
});
};
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(organizationKeys.getOrgServiceMemberships(serviceTokenData.organization));
}
});
};
export const useUpdateServiceTokenV3 = () => {
const queryClient = useQueryClient();
return useMutation<ServiceTokenDataV3, {}, UpdateServiceTokenDataV3DTO>({
mutationFn: async ({
serviceTokenDataId,
name,
role,
isActive,
trustedIps,
expiresIn,
accessTokenTTL,
isRefreshTokenRotationEnabled
}) => {
const { data: { serviceTokenData } } = await apiRequest.patch(`/api/v3/service-token/${serviceTokenDataId}`, {
name,
role,
isActive,
trustedIps,
expiresIn,
accessTokenTTL,
isRefreshTokenRotationEnabled
});
return serviceTokenData;
},
onSuccess: ({ organization }) => {
queryClient.invalidateQueries(organizationKeys.getOrgServiceMemberships(organization));
}
});
};
export const useDeleteServiceTokenV3 = () => {
const queryClient = useQueryClient();
return useMutation<ServiceTokenDataV3, {}, DeleteServiceTokenDataV3DTO>({
mutationFn: async ({
serviceTokenDataId
}) => {
const { data: { serviceTokenData } } = await apiRequest.delete(`/api/v3/service-token/${serviceTokenDataId}`);
return serviceTokenData;
},
onSuccess: ({ organization }) => {
queryClient.invalidateQueries(organizationKeys.getOrgServiceMemberships(organization));
}
});
};
+1 -83
View File
@@ -1,5 +1,3 @@
import { TRole } from "../roles/types";
export type ServiceTokenScope = {
environment: string;
secretPath: string;
@@ -34,84 +32,4 @@ export type CreateServiceTokenRes = {
serviceTokenData: ServiceToken;
};
export type DeleteServiceTokenRes = { serviceTokenData: ServiceToken };
// --- v3
export type ServiceTokenV3TrustedIp = {
_id: string;
ipAddress: string;
type: "ipv4" | "ipv6";
prefix?: number;
}
export type ServiceTokenDataV3 = {
_id: string;
name: string;
organization: string;
isActive: boolean;
refreshTokenLastUsed?: string;
accessTokenLastUsed?: string;
refreshTokenUsageCount: number;
accessTokenUsageCount: number;
trustedIps: ServiceTokenV3TrustedIp[];
expiresAt?: string;
accessTokenTTL: number;
isRefreshTokenRotationEnabled: boolean;
createdAt: string;
updatedAt: string;
};
export type ServiceMembershipOrg = {
_id: string;
service: ServiceTokenDataV3;
organization: string;
role: "admin" | "member" | "viewer" | "custom";
customRole?: TRole;
createdAt: string;
updatedAt: string;
}
export type ServiceMembership = {
_id: string;
service: ServiceTokenDataV3;
organization: string;
role: "admin" | "member" | "viewer" | "custom";
customRole?: TRole;
createdAt: string;
updatedAt: string;
}
export type CreateServiceTokenDataV3DTO = {
name: string;
organizationId: string;
role?: string;
trustedIps: {
ipAddress: string;
}[];
expiresIn?: number;
accessTokenTTL: number;
isRefreshTokenRotationEnabled: boolean;
}
export type CreateServiceTokenDataV3Res = {
refreshToken: string;
serviceTokenData: ServiceTokenDataV3;
}
export type UpdateServiceTokenDataV3DTO = {
serviceTokenDataId: string;
isActive?: boolean;
name?: string;
role?: string;
trustedIps?: {
ipAddress: string;
}[];
expiresIn?: number;
accessTokenTTL?: number;
isRefreshTokenRotationEnabled?: boolean;
}
export type DeleteServiceTokenDataV3DTO = {
serviceTokenDataId: string;
}
export type DeleteServiceTokenRes = { serviceTokenData: ServiceToken };