Skip to content

Commit 755b80c

Browse files
committed
feat: add SSH and Ansible configuration options, improve error handling, and enhance type safety in various services
1 parent 3b60fc2 commit 755b80c

File tree

7 files changed

+25
-17
lines changed

7 files changed

+25
-17
lines changed

.env.docker

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,12 @@ COMMAND_WHITELIST=["ls","pwd","whoami","uptime"]
4141
BOLT_EXECUTION_TIMEOUT=300000
4242
# Bolt project files can stay in the control repo or in a separate dir
4343
BOLT_PROJECT_PATH=/pabawi/control-repo
44+
45+
# SSH integration configuration
46+
SSH_ENABLED=true
47+
SSH_CONFIG_PATH=/pabawi/ssh/config
48+
# SSH_DEFAULT_USER=al
49+
50+
ANSIBLE_ENABLED=true
51+
ANSIBLE_PROJECT_PATH=/pabawi/ansible
52+
ANSIBLE_INVENTORY_PATH=inventory/hosts

backend/src/database/MigrationRunner.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,9 +210,7 @@ export class MigrationRunner {
210210

211211
// Execute each pending migration in order
212212
for (const migration of pendingMigrations) {
213-
console.log(`Applying migration: ${migration.filename}`);
214213
await this.executeMigration(migration);
215-
console.log(`✓ Migration ${migration.filename} applied successfully`);
216214
}
217215

218216
return pendingMigrations.length;

backend/src/integrations/ansible/AnsibleService.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -585,7 +585,7 @@ export class AnsibleService {
585585
const tempDir = mkdtempSync(join(tmpdir(), 'ansible-'));
586586
const inventoryPath = join(tempDir, 'inventory');
587587

588-
const user = process.env.ANSIBLE_REMOTE_USER || process.env.SSH_DEFAULT_USER || "root";
588+
const user = process.env.ANSIBLE_REMOTE_USER ?? process.env.SSH_DEFAULT_USER ?? "root";
589589

590590
// Create a simple INI-style inventory file
591591
const inventoryContent = `[adhoc]
@@ -606,7 +606,7 @@ ${hostname} ansible_connection=ssh ansible_user=${user}
606606
// Also try to remove the temp directory
607607
const tempDir = join(inventoryPath, '..');
608608
unlinkSync(tempDir);
609-
} catch (error) {
609+
} catch {
610610
// Ignore cleanup errors
611611
}
612612
}

backend/src/integrations/puppetdb/PuppetDBService.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -635,6 +635,7 @@ export class PuppetDBService
635635
complete({ cached: false, groupCount: 0 });
636636
return [];
637637
}
638+
const client = this.client;
638639

639640
try {
640641
// Check cache first
@@ -651,7 +652,7 @@ export class PuppetDBService
651652
// Query 1: Group by environment
652653
try {
653654
const envResult = await this.executeWithResilience(async () => {
654-
return await this.client!.query("pdb/query/v4/nodes", undefined);
655+
return await client.query("pdb/query/v4/nodes", undefined);
655656
});
656657

657658
if (Array.isArray(envResult)) {
@@ -665,7 +666,7 @@ export class PuppetDBService
665666
// Query 2: Group by OS family (from facts)
666667
try {
667668
const osResult = await this.executeWithResilience(async () => {
668-
return await this.client!.query(
669+
return await client.query(
669670
"pdb/query/v4/nodes",
670671
JSON.stringify(["extract", ["certname", ["fact", "os.family"]]])
671672
);

backend/src/integrations/ssh/SSHPlugin.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ export class SSHPlugin extends BasePlugin implements ExecutionToolPlugin, Inform
226226
if (hosts.length === 0) {
227227
return {
228228
id: executionId,
229-
type: action.type,
229+
type: 'command',
230230
targetNodes: targets,
231231
action: action.action,
232232
parameters: action.parameters,
@@ -275,7 +275,7 @@ export class SSHPlugin extends BasePlugin implements ExecutionToolPlugin, Inform
275275

276276
return {
277277
id: executionId,
278-
type: action.type,
278+
type: 'command',
279279
targetNodes: targets,
280280
action: action.action,
281281
parameters: action.parameters,
@@ -289,7 +289,7 @@ export class SSHPlugin extends BasePlugin implements ExecutionToolPlugin, Inform
289289
} catch (error) {
290290
return {
291291
id: executionId,
292-
type: action.type,
292+
type: 'command',
293293
targetNodes: Array.isArray(action.target) ? action.target : [action.target],
294294
action: action.action,
295295
parameters: action.parameters,
@@ -1028,16 +1028,16 @@ export class SSHPlugin extends BasePlugin implements ExecutionToolPlugin, Inform
10281028
}
10291029

10301030
// Use configured default user if no user specified
1031-
const defaultUser = this.sshConfig?.defaultUser || 'root';
1032-
const finalUser = user || defaultUser;
1031+
const defaultUser = this.sshConfig?.defaultUser ?? 'root';
1032+
const finalUser = user ?? defaultUser;
10331033

10341034
return {
10351035
name: hostname,
1036-
uri: `ssh://${finalUser}@${hostname}${port ? `:${port}` : ''}`,
1036+
uri: `ssh://${finalUser}@${hostname}${port ? `:${String(port)}` : ''}`,
10371037
user: finalUser,
1038-
port: port || 22,
1038+
port: port ?? 22,
10391039
};
1040-
} catch (error) {
1040+
} catch {
10411041
// Invalid host string format
10421042
return null;
10431043
}

backend/src/middleware/securityMiddleware.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ export function createRateLimitMiddleware(): (req: Request, res: Response, next:
6969
}
7070

7171
// For unauthenticated requests, use IP address with proper IPv6 handling
72-
return ipKeyGenerator(req);
72+
return ipKeyGenerator(req.ip ?? req.socket.remoteAddress ?? "");
7373
},
7474

7575
// Skip rate limiting for health check and public endpoints
@@ -116,7 +116,7 @@ export function createAuthRateLimitMiddleware(): (req: Request, res: Response, n
116116
legacyHeaders: false,
117117

118118
// Use IP address as the key with proper IPv6 handling
119-
keyGenerator: ipKeyGenerator,
119+
keyGenerator: (req: Request): string => ipKeyGenerator(req.ip ?? req.socket.remoteAddress ?? ""),
120120

121121
// Custom handler for rate limit exceeded
122122
handler: (_req: Request, res: Response): void => {

backend/src/server.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -625,7 +625,7 @@ async function startServer(): Promise<Express> {
625625
enabled: true,
626626
name: "ssh",
627627
type: "both",
628-
config: sshConfig as Record<string, unknown>,
628+
config: sshConfig as unknown as Record<string, unknown>,
629629
priority: sshConfig.priority,
630630
};
631631

0 commit comments

Comments
 (0)