update structure
This commit is contained in:
@ -1,17 +1,18 @@
|
||||
import * as fs from 'fs';
|
||||
import * as path from 'path';
|
||||
import { fileURLToPath } from 'url';
|
||||
import type { Certificates } from '../models/certificate-types.js';
|
||||
|
||||
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
||||
|
||||
export interface ICertificates {
|
||||
privateKey: string;
|
||||
publicKey: string;
|
||||
}
|
||||
|
||||
export function loadDefaultCertificates(): ICertificates {
|
||||
/**
|
||||
* Loads the default SSL certificates from the assets directory
|
||||
* @returns The certificate key pair
|
||||
*/
|
||||
export function loadDefaultCertificates(): Certificates {
|
||||
try {
|
||||
const certPath = path.join(__dirname, '..', 'assets', 'certs');
|
||||
// Need to adjust path from /ts/certificate/utils to /assets/certs
|
||||
const certPath = path.join(__dirname, '..', '..', '..', 'assets', 'certs');
|
||||
const privateKey = fs.readFileSync(path.join(certPath, 'key.pem'), 'utf8');
|
||||
const publicKey = fs.readFileSync(path.join(certPath, 'cert.pem'), 'utf8');
|
||||
|
||||
@ -28,3 +29,22 @@ export function loadDefaultCertificates(): ICertificates {
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if a certificate file exists at the specified path
|
||||
* @param certPath Path to check for certificate
|
||||
* @returns True if the certificate exists, false otherwise
|
||||
*/
|
||||
export function certificateExists(certPath: string): boolean {
|
||||
return fs.existsSync(certPath);
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensures the certificate directory exists
|
||||
* @param dirPath Path to the certificate directory
|
||||
*/
|
||||
export function ensureCertificateDirectory(dirPath: string): void {
|
||||
if (!fs.existsSync(dirPath)) {
|
||||
fs.mkdirSync(dirPath, { recursive: true });
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user