1 | 'use strict';
|
2 |
|
3 | let cli = require('heroku-cli-util');
|
4 | let co = require('co');
|
5 | let lib = require('../../lib');
|
6 |
|
7 | let empty = o => Object.keys(o).length === 0;
|
8 |
|
9 | function getUpdates (o) {
|
10 | let updates = {};
|
11 |
|
12 | if (o.url) updates.redirect_uri = lib.validateURL(o.url);
|
13 | if (o.name) updates.name = o.name;
|
14 |
|
15 | if (empty(updates)) throw new Error('No changes provided');
|
16 | return updates;
|
17 | }
|
18 |
|
19 | function* run (context, heroku) {
|
20 | let id = context.args.id;
|
21 | let request = heroku.request({
|
22 | method: 'PATCH',
|
23 | path: `/oauth/clients/${encodeURIComponent(id)}`,
|
24 | body: getUpdates(context.flags),
|
25 | });
|
26 |
|
27 | yield cli.action(`Updating ${cli.color.cyan(id)}`, request);
|
28 | }
|
29 |
|
30 | module.exports = {
|
31 | topic: 'clients',
|
32 | command: 'update',
|
33 | description: '(sudo) update OAuth client',
|
34 | args: [{name: 'id'}],
|
35 | flags: [
|
36 | {name: 'name', char: 'n', hasValue: true, description: 'change the client name'},
|
37 | {name: 'url', hasValue: true, description: 'change the client redirect URL'},
|
38 | ],
|
39 | needsAuth: true,
|
40 | run: cli.command(co.wrap(run))
|
41 | };
|