adapterExecutor.ts 1.2 KB

12345678910111213141516171819
  1. import {mkdirSync,lstatSync} from 'node:fs'
  2. import type {CredentialExecutor,IsolationGate} from './executor.js'
  3. import type {VaultEntry,LeaseInput} from './schema.js'
  4. import {WebsiteFormExecutor} from './websiteExecutor.js'
  5. import {SshSftpExecutor} from './sshExecutor.js'
  6. /** Shared bounded protocols. The boot path determines the deployment boundary. */
  7. export abstract class CredentialAdapterExecutor implements CredentialExecutor {
  8. abstract readonly mode:'protected-adapters'|'local-adapters'
  9. private website:WebsiteFormExecutor
  10. private ssh:SshSftpExecutor
  11. constructor(home:string,private gate:IsolationGate,testCA?:Buffer){
  12. gate.assert();mkdirSync(home,{recursive:true,mode:0o700});const stat=lstatSync(home)
  13. if(!stat.isDirectory()||stat.isSymbolicLink()||(stat.mode&0o077)||stat.uid!==process.getuid?.())throw new Error('private executor home required')
  14. this.website=new WebsiteFormExecutor(home,gate,testCA);this.ssh=new SshSftpExecutor(gate)
  15. }
  16. assertAvailable(){this.gate.assert()}
  17. execute(entry:Readonly<VaultEntry>,input:LeaseInput,signal:AbortSignal){this.gate.assert();return entry.target.kind==='website'?this.website.execute(entry,input,signal):this.ssh.execute(entry,input,signal)}
  18. }