From 55c61584f29d0bb7302cfb7e1596a09064d4dc7b Mon Sep 17 00:00:00 2001 From: Dillon Erb Date: Wed, 2 Sep 2020 15:37:31 -0400 Subject: [PATCH 1/3] feat(machine-access): new setAccessForUser method to add/remove users to machines --- lib/machines/index.js | 1 + lib/machines/setAccessForUser.js | 129 +++++++++++++++++++++++++++++++ 2 files changed, 130 insertions(+) create mode 100644 lib/machines/setAccessForUser.js diff --git a/lib/machines/index.js b/lib/machines/index.js index e7de981..911dcb7 100644 --- a/lib/machines/index.js +++ b/lib/machines/index.js @@ -16,4 +16,5 @@ module.exports = { update: require('./update'), utilization: require('./utilization'), waitfor: require('./waitfor'), + setAccessForUser: require('./setAccessForUser'), }; diff --git a/lib/machines/setAccessForUser.js b/lib/machines/setAccessForUser.js new file mode 100644 index 0000000..500df21 --- /dev/null +++ b/lib/machines/setAccessForUser.js @@ -0,0 +1,129 @@ +'use strict'; + +var method = require('./../method'); +var assign = require('lodash.assign'); + +/** + * @memberof machines + * @method setAccessForUser + * @description Show machine information for the machine with the given id. + * + * The state property can take on the follow values: + * - off + * - starting - machine is in the process of changing to the ready or serviceready state + * - stopping - machine is in the process of changing to the off state + * - restarting - combines stopping follow immediately by starting + * - serviceready - services are running on the machine but the Paperspace agent is not yet available + * - ready - services are running on machine and the Paperspace agent is ready to stream or accept logins + * - upgrading - the machine specification are being upgraded, which involves a shutdown and startup sequence + * - provisioning - the machine is in the process of being created for the first time + * + * The updatesPending property is either true or false and reflects whether the operating system has scheduled updates + * for the next machine state transition, e.g, stopping, starting, restarting or upgrading. + * + * Note: in some cases the operating system can force installation of critical updates immediately upon a state + * transition, or automatically restart a machine to install updates. In such cases the updatesPending property + * may not always be set accurately by the underlying os. + * @param {object} params - Machine show parameters + * @param {string} params.machineId - Id of the machine to show + * @param {string} params.userId - Id of the user to enable machine access for + * @param {boolean} params.enabeAccess- releases any assigned public ip address for the machine; defaults to false + * @param {function} cb - Node-style error-first callback function + * @returns {object} machine - The machine JSON object + * @example + * paperspace.machines.setAccessForUser({ + * machineId: 'ps123abc', + * userId: 'u123abc, + * }, function(err, res) { + * // handle error or result + * }); + * @example + * $ paperspace machines show \ + * --machineId "ps123abc" + * @example + * # HTTP request: + * https://api.paperspace.io + * GET /machines/getMachinePublic?machineId=ps123abc + * x-api-key: 1ba4f98e7c0... + * # Returns 200 on success + * @example + * //Example return value: + * { + * "id": "ps123abc", + * "name": "My Machine", + * "os": "Microsoft Windows Server 2016 Datacenter", + * "ram": "8589938688", + * "cpus": 4, + * "gpu": "GRID K160Q (2GB)", + * "storageTotal": "53687091200", + * "storageUsed": "110080", + * "usageRate": "Air monthly", + * "shutdownTimeoutInHours": 168, + * "shutdownTimeoutForces": false, + * "performAutoSnapshot": false, + * "autoSnapshotFrequency": null, + * "autoSnapshotSaveCount": null, + * "agentType": "WindowsDesktop", + * "dtCreated": "2016-11-18T05:18:29.533Z", + * "state": "ready", + * "updatesPending": false, + * "networkId": "n789ghi", + * "privateIpAddress": "10.64.21.47", + * "publicIpAddress": null, + * "region": "East Coast (NY2)", + * "userId": "u123abc", + * "teamId": "te456def", + * "scriptId": "sc123abc", + * "dtLastRun": "2017-06-30T07:22:49.763Z", + * "dynamicPublicIp": null, + * "events": [ + * { + * "name": "start", + * "state": "done", + * "errorMsg": "", + * "handle": "8ebe43dd-57c8-4bd4-b770-86b7fd0202e4", + * "dtModified": "2017-08-16T14:36:24.802Z", + * "dtFinished": null, + * "dtCreated": "2017-08-16T14:36:18.373Z" + * }, + * { + * "name": "start", + * "state": "error", + * "errorMsg": "Uh oh. This machine type can't start due to insufficient capacity or higher than normal demand. Please try again later.", + * "handle": "f6adb486-f5ae-4ab3-9a1a-51c19df5b337", + * "dtModified": "2017-06-09T15:32:38.115Z", + * "dtFinished": "2017-06-09T15:32:38.115Z", + * "dtCreated": "2017-06-09T15:32:37.019Z" + * }, + * { + * "name": "stop", + * "state": "done", + * "errorMsg": "", + * "handle": "e352ad96-734f-4a26-8829-007c2f1d89f2", + * "dtModified": "2017-06-03T04:14:01.327Z", + * "dtFinished": null, + * "dtCreated": "2017-06-03T04:13:47.885Z" + * } + * ] + * } + */ + +function setAccessForUser(params, cb) { + return method(setAccessForUser, params, cb); +} + +assign(setAccessForUser, { + auth: true, + group: 'machines', + name: 'setAccessForUser', + method: 'post', + route: '/machines/:machineId/setMachineAccessPublic', + requires: { + machineId: 'string', + userId: "string", + enableAccess: 'boolean', + }, + returns: {}, +}); + +module.exports = setAccessForUser; From 02bcd1eb4c6f5b4583d197c11ae911440b546e1e Mon Sep 17 00:00:00 2001 From: Dillon Erb Date: Wed, 2 Sep 2020 17:14:36 -0400 Subject: [PATCH 2/3] fix(setAccessForUser): docs --- lib/machines/setAccessForUser.js | 67 ++------------------------------ 1 file changed, 3 insertions(+), 64 deletions(-) diff --git a/lib/machines/setAccessForUser.js b/lib/machines/setAccessForUser.js index 500df21..753d495 100644 --- a/lib/machines/setAccessForUser.js +++ b/lib/machines/setAccessForUser.js @@ -38,75 +38,14 @@ var assign = require('lodash.assign'); * // handle error or result * }); * @example - * $ paperspace machines show \ - * --machineId "ps123abc" + * $ paperspace machines setAccessForUser \ + * --machineId "ps123abc" --userId "u12abc" * @example * # HTTP request: * https://api.paperspace.io - * GET /machines/getMachinePublic?machineId=ps123abc + * GET /machines/:machineId/setMachineAccessPublic?userId=u123abc * x-api-key: 1ba4f98e7c0... * # Returns 200 on success - * @example - * //Example return value: - * { - * "id": "ps123abc", - * "name": "My Machine", - * "os": "Microsoft Windows Server 2016 Datacenter", - * "ram": "8589938688", - * "cpus": 4, - * "gpu": "GRID K160Q (2GB)", - * "storageTotal": "53687091200", - * "storageUsed": "110080", - * "usageRate": "Air monthly", - * "shutdownTimeoutInHours": 168, - * "shutdownTimeoutForces": false, - * "performAutoSnapshot": false, - * "autoSnapshotFrequency": null, - * "autoSnapshotSaveCount": null, - * "agentType": "WindowsDesktop", - * "dtCreated": "2016-11-18T05:18:29.533Z", - * "state": "ready", - * "updatesPending": false, - * "networkId": "n789ghi", - * "privateIpAddress": "10.64.21.47", - * "publicIpAddress": null, - * "region": "East Coast (NY2)", - * "userId": "u123abc", - * "teamId": "te456def", - * "scriptId": "sc123abc", - * "dtLastRun": "2017-06-30T07:22:49.763Z", - * "dynamicPublicIp": null, - * "events": [ - * { - * "name": "start", - * "state": "done", - * "errorMsg": "", - * "handle": "8ebe43dd-57c8-4bd4-b770-86b7fd0202e4", - * "dtModified": "2017-08-16T14:36:24.802Z", - * "dtFinished": null, - * "dtCreated": "2017-08-16T14:36:18.373Z" - * }, - * { - * "name": "start", - * "state": "error", - * "errorMsg": "Uh oh. This machine type can't start due to insufficient capacity or higher than normal demand. Please try again later.", - * "handle": "f6adb486-f5ae-4ab3-9a1a-51c19df5b337", - * "dtModified": "2017-06-09T15:32:38.115Z", - * "dtFinished": "2017-06-09T15:32:38.115Z", - * "dtCreated": "2017-06-09T15:32:37.019Z" - * }, - * { - * "name": "stop", - * "state": "done", - * "errorMsg": "", - * "handle": "e352ad96-734f-4a26-8829-007c2f1d89f2", - * "dtModified": "2017-06-03T04:14:01.327Z", - * "dtFinished": null, - * "dtCreated": "2017-06-03T04:13:47.885Z" - * } - * ] - * } - */ function setAccessForUser(params, cb) { return method(setAccessForUser, params, cb); From efda83b5b4a0611d5c1f75f3ee7df296a8963d2c Mon Sep 17 00:00:00 2001 From: Dillon Erb Date: Thu, 3 Sep 2020 11:50:48 -0400 Subject: [PATCH 3/3] lint --- lib/machines/setAccessForUser.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/machines/setAccessForUser.js b/lib/machines/setAccessForUser.js index 753d495..8551743 100644 --- a/lib/machines/setAccessForUser.js +++ b/lib/machines/setAccessForUser.js @@ -46,6 +46,7 @@ var assign = require('lodash.assign'); * GET /machines/:machineId/setMachineAccessPublic?userId=u123abc * x-api-key: 1ba4f98e7c0... * # Returns 200 on success + */ function setAccessForUser(params, cb) { return method(setAccessForUser, params, cb); @@ -56,7 +57,7 @@ assign(setAccessForUser, { group: 'machines', name: 'setAccessForUser', method: 'post', - route: '/machines/:machineId/setMachineAccessPublic', + route: '/machines/:machineId/setMachineAccess', requires: { machineId: 'string', userId: "string",