feat: Implement repositories for authentication, certificates, metrics, and platform services

- Added AuthRepository for user and settings management with CRUD operations.
- Introduced CertificateRepository to handle domains, certificates, and requirements.
- Created MetricsRepository for managing metrics and logs.
- Developed PlatformRepository for platform services and resources management.
- Established RegistryRepository for registry and token operations.
- Implemented ServiceRepository for CRUD operations on services.
- Defined types and interfaces in types.ts for database interactions.
This commit is contained in:
2025-11-25 23:27:27 +00:00
parent 9d58971983
commit ad89f2cc1f
18 changed files with 2249 additions and 1966 deletions

View File

@@ -18,8 +18,8 @@ interface IProxyRoute {
interface ITlsConfig {
domain: string;
certPath: string;
keyPath: string;
certPem: string; // Certificate PEM content
keyPem: string; // Private key PEM content
}
export class OneboxReverseProxy {
@@ -112,8 +112,8 @@ export class OneboxReverseProxy {
{
port: this.httpsPort,
hostname: '0.0.0.0',
cert: await Deno.readTextFile(defaultConfig.certPath),
key: await Deno.readTextFile(defaultConfig.keyPath),
cert: defaultConfig.certPem,
key: defaultConfig.keyPem,
onListen: ({ hostname, port }) => {
logger.success(`HTTPS reverse proxy listening on https://${hostname}:${port}`);
},
@@ -402,30 +402,26 @@ export class OneboxReverseProxy {
}
/**
* Add TLS certificate for a domain
* Add TLS certificate for a domain (using PEM content)
*/
async addCertificate(domain: string, certPath: string, keyPath: string): Promise<void> {
try {
// Verify certificate files exist
await Deno.stat(certPath);
await Deno.stat(keyPath);
addCertificate(domain: string, certPem: string, keyPem: string): void {
if (!certPem || !keyPem) {
logger.warn(`Cannot add certificate for ${domain}: missing PEM content`);
return;
}
this.tlsConfigs.set(domain, {
domain,
certPath,
keyPath,
});
this.tlsConfigs.set(domain, {
domain,
certPem,
keyPem,
});
logger.success(`Added TLS certificate for ${domain}`);
logger.success(`Added TLS certificate for ${domain}`);
// If HTTPS server is already running, we need to restart it
// TODO: Implement hot reload for certificates
if (this.httpsServer) {
logger.warn('HTTPS server restart required for new certificate to take effect');
}
} catch (error) {
logger.error(`Failed to add certificate for ${domain}: ${getErrorMessage(error)}`);
throw error;
// If HTTPS server is already running, we need to restart it
// TODO: Implement hot reload for certificates
if (this.httpsServer) {
logger.warn('HTTPS server restart required for new certificate to take effect');
}
}
@@ -441,23 +437,22 @@ export class OneboxReverseProxy {
}
/**
* Reload TLS certificates from SSL manager
* Reload TLS certificates from database
*/
async reloadCertificates(): Promise<void> {
try {
logger.info('Reloading TLS certificates...');
logger.info('Reloading TLS certificates from database...');
this.tlsConfigs.clear();
const certificates = this.database.getAllSSLCertificates();
for (const cert of certificates) {
if (cert.domain && cert.certPath && cert.keyPath) {
try {
await this.addCertificate(cert.domain, cert.fullChainPath, cert.keyPath);
} catch (error) {
logger.warn(`Failed to load certificate for ${cert.domain}: ${getErrorMessage(error)}`);
}
// Use fullchainPem for the cert (includes intermediates) and keyPem for the key
if (cert.domain && cert.fullchainPem && cert.keyPem) {
this.addCertificate(cert.domain, cert.fullchainPem, cert.keyPem);
} else {
logger.warn(`Skipping certificate for ${cert.domain}: missing PEM content`);
}
}