Begin frontend for GCP IAM Auth

This commit is contained in:
Tuan Dang
2024-05-07 12:40:19 -07:00
parent e96ca8d355
commit 1d40d9e448
7 changed files with 479 additions and 21 deletions
@@ -5,6 +5,7 @@ import { apiRequest } from "@app/config/request";
import { organizationKeys } from "../organization/queries";
import { identitiesKeys } from "./queries";
import {
AddIdentityGcpIamAuthDTO,
AddIdentityUniversalAuthDTO,
ClientSecretData,
CreateIdentityDTO,
@@ -13,10 +14,11 @@ import {
DeleteIdentityDTO,
DeleteIdentityUniversalAuthClientSecretDTO,
Identity,
IdentityGcpIamAuth,
IdentityUniversalAuth,
UpdateIdentityDTO,
UpdateIdentityUniversalAuthDTO
} from "./types";
UpdateIdentityGcpIamAuthDTO,
UpdateIdentityUniversalAuthDTO} from "./types";
export const useCreateIdentity = () => {
const queryClient = useQueryClient();
@@ -169,3 +171,70 @@ export const useRevokeIdentityUniversalAuthClientSecret = () => {
}
});
};
export const useAddIdentityGcpIamAuth = () => {
const queryClient = useQueryClient();
return useMutation<IdentityGcpIamAuth, {}, AddIdentityGcpIamAuthDTO>({
mutationFn: async ({
identityId,
allowedServiceAccounts,
allowedProjects,
accessTokenTTL,
accessTokenMaxTTL,
accessTokenNumUsesLimit,
accessTokenTrustedIps
}) => {
const {
data: { identityGcpIamAuth }
} = await apiRequest.post<{ identityGcpIamAuth: IdentityGcpIamAuth }>(
`/api/v1/auth/gcp-iam-auth/identities/${identityId}`,
{
allowedServiceAccounts,
allowedProjects,
accessTokenTTL,
accessTokenMaxTTL,
accessTokenNumUsesLimit,
accessTokenTrustedIps
}
);
return identityGcpIamAuth;
},
onSuccess: (_, { organizationId }) => {
queryClient.invalidateQueries(organizationKeys.getOrgIdentityMemberships(organizationId));
}
});
};
export const useUpdateIdentityGcpIamAuth = () => {
const queryClient = useQueryClient();
return useMutation<IdentityGcpIamAuth, {}, UpdateIdentityGcpIamAuthDTO>({
mutationFn: async ({
identityId,
allowedServiceAccounts,
allowedProjects,
accessTokenTTL,
accessTokenMaxTTL,
accessTokenNumUsesLimit,
accessTokenTrustedIps
}) => {
const {
data: { identityGcpIamAuth }
} = await apiRequest.patch<{ identityGcpIamAuth: IdentityGcpIamAuth }>(
`/api/v1/auth/gcp-iam-auth/identities/${identityId}`,
{
allowedServiceAccounts,
allowedProjects,
accessTokenTTL,
accessTokenMaxTTL,
accessTokenNumUsesLimit,
accessTokenTrustedIps
}
);
return identityGcpIamAuth;
},
onSuccess: (_, { organizationId }) => {
queryClient.invalidateQueries(organizationKeys.getOrgIdentityMemberships(organizationId));
}
});
};