tlc-claude-code 1.4.7 → 1.4.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (170) hide show
  1. package/docker-compose.dev.yml +6 -3
  2. package/package.json +1 -1
  3. package/server/index.js +229 -14
  4. package/server/lib/compliance/control-mapper.js +401 -0
  5. package/server/lib/compliance/control-mapper.test.js +117 -0
  6. package/server/lib/compliance/evidence-linker.js +296 -0
  7. package/server/lib/compliance/evidence-linker.test.js +121 -0
  8. package/server/lib/compliance/gdpr-checklist.js +416 -0
  9. package/server/lib/compliance/gdpr-checklist.test.js +131 -0
  10. package/server/lib/compliance/hipaa-checklist.js +277 -0
  11. package/server/lib/compliance/hipaa-checklist.test.js +101 -0
  12. package/server/lib/compliance/iso27001-checklist.js +287 -0
  13. package/server/lib/compliance/iso27001-checklist.test.js +99 -0
  14. package/server/lib/compliance/multi-framework-reporter.js +284 -0
  15. package/server/lib/compliance/multi-framework-reporter.test.js +127 -0
  16. package/server/lib/compliance/pci-dss-checklist.js +214 -0
  17. package/server/lib/compliance/pci-dss-checklist.test.js +95 -0
  18. package/server/lib/compliance/trust-centre.js +187 -0
  19. package/server/lib/compliance/trust-centre.test.js +93 -0
  20. package/server/lib/dashboard/api-server.js +155 -0
  21. package/server/lib/dashboard/api-server.test.js +155 -0
  22. package/server/lib/dashboard/health-api.js +199 -0
  23. package/server/lib/dashboard/health-api.test.js +122 -0
  24. package/server/lib/dashboard/notes-api.js +234 -0
  25. package/server/lib/dashboard/notes-api.test.js +134 -0
  26. package/server/lib/dashboard/router-api.js +176 -0
  27. package/server/lib/dashboard/router-api.test.js +132 -0
  28. package/server/lib/dashboard/tasks-api.js +289 -0
  29. package/server/lib/dashboard/tasks-api.test.js +161 -0
  30. package/server/lib/dashboard/tlc-introspection.js +197 -0
  31. package/server/lib/dashboard/tlc-introspection.test.js +138 -0
  32. package/server/lib/dashboard/version-api.js +222 -0
  33. package/server/lib/dashboard/version-api.test.js +112 -0
  34. package/server/lib/dashboard/websocket-server.js +104 -0
  35. package/server/lib/dashboard/websocket-server.test.js +118 -0
  36. package/server/lib/deploy/branch-classifier.js +163 -0
  37. package/server/lib/deploy/branch-classifier.test.js +164 -0
  38. package/server/lib/deploy/deployment-approval.js +299 -0
  39. package/server/lib/deploy/deployment-approval.test.js +296 -0
  40. package/server/lib/deploy/deployment-audit.js +374 -0
  41. package/server/lib/deploy/deployment-audit.test.js +307 -0
  42. package/server/lib/deploy/deployment-executor.js +335 -0
  43. package/server/lib/deploy/deployment-executor.test.js +329 -0
  44. package/server/lib/deploy/deployment-rules.js +163 -0
  45. package/server/lib/deploy/deployment-rules.test.js +188 -0
  46. package/server/lib/deploy/rollback-manager.js +379 -0
  47. package/server/lib/deploy/rollback-manager.test.js +321 -0
  48. package/server/lib/deploy/security-gates.js +236 -0
  49. package/server/lib/deploy/security-gates.test.js +222 -0
  50. package/server/lib/k8s/gitops-config.js +188 -0
  51. package/server/lib/k8s/gitops-config.test.js +59 -0
  52. package/server/lib/k8s/helm-generator.js +196 -0
  53. package/server/lib/k8s/helm-generator.test.js +59 -0
  54. package/server/lib/k8s/kustomize-generator.js +176 -0
  55. package/server/lib/k8s/kustomize-generator.test.js +58 -0
  56. package/server/lib/k8s/network-policy.js +114 -0
  57. package/server/lib/k8s/network-policy.test.js +53 -0
  58. package/server/lib/k8s/pod-security.js +114 -0
  59. package/server/lib/k8s/pod-security.test.js +55 -0
  60. package/server/lib/k8s/rbac-generator.js +132 -0
  61. package/server/lib/k8s/rbac-generator.test.js +57 -0
  62. package/server/lib/k8s/resource-manager.js +172 -0
  63. package/server/lib/k8s/resource-manager.test.js +60 -0
  64. package/server/lib/k8s/secrets-encryption.js +168 -0
  65. package/server/lib/k8s/secrets-encryption.test.js +49 -0
  66. package/server/lib/monitoring/alert-manager.js +238 -0
  67. package/server/lib/monitoring/alert-manager.test.js +106 -0
  68. package/server/lib/monitoring/health-check.js +226 -0
  69. package/server/lib/monitoring/health-check.test.js +176 -0
  70. package/server/lib/monitoring/incident-manager.js +230 -0
  71. package/server/lib/monitoring/incident-manager.test.js +98 -0
  72. package/server/lib/monitoring/log-aggregator.js +147 -0
  73. package/server/lib/monitoring/log-aggregator.test.js +89 -0
  74. package/server/lib/monitoring/metrics-collector.js +337 -0
  75. package/server/lib/monitoring/metrics-collector.test.js +172 -0
  76. package/server/lib/monitoring/status-page.js +214 -0
  77. package/server/lib/monitoring/status-page.test.js +105 -0
  78. package/server/lib/monitoring/uptime-monitor.js +194 -0
  79. package/server/lib/monitoring/uptime-monitor.test.js +109 -0
  80. package/server/lib/network/fail2ban-config.js +294 -0
  81. package/server/lib/network/fail2ban-config.test.js +275 -0
  82. package/server/lib/network/firewall-manager.js +252 -0
  83. package/server/lib/network/firewall-manager.test.js +254 -0
  84. package/server/lib/network/geoip-filter.js +282 -0
  85. package/server/lib/network/geoip-filter.test.js +264 -0
  86. package/server/lib/network/rate-limiter.js +229 -0
  87. package/server/lib/network/rate-limiter.test.js +293 -0
  88. package/server/lib/network/request-validator.js +351 -0
  89. package/server/lib/network/request-validator.test.js +345 -0
  90. package/server/lib/network/security-headers.js +251 -0
  91. package/server/lib/network/security-headers.test.js +283 -0
  92. package/server/lib/network/tls-config.js +210 -0
  93. package/server/lib/network/tls-config.test.js +248 -0
  94. package/server/lib/security/auth-security.js +369 -0
  95. package/server/lib/security/auth-security.test.js +448 -0
  96. package/server/lib/security/cis-benchmark.js +152 -0
  97. package/server/lib/security/cis-benchmark.test.js +137 -0
  98. package/server/lib/security/compose-templates.js +312 -0
  99. package/server/lib/security/compose-templates.test.js +229 -0
  100. package/server/lib/security/container-runtime.js +456 -0
  101. package/server/lib/security/container-runtime.test.js +503 -0
  102. package/server/lib/security/cors-validator.js +278 -0
  103. package/server/lib/security/cors-validator.test.js +310 -0
  104. package/server/lib/security/crypto-utils.js +253 -0
  105. package/server/lib/security/crypto-utils.test.js +409 -0
  106. package/server/lib/security/dockerfile-linter.js +459 -0
  107. package/server/lib/security/dockerfile-linter.test.js +483 -0
  108. package/server/lib/security/dockerfile-templates.js +278 -0
  109. package/server/lib/security/dockerfile-templates.test.js +164 -0
  110. package/server/lib/security/error-sanitizer.js +426 -0
  111. package/server/lib/security/error-sanitizer.test.js +331 -0
  112. package/server/lib/security/headers-generator.js +368 -0
  113. package/server/lib/security/headers-generator.test.js +398 -0
  114. package/server/lib/security/image-scanner.js +83 -0
  115. package/server/lib/security/image-scanner.test.js +106 -0
  116. package/server/lib/security/input-validator.js +352 -0
  117. package/server/lib/security/input-validator.test.js +330 -0
  118. package/server/lib/security/network-policy.js +174 -0
  119. package/server/lib/security/network-policy.test.js +164 -0
  120. package/server/lib/security/output-encoder.js +237 -0
  121. package/server/lib/security/output-encoder.test.js +276 -0
  122. package/server/lib/security/path-validator.js +359 -0
  123. package/server/lib/security/path-validator.test.js +293 -0
  124. package/server/lib/security/query-builder.js +421 -0
  125. package/server/lib/security/query-builder.test.js +318 -0
  126. package/server/lib/security/secret-detector.js +290 -0
  127. package/server/lib/security/secret-detector.test.js +354 -0
  128. package/server/lib/security/secrets-validator.js +137 -0
  129. package/server/lib/security/secrets-validator.test.js +120 -0
  130. package/server/lib/security-testing/dast-runner.js +154 -0
  131. package/server/lib/security-testing/dast-runner.test.js +62 -0
  132. package/server/lib/security-testing/dependency-scanner.js +172 -0
  133. package/server/lib/security-testing/dependency-scanner.test.js +64 -0
  134. package/server/lib/security-testing/pentest-runner.js +230 -0
  135. package/server/lib/security-testing/pentest-runner.test.js +60 -0
  136. package/server/lib/security-testing/sast-runner.js +136 -0
  137. package/server/lib/security-testing/sast-runner.test.js +62 -0
  138. package/server/lib/security-testing/secret-scanner.js +153 -0
  139. package/server/lib/security-testing/secret-scanner.test.js +66 -0
  140. package/server/lib/security-testing/security-gate.js +216 -0
  141. package/server/lib/security-testing/security-gate.test.js +115 -0
  142. package/server/lib/security-testing/security-reporter.js +303 -0
  143. package/server/lib/security-testing/security-reporter.test.js +114 -0
  144. package/server/lib/standards/audit-checker.js +546 -0
  145. package/server/lib/standards/audit-checker.test.js +415 -0
  146. package/server/lib/standards/cleanup-executor.js +452 -0
  147. package/server/lib/standards/cleanup-executor.test.js +293 -0
  148. package/server/lib/standards/refactor-stepper.js +425 -0
  149. package/server/lib/standards/refactor-stepper.test.js +298 -0
  150. package/server/lib/standards/standards-injector.js +167 -0
  151. package/server/lib/standards/standards-injector.test.js +232 -0
  152. package/server/lib/user-management.test.js +284 -0
  153. package/server/lib/vps/backup-manager.js +157 -0
  154. package/server/lib/vps/backup-manager.test.js +59 -0
  155. package/server/lib/vps/caddy-config.js +159 -0
  156. package/server/lib/vps/caddy-config.test.js +48 -0
  157. package/server/lib/vps/compose-orchestrator.js +219 -0
  158. package/server/lib/vps/compose-orchestrator.test.js +50 -0
  159. package/server/lib/vps/database-config.js +208 -0
  160. package/server/lib/vps/database-config.test.js +47 -0
  161. package/server/lib/vps/deploy-script.js +211 -0
  162. package/server/lib/vps/deploy-script.test.js +53 -0
  163. package/server/lib/vps/secrets-manager.js +148 -0
  164. package/server/lib/vps/secrets-manager.test.js +58 -0
  165. package/server/lib/vps/server-hardening.js +174 -0
  166. package/server/lib/vps/server-hardening.test.js +70 -0
  167. package/server/package-lock.json +19 -0
  168. package/server/package.json +1 -0
  169. package/server/templates/CLAUDE.md +37 -0
  170. package/server/templates/CODING-STANDARDS.md +408 -0
