|
| 1 | +'use strict'; |
| 2 | + |
| 3 | +var method = require('./../method'); |
| 4 | +var assign = require('lodash.assign'); |
| 5 | + |
| 6 | +/** |
| 7 | + * @memberof resourceDelegations |
| 8 | + * @method create |
| 9 | + * @description Create resourceDelegation with limited access, e.g. for users who needs to stream a machine you created. |
| 10 | + * The create method takes a delegation object as the only argument with resource name as key and an object with ids to list resource ids to give access to. |
| 11 | + * @param {object} [delegation] - A delegation object to grant access to reources |
| 12 | + * @param {object} [delegation.machine] - Optional resource 'machine' to grant access to. |
| 13 | + * @param {array} [delegation.machine.ids] - Optional list of machine ids to grant access to. |
| 14 | + * @param {function} cb - Node-style error-first callback function |
| 15 | + * @returns {object} { |
| 16 | + * delegation: { machine: ['m123abc', 'm456def', ... ] }, |
| 17 | + * accessToken: 'resource-delegation-token-123abc...', |
| 18 | + * ... |
| 19 | + * } - JSON object with provided delegation and newly generated resourceDelegation accessToken |
| 20 | + * @example |
| 21 | + * var delegation = { |
| 22 | + * machine: { |
| 23 | + * ids: ['m123abc', 'm456def'] |
| 24 | + * } |
| 25 | + * }; |
| 26 | + * paperspace.resourceDelegations.create(delegation, function(err, res) { |
| 27 | + * // handle error or result |
| 28 | + * }); |
| 29 | + * @example |
| 30 | + * $ paperspace resourceDelegations create |
| 31 | + * @example |
| 32 | + * # HTTP request: |
| 33 | + * https://api.paperspace.io |
| 34 | + * POST /resourceDelegations/create |
| 35 | + * x-api-key: 1ba4f98e7c0... |
| 36 | + * { |
| 37 | + "machine": { |
| 38 | + "ids": ["m123abc", "m456def"] |
| 39 | + } |
| 40 | +} |
| 41 | + * # Returns 200 on success |
| 42 | + * @example |
| 43 | + * // Example return value: |
| 44 | + * [ |
| 45 | + * { |
| 46 | + * "delegation": { |
| 47 | + * "machine": { |
| 48 | + * "ids": [ |
| 49 | + * "m123abc", |
| 50 | + * "m456def" |
| 51 | + * ] |
| 52 | + * } |
| 53 | + * }, |
| 54 | + * "isEnabled": true, |
| 55 | + * "accessTokenId": "resource-delegation-token-123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc", |
| 56 | + * "dtCreated": "2019-04-03T12:31:40.061Z", |
| 57 | + * "id": 123 |
| 58 | + * } |
| 59 | + * ] |
| 60 | + */ |
| 61 | + |
| 62 | +function create(params, cb) { |
| 63 | + return method(create, params, cb); |
| 64 | +} |
| 65 | + |
| 66 | +assign(create, { |
| 67 | + auth: true, |
| 68 | + group: 'resourceDelegations', |
| 69 | + name: 'create', |
| 70 | + method: 'post', |
| 71 | + route: '/resourceDelegations/create', |
| 72 | + requires: {}, |
| 73 | + returns: {}, |
| 74 | +}); |
| 75 | + |
| 76 | +module.exports = create; |
0 commit comments