mirror of
https://github.com/Drop-OSS/drop.git
synced 2025-11-14 08:41:15 +10:00
ca groundwork
This commit is contained in:
23
server/internal/clients/store.ts
Normal file
23
server/internal/clients/store.ts
Normal file
@ -0,0 +1,23 @@
|
||||
import path from "path";
|
||||
import fs from "fs";
|
||||
import { CertificateBundle } from "./ca";
|
||||
|
||||
export type CertificateStore = {
|
||||
store(name: string, data: CertificateBundle): Promise<void>;
|
||||
fetch(name: string): Promise<CertificateBundle | undefined>;
|
||||
};
|
||||
|
||||
export const fsCertificateStore = (base: string) => {
|
||||
const store: CertificateStore = {
|
||||
async store(name: string, data: CertificateBundle) {
|
||||
const filepath = path.join(base, name);
|
||||
fs.writeFileSync(filepath, JSON.stringify(data));
|
||||
},
|
||||
async fetch(name: string) {
|
||||
const filepath = path.join(base, name);
|
||||
if (!fs.existsSync(filepath)) return undefined;
|
||||
return JSON.parse(fs.readFileSync(filepath, "utf-8"));
|
||||
},
|
||||
};
|
||||
return store;
|
||||
};
|
||||
Reference in New Issue
Block a user