fix(ui): сохранять контекст экспорта сертификатов IPsec
This commit is contained in:
1 parent
86ecf764ff
commit
74e7cd257d
7 files changed
+151
-67
No files matched your search
+16
-3
@@ -1,4 +1,4 @@
|
||||
import { ipsecServerSummaryDtoSchema, ipsecUserCreatedSchema } from "@mmapp/contracts/ipsec"
|
||||
import { ipsecServerSummaryDtoSchema, ipsecUserCreatedSchema, ipsecCertBundleSchema } from "@mmapp/contracts/ipsec"
|
||||
import { requestJson } from "@/shared/api/http-client"
|
||||
import type {
|
||||
IpsecCertBundle,
|
||||
@@ -97,17 +97,29 @@ export async function deleteIpsecUser(
|
||||
)
|
||||
}
|
||||
|
||||
function parseExportBundle(response: unknown): IpsecCertBundle {
|
||||
const result = ipsecCertBundleSchema.safeParse(response)
|
||||
if (!result.success || !result.data.filename.trim() || !result.data.user.trim() ||
|
||||
!result.data.passphrase || result.data.passphrase.length < 8 ||
|
||||
!/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/.test(result.data.contentB64) ||
|
||||
!result.data.contentB64) {
|
||||
throw new Error("Некорректный ответ экспорта сертификата")
|
||||
}
|
||||
return result.data
|
||||
}
|
||||
|
||||
export async function exportIpsecUserCert(
|
||||
baseUrl: string,
|
||||
serverId: string,
|
||||
clientId: string,
|
||||
passphrase: string,
|
||||
): Promise<IpsecCertBundle> {
|
||||
return requestJson<IpsecCertBundle>(
|
||||
const response = await requestJson<unknown>(
|
||||
baseUrl,
|
||||
`/api/ipsec/users/${encodeURIComponent(serverId)}/${encodeURIComponent(clientId)}/cert`,
|
||||
{ method: "POST", body: JSON.stringify({ passphrase }) },
|
||||
)
|
||||
return parseExportBundle(response)
|
||||
}
|
||||
|
||||
export async function exportIpsecCertByName(
|
||||
@@ -116,11 +128,12 @@ export async function exportIpsecCertByName(
|
||||
name: string,
|
||||
passphrase: string,
|
||||
): Promise<IpsecCertBundle> {
|
||||
return requestJson<IpsecCertBundle>(
|
||||
const response = await requestJson<unknown>(
|
||||
baseUrl,
|
||||
`/api/ipsec/certs/${encodeURIComponent(serverId)}/export`,
|
||||
{ method: "POST", body: JSON.stringify({ name, passphrase }) },
|
||||
)
|
||||
return parseExportBundle(response)
|
||||
}
|
||||
|
||||
export async function restoreIpsecRevision(
|
||||
|
||||
Reference in new issue
Block a user