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