mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-15 21:40:31 +00:00
misc: made kms hook generic
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
export {
|
||||
useAddAwsExternalKms,
|
||||
useAddExternalKms,
|
||||
useLoadProjectKmsBackup,
|
||||
useRemoveExternalKms,
|
||||
useUpdateAwsExternalKms,
|
||||
useUpdateExternalKms,
|
||||
useUpdateProjectKms
|
||||
} from "./mutations";
|
||||
export { useGetActiveProjectKms, useGetExternalKmsById, useGetExternalKmsList } from "./queries";
|
||||
|
||||
@@ -3,50 +3,16 @@ import { useMutation, useQueryClient } from "@tanstack/react-query";
|
||||
import { apiRequest } from "@app/config/request";
|
||||
|
||||
import { kmsKeys } from "./queries";
|
||||
import { AddExternalKmsType } from "./types";
|
||||
|
||||
export const useAddAwsExternalKms = (orgId: string) => {
|
||||
export const useAddExternalKms = (orgId: string) => {
|
||||
const queryClient = useQueryClient();
|
||||
return useMutation({
|
||||
mutationFn: async ({
|
||||
slug,
|
||||
description,
|
||||
credentialType,
|
||||
accessKey,
|
||||
secretKey,
|
||||
assumeRoleArn,
|
||||
externalId,
|
||||
awsRegion,
|
||||
kmsKeyId
|
||||
}: {
|
||||
slug: string;
|
||||
description: string;
|
||||
credentialType: string;
|
||||
accessKey?: string;
|
||||
secretKey?: string;
|
||||
assumeRoleArn?: string;
|
||||
externalId?: string;
|
||||
awsRegion: string;
|
||||
kmsKeyId?: string;
|
||||
}) => {
|
||||
mutationFn: async ({ slug, description, provider }: AddExternalKmsType) => {
|
||||
const { data } = await apiRequest.post("/api/v1/external-kms", {
|
||||
slug,
|
||||
description,
|
||||
provider: {
|
||||
type: "aws",
|
||||
inputs: {
|
||||
credential: {
|
||||
type: credentialType,
|
||||
data: {
|
||||
accessKey,
|
||||
secretKey,
|
||||
assumeRoleArn,
|
||||
externalId
|
||||
}
|
||||
},
|
||||
awsRegion,
|
||||
kmsKeyId
|
||||
}
|
||||
}
|
||||
provider
|
||||
});
|
||||
|
||||
return data;
|
||||
@@ -57,51 +23,21 @@ export const useAddAwsExternalKms = (orgId: string) => {
|
||||
});
|
||||
};
|
||||
|
||||
export const useUpdateAwsExternalKms = (orgId: string) => {
|
||||
export const useUpdateExternalKms = (orgId: string) => {
|
||||
const queryClient = useQueryClient();
|
||||
return useMutation({
|
||||
mutationFn: async ({
|
||||
kmsId,
|
||||
slug,
|
||||
description,
|
||||
credentialType,
|
||||
accessKey,
|
||||
secretKey,
|
||||
assumeRoleArn,
|
||||
externalId,
|
||||
awsRegion,
|
||||
kmsKeyId
|
||||
provider
|
||||
}: {
|
||||
kmsId: string;
|
||||
slug?: string;
|
||||
description?: string;
|
||||
credentialType?: string;
|
||||
accessKey?: string;
|
||||
secretKey?: string;
|
||||
assumeRoleArn?: string;
|
||||
externalId?: string;
|
||||
awsRegion: string;
|
||||
kmsKeyId?: string;
|
||||
}) => {
|
||||
} & AddExternalKmsType) => {
|
||||
const { data } = await apiRequest.patch(`/api/v1/external-kms/${kmsId}`, {
|
||||
slug,
|
||||
description,
|
||||
provider: {
|
||||
type: "aws",
|
||||
inputs: {
|
||||
credential: {
|
||||
type: credentialType,
|
||||
data: {
|
||||
accessKey,
|
||||
secretKey,
|
||||
assumeRoleArn,
|
||||
externalId
|
||||
}
|
||||
},
|
||||
awsRegion,
|
||||
kmsKeyId
|
||||
}
|
||||
}
|
||||
provider
|
||||
});
|
||||
|
||||
return data;
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
import slugify from "@sindresorhus/slugify";
|
||||
import { z } from "zod";
|
||||
|
||||
export type Kms = {
|
||||
id: string;
|
||||
description: string;
|
||||
@@ -31,3 +34,64 @@ export enum ExternalKmsProvider {
|
||||
}
|
||||
|
||||
export const INTERNAL_KMS_KEY_ID = "internal";
|
||||
|
||||
export enum KmsAwsCredentialType {
|
||||
AssumeRole = "assume-role",
|
||||
AccessKey = "access-key"
|
||||
}
|
||||
|
||||
export const ExternalKmsAwsSchema = z.object({
|
||||
credential: z
|
||||
.discriminatedUnion("type", [
|
||||
z.object({
|
||||
type: z.literal(KmsAwsCredentialType.AccessKey),
|
||||
data: z.object({
|
||||
accessKey: z.string().trim().min(1).describe("AWS user account access key"),
|
||||
secretKey: z.string().trim().min(1).describe("AWS user account secret key")
|
||||
})
|
||||
}),
|
||||
z.object({
|
||||
type: z.literal(KmsAwsCredentialType.AssumeRole),
|
||||
data: z.object({
|
||||
assumeRoleArn: z
|
||||
.string()
|
||||
.trim()
|
||||
.min(1)
|
||||
.describe("AWS user role to be assumed by infisical"),
|
||||
externalId: z
|
||||
.string()
|
||||
.trim()
|
||||
.min(1)
|
||||
.optional()
|
||||
.describe("AWS assume role external id for furthur security in authentication")
|
||||
})
|
||||
})
|
||||
])
|
||||
.describe("AWS credential information to connect"),
|
||||
awsRegion: z.string().min(1).trim().describe("AWS region to connect"),
|
||||
kmsKeyId: z
|
||||
.string()
|
||||
.trim()
|
||||
.optional()
|
||||
.describe(
|
||||
"A pre existing AWS KMS key id to be used for encryption. If not provided a kms key will be generated."
|
||||
)
|
||||
});
|
||||
|
||||
export const ExternalKmsInputSchema = z.discriminatedUnion("type", [
|
||||
z.object({ type: z.literal(ExternalKmsProvider.AWS), inputs: ExternalKmsAwsSchema })
|
||||
]);
|
||||
|
||||
export const AddExternalKmsSchema = z.object({
|
||||
slug: z
|
||||
.string()
|
||||
.trim()
|
||||
.min(1)
|
||||
.refine((v) => slugify(v) === v, {
|
||||
message: "Alias must be a valid slug"
|
||||
}),
|
||||
description: z.string().trim().min(1).default(""),
|
||||
provider: ExternalKmsInputSchema
|
||||
});
|
||||
|
||||
export type AddExternalKmsType = z.infer<typeof AddExternalKmsSchema>;
|
||||
|
||||
Reference in New Issue
Block a user