/// declare class Provisioner { private dispatch_; private state_; constructor(dispatch_: Function, state_?: any); /** * One-click setup of a VM * See freedom-module.json for return and error types * @param {String} name of VM to create * @param {String} region to create VM in * @return {Promise.} */ start: (name: string, region?: string, image?: string, size?: string) => Promise; /** * One-click destruction of a VM * @param {String} name of VM to create * @return {Promise.} */ stop: (name: string) => Promise; /** * Destroys cloud server; assumes OAuth has already been completed * This method will use this.waitDigitalOceanActions_() to wait until the server is deleted * @param {String} droplet name, as a string * @return {Promise.} */ private destroyServer_; /** * Reboots a droplet with this name * @param {String} droplet name, as a string * @return {Promise.}, resolves after waiting for reboot action * to complete or rejects if droplet doesn't exist */ reboot: (name: string) => Promise; private getDropletByName_; /** * Generates an RSA keypair using forge * @return {KeyPair} public and private SSH keys */ private static generateKeyPair_; /** * Dispatches status events * events listed in STATUS_CODES * @param {String} code one of STATUS_CODES */ private sendStatus_; /** * Initiates a Digital Ocean oAuth flow * @return {Promise.} oAuth response from Digital Ocean * { * access_token: '..', * expires_in: '..', * state: '..', * token_type: '..' * } */ private doOAuth_; /** * Retrieves an SSH keypair from storage, generating and saving * a new keypair if none is found. * @param {String} name name of the key * @return {Promise.} * @throws if there is any problem loading from or saving to * storage or if a keypair cannot be generated */ private getSshKey_; /** * Make a request to Digital Ocean * @param {String} method - GET/POST/DELETE etc * @param {String} actionPath - e.g. 'droplets/' * @param {String} body - if POST, contents to post * @return {Promise.} - JSON object of response body */ private doRequest_; /** * Waits for all in-progress Digital Ocean actions to complete * e.g. after powering on a machine, or creating a VM */ private waitDigitalOceanActions_; /** * Properly configure Digital Ocean with a single droplet of name:name * Assumes we already have oAuth token and SSH key in this.state_ * This method will use this.waitDigitalOceanActions_() to wait until all actions complete * before resolving * @param {String} name of droplet * @param {String} region to create VM in * @return {Promise.} resolves on success, rejects on failure */ private setupDigitalOcean_; } export = Provisioner;