API Examples
API Examples
Section titled “API Examples”Common API usage patterns with SDK examples.
Host Management
Section titled “Host Management”List All Hosts
Section titled “List All Hosts”const hosts = await client.ssh.listHosts({ limit: 100, filter: { labels: { environment: 'production' } }});Add a Host
Section titled “Add a Host”const host = await client.ssh.addHost({ hostname: 'server01.example.com', port: 22, labels: { environment: 'production', team: 'platform' }});Update Host Labels
Section titled “Update Host Labels”await client.ssh.updateHost({ hostId: 'host_abc123', labels: { environment: 'staging' }});Key Discovery
Section titled “Key Discovery”Start Discovery Scan
Section titled “Start Discovery Scan”const scan = await client.ssh.startDiscovery({ hosts: ['server01.example.com', 'server02.example.com'], scanType: 'full'});
console.log(`Scan ID: ${scan.id}`);Check Scan Status
Section titled “Check Scan Status”const status = await client.ssh.getScanStatus(scan.id);
if (status.state === 'completed') { console.log(`Found ${status.keysDiscovered} keys`);}List Discovered Keys
Section titled “List Discovered Keys”const keys = await client.ssh.listKeys({ scanId: scan.id, riskScoreMin: 50 // Only high-risk keys});Key Rotation
Section titled “Key Rotation”Rotate Single Key
Section titled “Rotate Single Key”const rotation = await client.ssh.rotateKey({ keyId: 'key_abc123', algorithm: 'ed25519', reason: 'Scheduled rotation'});Bulk Rotation
Section titled “Bulk Rotation”const bulk = await client.ssh.bulkRotate({ filter: { algorithm: ['dsa', 'rsa-1024'], ageGreaterThan: '365d' }, dryRun: false});
console.log(`Rotating ${bulk.keysAffected} keys`);Ephemeral Access
Section titled “Ephemeral Access”Request Ephemeral Key
Section titled “Request Ephemeral Key”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);Revoke Ephemeral Key
Section titled “Revoke Ephemeral Key”await client.ssh.revokeEphemeral({ ephemeralId: ephemeral.id, reason: 'Access no longer needed'});Policies
Section titled “Policies”Create Rotation Policy
Section titled “Create Rotation Policy”const policy = await client.ssh.createPolicy({ name: 'Production 90-day rotation', type: 'rotation', rules: { interval: '90d', algorithm: 'ed25519', hosts: { labels: { environment: 'production' } } }});Error Handling
Section titled “Error Handling”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); }}