86 lines
2.8 KiB
TypeScript
86 lines
2.8 KiB
TypeScript
import * as plugins from '../plugins.ts';
|
|
import { logger } from '../logging.ts';
|
|
import { ConnectionManager } from './connectionmanager.ts';
|
|
import { OpsServer } from '../opsserver/index.ts';
|
|
import { StorageManager } from '../storage/index.ts';
|
|
import { CacheDb, CacheCleaner, CachedProject, CachedSecret, SecretsScanService } from '../cache/index.ts';
|
|
import { resolvePaths } from '../paths.ts';
|
|
|
|
/**
|
|
* Main GitOps application orchestrator
|
|
*/
|
|
export class GitopsApp {
|
|
public storageManager: StorageManager;
|
|
public smartSecret: plugins.smartsecret.SmartSecret;
|
|
public connectionManager: ConnectionManager;
|
|
public opsServer: OpsServer;
|
|
public cacheDb: CacheDb;
|
|
public cacheCleaner: CacheCleaner;
|
|
public secretsScanService!: SecretsScanService;
|
|
private scanIntervalId: number | null = null;
|
|
|
|
constructor() {
|
|
const paths = resolvePaths();
|
|
this.storageManager = new StorageManager({
|
|
backend: 'filesystem',
|
|
fsPath: paths.defaultStoragePath,
|
|
});
|
|
this.smartSecret = new plugins.smartsecret.SmartSecret({ service: 'gitops' });
|
|
this.connectionManager = new ConnectionManager(this.storageManager, this.smartSecret);
|
|
|
|
this.cacheDb = CacheDb.getInstance({
|
|
storagePath: paths.defaultTsmDbPath,
|
|
dbName: 'gitops_cache',
|
|
});
|
|
this.cacheCleaner = new CacheCleaner(this.cacheDb);
|
|
this.cacheCleaner.registerClass(CachedProject);
|
|
this.cacheCleaner.registerClass(CachedSecret);
|
|
|
|
this.opsServer = new OpsServer(this);
|
|
}
|
|
|
|
async start(port = 3000): Promise<void> {
|
|
logger.info('Initializing GitOps...');
|
|
|
|
// Start CacheDb
|
|
await this.cacheDb.start();
|
|
|
|
// Initialize connection manager (loads saved connections)
|
|
await this.connectionManager.init();
|
|
|
|
// Initialize secrets scan service with 24h auto-scan
|
|
this.secretsScanService = new SecretsScanService(this.connectionManager);
|
|
const SCAN_INTERVAL_MS = 24 * 60 * 60 * 1000; // 24 hours
|
|
this.scanIntervalId = setInterval(() => {
|
|
this.secretsScanService.fullScan().catch((err) => {
|
|
logger.error(`Scheduled secrets scan failed: ${err}`);
|
|
});
|
|
}, SCAN_INTERVAL_MS);
|
|
Deno.unrefTimer(this.scanIntervalId);
|
|
// Fire-and-forget initial scan (doesn't block startup)
|
|
this.secretsScanService.fullScan().catch((err) => {
|
|
logger.error(`Initial secrets scan failed: ${err}`);
|
|
});
|
|
|
|
// Start CacheCleaner
|
|
this.cacheCleaner.start();
|
|
|
|
// Start OpsServer
|
|
await this.opsServer.start(port);
|
|
|
|
logger.success('GitOps initialized successfully');
|
|
}
|
|
|
|
async stop(): Promise<void> {
|
|
logger.info('Shutting down GitOps...');
|
|
if (this.scanIntervalId !== null) {
|
|
clearInterval(this.scanIntervalId);
|
|
this.scanIntervalId = null;
|
|
}
|
|
await this.opsServer.stop();
|
|
this.cacheCleaner.stop();
|
|
await this.cacheDb.stop();
|
|
logger.success('GitOps shutdown complete');
|
|
}
|
|
}
|