Docker images / prepare-release (push) Successful in 12s
Docker images / backend-test (push) Successful in 2m41s
Docker images / frontend-image (push) Successful in 2m57s
Docker images / updater-image (push) Successful in 48s
Docker images / backend-image (push) Successful in 2m48s
Docker images / notify-webhook (push) Skipped
Docker images / publish-release (push) Successful in 13s
- Implemented a new backend route for exporting existing client certificates in .p12 format by name. - Enhanced the frontend to support exporting certificates directly from the IPsec server grid. - Updated the IPsec page to manage certificate states and handle exports effectively. - Introduced new utility functions for certificate handling and improved data structures to accommodate the changes. - Added tests to ensure the reliability of the new certificate export feature.
168 lines
4.7 KiB
TypeScript
168 lines
4.7 KiB
TypeScript
import { requestJson } from "@/shared/api/http-client"
|
|
import type {
|
|
IpsecCertBundle,
|
|
IpsecInitRequest,
|
|
IpsecListResponse,
|
|
IpsecPeerPatch,
|
|
IpsecServerSummaryDto,
|
|
IpsecUserCreateRequest,
|
|
IpsecUserCreated,
|
|
IpsecUserPatch,
|
|
} from "@mmapp/contracts/ipsec"
|
|
|
|
export async function listIpsec(
|
|
baseUrl: string,
|
|
opts?: { serverId?: string },
|
|
): Promise<IpsecListResponse> {
|
|
const q = new URLSearchParams()
|
|
if (opts?.serverId) q.set("serverId", opts.serverId)
|
|
const suffix = q.size > 0 ? `?${q.toString()}` : ""
|
|
return requestJson<IpsecListResponse>(baseUrl, `/api/ipsec${suffix}`, { method: "GET" })
|
|
}
|
|
|
|
export async function initIpsecServer(
|
|
baseUrl: string,
|
|
body: IpsecInitRequest,
|
|
): Promise<IpsecServerSummaryDto> {
|
|
return requestJson<IpsecServerSummaryDto>(baseUrl, "/api/ipsec/server/init", {
|
|
method: "POST",
|
|
body: JSON.stringify(body),
|
|
})
|
|
}
|
|
|
|
export async function deleteIpsecServer(
|
|
baseUrl: string,
|
|
serverId: string,
|
|
opts?: { removeCertificates?: boolean },
|
|
): Promise<{ ok: boolean }> {
|
|
const q = new URLSearchParams()
|
|
if (opts?.removeCertificates === false) q.set("removeCertificates", "false")
|
|
const suffix = q.size > 0 ? `?${q.toString()}` : ""
|
|
return requestJson<{ ok: boolean }>(
|
|
baseUrl,
|
|
`/api/ipsec/server/${encodeURIComponent(serverId)}${suffix}`,
|
|
{ method: "DELETE" },
|
|
)
|
|
}
|
|
|
|
export async function createIpsecUser(
|
|
baseUrl: string,
|
|
body: IpsecUserCreateRequest,
|
|
): Promise<IpsecUserCreated> {
|
|
return requestJson<IpsecUserCreated>(baseUrl, "/api/ipsec/users", {
|
|
method: "POST",
|
|
body: JSON.stringify(body),
|
|
})
|
|
}
|
|
|
|
export async function patchIpsecUser(
|
|
baseUrl: string,
|
|
serverId: string,
|
|
clientId: string,
|
|
patch: IpsecUserPatch,
|
|
): Promise<{ ok: boolean }> {
|
|
return requestJson<{ ok: boolean }>(
|
|
baseUrl,
|
|
`/api/ipsec/users/${encodeURIComponent(serverId)}/${encodeURIComponent(clientId)}`,
|
|
{ method: "PATCH", body: JSON.stringify(patch) },
|
|
)
|
|
}
|
|
|
|
export async function deleteIpsecUser(
|
|
baseUrl: string,
|
|
serverId: string,
|
|
clientId: string,
|
|
opts?: { removeCertificate?: boolean },
|
|
): Promise<{ ok: boolean }> {
|
|
const q = new URLSearchParams()
|
|
if (opts?.removeCertificate === false) q.set("removeCertificate", "false")
|
|
const suffix = q.size > 0 ? `?${q.toString()}` : ""
|
|
return requestJson<{ ok: boolean }>(
|
|
baseUrl,
|
|
`/api/ipsec/users/${encodeURIComponent(serverId)}/${encodeURIComponent(clientId)}${suffix}`,
|
|
{ method: "DELETE" },
|
|
)
|
|
}
|
|
|
|
export async function exportIpsecUserCert(
|
|
baseUrl: string,
|
|
serverId: string,
|
|
clientId: string,
|
|
passphrase: string,
|
|
): Promise<IpsecCertBundle> {
|
|
return requestJson<IpsecCertBundle>(
|
|
baseUrl,
|
|
`/api/ipsec/users/${encodeURIComponent(serverId)}/${encodeURIComponent(clientId)}/cert`,
|
|
{ method: "POST", body: JSON.stringify({ passphrase }) },
|
|
)
|
|
}
|
|
|
|
export async function exportIpsecCertByName(
|
|
baseUrl: string,
|
|
serverId: string,
|
|
name: string,
|
|
passphrase: string,
|
|
): Promise<IpsecCertBundle> {
|
|
return requestJson<IpsecCertBundle>(
|
|
baseUrl,
|
|
`/api/ipsec/certs/${encodeURIComponent(serverId)}/export`,
|
|
{ method: "POST", body: JSON.stringify({ name, passphrase }) },
|
|
)
|
|
}
|
|
|
|
export async function restoreIpsecRevision(
|
|
baseUrl: string,
|
|
revisionId: string,
|
|
serverId: string,
|
|
): Promise<{ ok: boolean }> {
|
|
return requestJson<{ ok: boolean }>(baseUrl, `/api/ipsec/revisions/${encodeURIComponent(revisionId)}/restore`, {
|
|
method: "POST",
|
|
body: JSON.stringify({ serverId }),
|
|
})
|
|
}
|
|
|
|
export async function patchIpsecPeer(
|
|
baseUrl: string,
|
|
serverId: string,
|
|
peerId: string,
|
|
patch: IpsecPeerPatch,
|
|
): Promise<{ ok: boolean }> {
|
|
return requestJson<{ ok: boolean }>(
|
|
baseUrl,
|
|
`/api/ipsec/peers/${encodeURIComponent(serverId)}/${encodeURIComponent(peerId)}`,
|
|
{ method: "PATCH", body: JSON.stringify(patch) },
|
|
)
|
|
}
|
|
|
|
export async function deleteIpsecPeer(
|
|
baseUrl: string,
|
|
serverId: string,
|
|
peerId: string,
|
|
opts?: { force?: boolean },
|
|
): Promise<{ ok: boolean }> {
|
|
const q = new URLSearchParams()
|
|
if (opts?.force) q.set("force", "true")
|
|
const suffix = q.size > 0 ? `?${q.toString()}` : ""
|
|
return requestJson<{ ok: boolean }>(
|
|
baseUrl,
|
|
`/api/ipsec/peers/${encodeURIComponent(serverId)}/${encodeURIComponent(peerId)}${suffix}`,
|
|
{ method: "DELETE" },
|
|
)
|
|
}
|
|
|
|
export async function deleteIpsecCert(
|
|
baseUrl: string,
|
|
serverId: string,
|
|
name: string,
|
|
opts?: { force?: boolean },
|
|
): Promise<{ ok: boolean }> {
|
|
const q = new URLSearchParams()
|
|
if (opts?.force) q.set("force", "true")
|
|
const suffix = q.size > 0 ? `?${q.toString()}` : ""
|
|
return requestJson<{ ok: boolean }>(
|
|
baseUrl,
|
|
`/api/ipsec/certs/${encodeURIComponent(serverId)}${suffix}`,
|
|
{ method: "DELETE", body: JSON.stringify({ name }) },
|
|
)
|
|
}
|