mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-15 22:46:24 +00:00
feat: simplified ui for password based secret sharing
This commit is contained in:
@@ -7,7 +7,11 @@ import { TSharedSecret, TViewSharedSecretResponse } from "./types";
|
||||
export const secretSharingKeys = {
|
||||
allSharedSecrets: () => ["sharedSecrets"] as const,
|
||||
specificSharedSecrets: ({ offset, limit }: { offset: number; limit: number }) =>
|
||||
[...secretSharingKeys.allSharedSecrets(), { offset, limit }] as const
|
||||
[...secretSharingKeys.allSharedSecrets(), { offset, limit }] as const,
|
||||
getSecretById: (arg: { id: string; hashedHex: string; password?: string }) => [
|
||||
"shared-secret",
|
||||
arg
|
||||
]
|
||||
};
|
||||
|
||||
export const useGetSharedSecrets = ({
|
||||
@@ -38,51 +42,28 @@ export const useGetSharedSecrets = ({
|
||||
|
||||
export const useGetActiveSharedSecretById = ({
|
||||
sharedSecretId,
|
||||
hashedHex
|
||||
hashedHex,
|
||||
password
|
||||
}: {
|
||||
sharedSecretId: string;
|
||||
hashedHex: string;
|
||||
password?: string;
|
||||
}) => {
|
||||
return useQuery<TViewSharedSecretResponse | null>(
|
||||
[`sharedSecret-${sharedSecretId}`],
|
||||
return useQuery<TViewSharedSecretResponse>(
|
||||
secretSharingKeys.getSecretById({ id: sharedSecretId, hashedHex, password }),
|
||||
async () => {
|
||||
const params = new URLSearchParams({ hashedHex });
|
||||
const { data } = await apiRequest.get<TViewSharedSecretResponse>(
|
||||
const { data } = await apiRequest.post<TViewSharedSecretResponse>(
|
||||
`/api/v1/secret-sharing/public/${sharedSecretId}`,
|
||||
{
|
||||
params
|
||||
hashedHex,
|
||||
password
|
||||
}
|
||||
);
|
||||
|
||||
if (!data) return null
|
||||
|
||||
return {
|
||||
encryptedValue: data.encryptedValue,
|
||||
iv: data.iv,
|
||||
tag: data.tag,
|
||||
accessType: data.accessType,
|
||||
orgName: data.orgName
|
||||
};
|
||||
|
||||
return data;
|
||||
},
|
||||
{
|
||||
enabled: Boolean(sharedSecretId) && Boolean(hashedHex)
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
// returns a secret (secret or undefined if password doesn't match)
|
||||
export const fetchSecretIfPasswordIsValid = async (
|
||||
sharedSecretId: string,
|
||||
hashedHex: string,
|
||||
password: string,
|
||||
) => {
|
||||
const { data } = await apiRequest.post<TViewSharedSecretResponse>(
|
||||
`/api/v1/secret-sharing/public/${sharedSecretId}/validate`,
|
||||
{
|
||||
hashedHex,
|
||||
password
|
||||
}
|
||||
);
|
||||
|
||||
return data;
|
||||
};
|
||||
|
||||
@@ -26,11 +26,14 @@ export type TCreateSharedSecretRequest = {
|
||||
};
|
||||
|
||||
export type TViewSharedSecretResponse = {
|
||||
encryptedValue: string;
|
||||
iv: string;
|
||||
tag: string;
|
||||
accessType: SecretSharingAccessType;
|
||||
orgName?: string;
|
||||
isPasswordProtected: boolean;
|
||||
secret: {
|
||||
encryptedValue: string;
|
||||
iv: string;
|
||||
tag: string;
|
||||
accessType: SecretSharingAccessType;
|
||||
orgName?: string;
|
||||
};
|
||||
};
|
||||
|
||||
export type TDeleteSharedSecretRequest = {
|
||||
@@ -40,4 +43,5 @@ export type TDeleteSharedSecretRequest = {
|
||||
export enum SecretSharingAccessType {
|
||||
Anyone = "anyone",
|
||||
Organization = "organization"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user