Skip to content

API Examples

Common API usage patterns with SDK examples.

const hosts = await client.ssh.listHosts({
limit: 100,
filter: {
labels: { environment: 'production' }
}
});
const host = await client.ssh.addHost({
hostname: 'server01.example.com',
port: 22,
labels: {
environment: 'production',
team: 'platform'
}
});
await client.ssh.updateHost({
hostId: 'host_abc123',
labels: {
environment: 'staging'
}
});
const scan = await client.ssh.startDiscovery({
hosts: ['server01.example.com', 'server02.example.com'],
scanType: 'full'
});
console.log(`Scan ID: ${scan.id}`);
const status = await client.ssh.getScanStatus(scan.id);
if (status.state === 'completed') {
console.log(`Found ${status.keysDiscovered} keys`);
}
const keys = await client.ssh.listKeys({
scanId: scan.id,
riskScoreMin: 50 // Only high-risk keys
});
const rotation = await client.ssh.rotateKey({
keyId: 'key_abc123',
algorithm: 'ed25519',
reason: 'Scheduled rotation'
});
const bulk = await client.ssh.bulkRotate({
filter: {
algorithm: ['dsa', 'rsa-1024'],
ageGreaterThan: '365d'
},
dryRun: false
});
console.log(`Rotating ${bulk.keysAffected} keys`);
const ephemeral = await client.ssh.requestEphemeral({
host: 'server01.example.com',
username: 'deploy',
ttl: 300, // 5 minutes
reason: 'Deploy v2.0.0'
});
console.log('Private Key:', ephemeral.privateKey);
console.log('Expires:', ephemeral.expiresAt);
await client.ssh.revokeEphemeral({
ephemeralId: ephemeral.id,
reason: 'Access no longer needed'
});
const policy = await client.ssh.createPolicy({
name: 'Production 90-day rotation',
type: 'rotation',
rules: {
interval: '90d',
algorithm: 'ed25519',
hosts: { labels: { environment: 'production' } }
}
});
try {
await client.ssh.rotateKey({ keyId: 'invalid' });
} catch (error) {
if (error.code === 'NOT_FOUND') {
console.log('Key not found');
} else if (error.code === 'RATE_LIMITED') {
console.log('Too many requests, retry after:', error.retryAfter);
}
}