@@ -0,0 +1,219 @@
1
+ /**
2
+ * Docker Compose Orchestrator
3
+ * Docker Compose orchestration for production deployments
4
+ */
5
+
6
+ import YAML from 'js-yaml';
7
+
8
+ /**
9
+ * Generate a production Docker Compose configuration
10
+ * @param {Object} options - Compose configuration options
11
+ * @param {string[]} options.services - List of service names
12
+ * @param {string} [options.version='3.8'] - Compose file version
13
+ * @returns {string} Docker Compose YAML configuration
14
+ */
15
+ export function generateProductionCompose(options = {}) {
16
+ const { services = [], version = '3.8' } = options;
17
+
18
+ const compose = {
19
+ version,
20
+ services: {},
21
+ networks: {
22
+ default: {
23
+ driver: 'bridge',
24
+ },
25
+ },
26
+ };
27
+
28
+ for (const serviceName of services) {
29
+ compose.services[serviceName] = {
30
+ image: `${serviceName}:latest`,
31
+ restart: 'always',
32
+ networks: ['default'],
33
+ };
34
+ }
35
+
36
+ return YAML.dump(compose);
37
+ }
38
+
39
+ /**
40
+ * Add health check configuration to a service
41
+ * @param {Object} options - Health check options
42
+ * @param {string} options.test - Health check command
43
+ * @param {string} [options.interval='30s'] - Check interval
44
+ * @param {string} [options.timeout='10s'] - Check timeout
45
+ * @param {number} [options.retries=3] - Number of retries
46
+ * @returns {Object} Service configuration with health check
47
+ */
48
+ export function addHealthCheck(options = {}) {
49
+ const {
50
+ test,
51
+ interval = '30s',
52
+ timeout = '10s',
53
+ retries = 3,
54
+ startPeriod = '40s',
55
+ } = options;
56
+
57
+ return {
58
+ healthcheck: {
59
+ test: `CMD-SHELL ${test}`,
60
+ interval,
61
+ timeout,
62
+ retries,
63
+ start_period: startPeriod,
64
+ },
65
+ };
66
+ }
67
+
68
+ /**
69
+ * Set resource limits for a service
70
+ * @param {Object} options - Resource limit options
71
+ * @param {string} [options.memory] - Memory limit (e.g., '512M')
72
+ * @param {string} [options.cpus] - CPU limit (e.g., '0.5')
73
+ * @returns {Object} Service configuration with resource limits
74
+ */
75
+ export function setResourceLimits(options = {}) {
76
+ const { memory, cpus } = options;
77
+
78
+ const limits = {};
79
+ const reservations = {};
80
+
81
+ if (memory) {
82
+ limits.memory = memory;
83
+ // Reserve half of the limit by default
84
+ reservations.memory = memory;
85
+ }
86
+
87
+ if (cpus) {
88
+ limits.cpus = cpus;
89
+ }
90
+
91
+ return {
92
+ deploy: {
93
+ resources: {
94
+ limits,
95
+ reservations,
96
+ },
97
+ },
98
+ };
99
+ }
100
+
101
+ /**
102
+ * Configure logging for a service
103
+ * @param {Object} options - Logging options
104
+ * @param {string} [options.driver='json-file'] - Logging driver
105
+ * @param {string} [options.maxSize='10m'] - Max log file size
106
+ * @param {string} [options.maxFile='3'] - Max number of log files
107
+ * @returns {Object} Service configuration with logging
108
+ */
109
+ export function configureLogging(options = {}) {
110
+ const {
111
+ driver = 'json-file',
112
+ maxSize = '10m',
113
+ maxFile = '3',
114
+ } = options;
115
+
116
+ return {
117
+ logging: {
118
+ driver,
119
+ options: {
120
+ 'max-size': maxSize,
121
+ 'max-file': maxFile,
122
+ },
123
+ },
124
+ };
125
+ }
126
+
127
+ /**
128
+ * Create a Docker Compose orchestrator
129
+ * @returns {Object} Compose orchestrator with methods
130
+ */
131
+ export function createComposeOrchestrator() {
132
+ const services = {};
133
+ let composeVersion = '3.8';
134
+
135
+ return {
136
+ /**
137
+ * Add a service to the compose configuration
138
+ * @param {string} name - Service name
139
+ * @param {Object} config - Service configuration
140
+ */
141
+ addService(name, config = {}) {
142
+ services[name] = {
143
+ image: config.image || `${name}:latest`,
144
+ restart: 'always',
145
+ ...config,
146
+ };
147
+ },
148
+
149
+ /**
150
+ * Set the compose file version
151
+ * @param {string} version - Compose version
152
+ */
153
+ setVersion(version) {
154
+ composeVersion = version;
155
+ },
156
+
157
+ /**
158
+ * Generate the complete Docker Compose configuration
159
+ * @returns {string} Docker Compose YAML
160
+ */
161
+ generate() {
162
+ const compose = {
163
+ version: composeVersion,
164
+ services,
165
+ networks: {
166
+ default: {
167
+ driver: 'bridge',
168
+ },
169
+ },
170
+ };
171
+
172
+ return YAML.dump(compose);
173
+ },
174
+
175
+ /**
176
+ * Get all configured services
177
+ * @returns {Object} Services configuration
178
+ */
179
+ getServices() {
180
+ return { ...services };
181
+ },
182
+
183
+ /**
184
+ * Add health check to a service
185
+ * @param {string} serviceName - Service name
186
+ * @param {Object} healthCheckOptions - Health check options
187
+ */
188
+ addHealthCheck(serviceName, healthCheckOptions) {
189
+ if (services[serviceName]) {
190
+ const healthConfig = addHealthCheck(healthCheckOptions);
191
+ services[serviceName] = { ...services[serviceName], ...healthConfig };
192
+ }
193
+ },
194
+
195
+ /**
196
+ * Set resource limits for a service
197
+ * @param {string} serviceName - Service name
198
+ * @param {Object} resourceOptions - Resource limit options
199
+ */
200
+ setResourceLimits(serviceName, resourceOptions) {
201
+ if (services[serviceName]) {
202
+ const resourceConfig = setResourceLimits(resourceOptions);
203
+ services[serviceName] = { ...services[serviceName], ...resourceConfig };
204
+ }
205
+ },
206
+
207
+ /**
208
+ * Configure logging for a service
209
+ * @param {string} serviceName - Service name
210
+ * @param {Object} loggingOptions - Logging options
211
+ */
212
+ configureLogging(serviceName, loggingOptions) {
213
+ if (services[serviceName]) {
214
+ const loggingConfig = configureLogging(loggingOptions);
215
+ services[serviceName] = { ...services[serviceName], ...loggingConfig };
216
+ }
217
+ },
218
+ };
219
+ }
@@ -0,0 +1,50 @@
1
+ /**
2
+ * Docker Compose Orchestrator Tests
3
+ */
4
+ import { describe, it, expect } from 'vitest';
5
+ import { generateProductionCompose, addHealthCheck, setResourceLimits, configureLogging, createComposeOrchestrator } from './compose-orchestrator.js';
6
+
7
+ describe('compose-orchestrator', () => {
8
+ describe('generateProductionCompose', () => {
9
+ it('generates production compose file', () => {
10
+ const config = generateProductionCompose({ services: ['app', 'db'] });
11
+ expect(config).toContain('version:');
12
+ expect(config).toContain('services:');
13
+ });
14
+
15
+ it('sets restart policy', () => {
16
+ const config = generateProductionCompose({ services: ['app'] });
17
+ expect(config).toContain('restart: always');
18
+ });
19
+ });
20
+
21
+ describe('addHealthCheck', () => {
22
+ it('adds health check config', () => {
23
+ const config = addHealthCheck({ test: 'curl -f http://localhost', interval: '30s' });
24
+ expect(config.healthcheck).toBeDefined();
25
+ expect(config.healthcheck.test).toContain('curl');
26
+ });
27
+ });
28
+
29
+ describe('setResourceLimits', () => {
30
+ it('sets memory limits', () => {
31
+ const config = setResourceLimits({ memory: '512M', cpus: '0.5' });
32
+ expect(config.deploy.resources.limits.memory).toBe('512M');
33
+ });
34
+ });
35
+
36
+ describe('configureLogging', () => {
37
+ it('configures logging driver', () => {
38
+ const config = configureLogging({ driver: 'json-file', maxSize: '10m' });
39
+ expect(config.logging.driver).toBe('json-file');
40
+ });
41
+ });
42
+
43
+ describe('createComposeOrchestrator', () => {
44
+ it('creates orchestrator', () => {
45
+ const orchestrator = createComposeOrchestrator();
46
+ expect(orchestrator.generate).toBeDefined();
47
+ expect(orchestrator.addService).toBeDefined();
48
+ });
49
+ });
50
+ });
@@ -0,0 +1,208 @@
1
+ /**
2
+ * Database Configuration Generator
3
+ * PostgreSQL and Redis configuration
4
+ */
5
+
6
+ /**
7
+ * Generate PostgreSQL configuration
8
+ * @param {Object} options - PostgreSQL configuration options
9
+ * @param {boolean} [options.ssl=false] - Enable SSL
10
+ * @param {number} [options.maxConnections=100] - Maximum connections
11
+ * @param {string} [options.sharedBuffers='256MB'] - Shared buffers size
12
+ * @param {string} [options.workMem='4MB'] - Work memory size
13
+ * @returns {string} PostgreSQL configuration
14
+ */
15
+ export function generatePostgresConfig(options = {}) {
16
+ const {
17
+ ssl = false,
18
+ maxConnections = 100,
19
+ sharedBuffers = '256MB',
20
+ workMem = '4MB',
21
+ effectiveCacheSize = '1GB',
22
+ maintenanceWorkMem = '64MB',
23
+ } = options;
24
+
25
+ const lines = [
26
+ '# PostgreSQL Configuration',
27
+ '# Generated by TLC Database Config',
28
+ '',
29
+ '# Connection Settings',
30
+ `max_connections = ${maxConnections}`,
31
+ '',
32
+ '# Memory Settings',
33
+ `shared_buffers = ${sharedBuffers}`,
34
+ `work_mem = ${workMem}`,
35
+ `effective_cache_size = ${effectiveCacheSize}`,
36
+ `maintenance_work_mem = ${maintenanceWorkMem}`,
37
+ '',
38
+ '# SSL Configuration',
39
+ `ssl = ${ssl ? 'on' : 'off'}`,
40
+ ];
41
+
42
+ if (ssl) {
43
+ lines.push("ssl_cert_file = '/etc/ssl/certs/server.crt'");
44
+ lines.push("ssl_key_file = '/etc/ssl/private/server.key'");
45
+ }
46
+
47
+ lines.push('');
48
+ lines.push('# Logging');
49
+ lines.push("log_destination = 'stderr'");
50
+ lines.push('logging_collector = on');
51
+ lines.push("log_directory = 'pg_log'");
52
+ lines.push("log_filename = 'postgresql-%Y-%m-%d_%H%M%S.log'");
53
+ lines.push('');
54
+ lines.push('# Performance');
55
+ lines.push('checkpoint_completion_target = 0.9');
56
+ lines.push('wal_buffers = 16MB');
57
+ lines.push('default_statistics_target = 100');
58
+
59
+ return lines.join('\n');
60
+ }
61
+
62
+ /**
63
+ * Generate pg_hba.conf configuration
64
+ * @param {Object} options - pg_hba configuration options
65
+ * @param {Array} options.rules - Authentication rules
66
+ * @returns {string} pg_hba.conf configuration
67
+ */
68
+ export function generatePgHba(options = {}) {
69
+ const { rules = [] } = options;
70
+
71
+ const lines = [
72
+ '# PostgreSQL Client Authentication Configuration',
73
+ '# Generated by TLC Database Config',
74
+ '',
75
+ '# TYPE DATABASE USER ADDRESS METHOD',
76
+ '',
77
+ '# Local connections',
78
+ 'local all all peer',
79
+ 'local all postgres peer',
80
+ '',
81
+ '# IPv4 local connections',
82
+ 'host all all 127.0.0.1/32 scram-sha-256',
83
+ '',
84
+ '# IPv6 local connections',
85
+ 'host all all ::1/128 scram-sha-256',
86
+ '',
87
+ '# Custom rules',
88
+ ];
89
+
90
+ for (const rule of rules) {
91
+ const { type, database, user, address, method } = rule;
92
+ lines.push(`${type}\t${database}\t\t${user}\t\t${address}\t\t${method}`);
93
+ }
94
+
95
+ return lines.join('\n');
96
+ }
97
+
98
+ /**
99
+ * Generate Redis configuration
100
+ * @param {Object} options - Redis configuration options
101
+ * @param {string} [options.requirepass] - Password for authentication
102
+ * @param {boolean} [options.tls=false] - Enable TLS
103
+ * @param {number} [options.maxmemory] - Maximum memory in bytes
104
+ * @param {string} [options.maxmemoryPolicy='allkeys-lru'] - Eviction policy
105
+ * @returns {string} Redis configuration
106
+ */
107
+ export function generateRedisConfig(options = {}) {
108
+ const {
109
+ requirepass,
110
+ tls = false,
111
+ maxmemory,
112
+ maxmemoryPolicy = 'allkeys-lru',
113
+ port = 6379,
114
+ bind = '127.0.0.1',
115
+ } = options;
116
+
117
+ const lines = [
118
+ '# Redis Configuration',
119
+ '# Generated by TLC Database Config',
120
+ '',
121
+ '# Network',
122
+ `bind ${bind}`,
123
+ `port ${tls ? 0 : port}`,
124
+ 'protected-mode yes',
125
+ '',
126
+ ];
127
+
128
+ if (tls) {
129
+ lines.push('# TLS Configuration');
130
+ lines.push(`tls-port ${port}`);
131
+ lines.push('tls-cert-file /etc/redis/redis.crt');
132
+ lines.push('tls-key-file /etc/redis/redis.key');
133
+ lines.push('tls-ca-cert-file /etc/redis/ca.crt');
134
+ lines.push('');
135
+ }
136
+
137
+ if (requirepass) {
138
+ lines.push('# Security');
139
+ lines.push(`requirepass ${requirepass}`);
140
+ lines.push('');
141
+ }
142
+
143
+ lines.push('# Memory Management');
144
+ if (maxmemory) {
145
+ lines.push(`maxmemory ${maxmemory}`);
146
+ }
147
+ lines.push(`maxmemory-policy ${maxmemoryPolicy}`);
148
+ lines.push('');
149
+
150
+ lines.push('# Persistence');
151
+ lines.push('appendonly yes');
152
+ lines.push('appendfsync everysec');
153
+ lines.push('');
154
+
155
+ lines.push('# Logging');
156
+ lines.push('loglevel notice');
157
+ lines.push('logfile /var/log/redis/redis-server.log');
158
+
159
+ return lines.join('\n');
160
+ }
161
+
162
+ /**
163
+ * Create a database configuration manager
164
+ * @returns {Object} Database config manager with methods
165
+ */
166
+ export function createDatabaseConfig() {
167
+ return {
168
+ /**
169
+ * Generate PostgreSQL configuration
170
+ * @param {Object} options - PostgreSQL options
171
+ * @returns {string} PostgreSQL configuration
172
+ */
173
+ generatePostgres(options = {}) {
174
+ return generatePostgresConfig(options);
175
+ },
176
+
177
+ /**
178
+ * Generate pg_hba.conf configuration
179
+ * @param {Object} options - pg_hba options
180
+ * @returns {string} pg_hba configuration
181
+ */
182
+ generatePgHba(options = {}) {
183
+ return generatePgHba(options);
184
+ },
185
+
186
+ /**
187
+ * Generate Redis configuration
188
+ * @param {Object} options - Redis options
189
+ * @returns {string} Redis configuration
190
+ */
191
+ generateRedis(options = {}) {
192
+ return generateRedisConfig(options);
193
+ },
194
+
195
+ /**
196
+ * Generate all database configurations
197
+ * @param {Object} options - Configuration options
198
+ * @returns {Object} All generated configurations
199
+ */
200
+ generateAll(options = {}) {
201
+ return {
202
+ postgres: generatePostgresConfig(options.postgres || {}),
203
+ pgHba: generatePgHba(options.pgHba || {}),
204
+ redis: generateRedisConfig(options.redis || {}),
205
+ };
206
+ },
207
+ };
208
+ }
@@ -0,0 +1,47 @@
1
+ /**
2
+ * Database Configuration Tests
3
+ */
4
+ import { describe, it, expect } from 'vitest';
5
+ import { generatePostgresConfig, generatePgHba, generateRedisConfig, createDatabaseConfig } from './database-config.js';
6
+
7
+ describe('database-config', () => {
8
+ describe('generatePostgresConfig', () => {
9
+ it('enables SSL', () => {
10
+ const config = generatePostgresConfig({ ssl: true });
11
+ expect(config).toContain('ssl = on');
12
+ });
13
+
14
+ it('configures connection pooling', () => {
15
+ const config = generatePostgresConfig({ maxConnections: 100 });
16
+ expect(config).toContain('max_connections = 100');
17
+ });
18
+ });
19
+
20
+ describe('generatePgHba', () => {
21
+ it('configures authentication rules', () => {
22
+ const config = generatePgHba({ rules: [{ type: 'host', database: 'all', user: 'all', address: '0.0.0.0/0', method: 'md5' }] });
23
+ expect(config).toContain('host');
24
+ expect(config).toContain('md5');
25
+ });
26
+ });
27
+
28
+ describe('generateRedisConfig', () => {
29
+ it('enables auth', () => {
30
+ const config = generateRedisConfig({ requirepass: 'secret' });
31
+ expect(config).toContain('requirepass');
32
+ });
33
+
34
+ it('enables TLS', () => {
35
+ const config = generateRedisConfig({ tls: true });
36
+ expect(config).toContain('tls-port');
37
+ });
38
+ });
39
+
40
+ describe('createDatabaseConfig', () => {
41
+ it('creates config manager', () => {
42
+ const manager = createDatabaseConfig();
43
+ expect(manager.generatePostgres).toBeDefined();
44
+ expect(manager.generateRedis).toBeDefined();
45
+ });
46
+ });
47
+ });