@heroku/skynet 1.6.16 → 1.6.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,6 +2,7 @@ const cli = require('heroku-cli-util')
2
2
  const command = require('../lib/command')
3
3
  const sudo = require('../lib/sudo')
4
4
  const SkynetAPI = require('../lib/skynet')
5
+ const notifyOption = require('../lib/notifyOption')
5
6
 
6
7
  async function run (context) {
7
8
  sudo()
@@ -10,7 +11,9 @@ async function run (context) {
10
11
  const notes = context.flags.notes
11
12
  const category = context.flags.category
12
13
  const force = context.flags.bypass
13
- const notify = !context.flags['no-notify']
14
+
15
+ const notify = notifyOption.set(context.flags.notify, context.flags['no-notify'])
16
+ const notificationStatus = (notify) ? 'enabled' : 'disabled'
14
17
 
15
18
  if (!user) {
16
19
  throw new Error('Required flag: --user USER')
@@ -18,7 +21,7 @@ async function run (context) {
18
21
 
19
22
  let response = await cli.action(`deprovisioning ${cli.color.cyan(user)}`, skynet.deprovision(user, notes, category, notify, force))
20
23
  response = JSON.parse(response)
21
- cli.log(`${response.status}. ${response.message}`)
24
+ cli.log(`${response.status}. ${response.message}. Notification ${notificationStatus}`)
22
25
  }
23
26
 
24
27
  module.exports = {
@@ -32,6 +35,7 @@ module.exports = {
32
35
  { name: 'category', char: 'c', description: 'suspension category', hasValue: true, required: true },
33
36
  { name: 'notes', char: 'n', description: 'suspend notes', hasValue: true, required: true },
34
37
  { name: 'bypass', description: 'bypass the whitelist', hasValue: false, required: false },
38
+ { name: 'notify', description: 'send user suspension email notification', hasValue: false, required: false },
35
39
  { name: 'no-notify', description: 'skip user suspension email notification', hasValue: false, required: false }
36
40
  ],
37
41
  run: command(run)
@@ -2,6 +2,8 @@ const cli = require('heroku-cli-util')
2
2
  const command = require('../../lib/command')
3
3
  const sudo = require('../../lib/sudo')
4
4
  const SkynetAPI = require('../../lib/skynet')
5
+ const HerokuAPI = require('../../lib/heroku')
6
+ const notifyOption = require('../../lib/notifyOption')
5
7
 
6
8
  function readlines (file) {
7
9
  return new Promise(function (resolve, reject) {
@@ -26,15 +28,24 @@ function readlines (file) {
26
28
  })
27
29
  }
28
30
 
31
+ async function unverifyUser (api, user) {
32
+ const resMsg = await api.unverifyUser(user)
33
+ cli.log('Unverify ' + user + ': ' + resMsg)
34
+ }
35
+
29
36
  async function run (context) {
30
37
  sudo()
31
38
  const skynet = new SkynetAPI(context.auth.password)
39
+ const api = new HerokuAPI(context.auth.password)
32
40
  const user = context.flags.user || process.env.HEROKU_USER
33
41
  const file = context.flags.infile
34
42
  const notes = context.flags.notes
35
43
  const category = context.flags.category
36
44
  const force = context.flags.bypass
37
- const notify = !context.flags['no-notify']
45
+ const unverify = context.flags.unverify
46
+
47
+ const notify = notifyOption.set(context.flags.notify, context.flags['no-notify'])
48
+ const notificationStatus = (notify) ? 'enabled' : 'disabled'
38
49
 
39
50
  if (user && file) {
40
51
  throw new Error('Either --user USER or --infile must be passed, but not both')
@@ -43,7 +54,11 @@ async function run (context) {
43
54
  if (file) {
44
55
  const users = await readlines(file)
45
56
  const response = await skynet.bulkSuspendUsers(users.join(), notes, category, notify, force)
46
- cli.log(response)
57
+ cli.log(`${response}. Notification ${notificationStatus}`)
58
+
59
+ if (unverify) {
60
+ users.forEach(item => unverifyUser(api, item))
61
+ }
47
62
  } else {
48
63
  if (!user) {
49
64
  throw new Error('Required flag: --user USER or --infile FILE')
@@ -51,7 +66,11 @@ async function run (context) {
51
66
 
52
67
  let response = await skynet.suspendUser(user, notes, category, notify, force)
53
68
  response = JSON.parse(response)
54
- cli.log(`${response.status}. ${response.message}`)
69
+ cli.log(`${response.status}. ${response.message}. Notification ${notificationStatus}`)
70
+
71
+ if (unverify) {
72
+ unverifyUser(api, user)
73
+ }
55
74
  }
56
75
  }
57
76
 
@@ -67,7 +86,9 @@ module.exports = {
67
86
  { name: 'category', char: 'c', description: 'suspension category', hasValue: true, required: true },
68
87
  { name: 'notes', char: 'n', description: 'suspend notes', hasValue: true, required: true },
69
88
  { name: 'bypass', description: 'bypass the whitelist', hasValue: false, required: false },
70
- { name: 'no-notify', description: 'skip user suspension email notification', hasValue: false, required: false }
89
+ { name: 'no-notify', description: 'skip user suspension email notification', hasValue: false, required: false },
90
+ { name: 'notify', description: 'send user suspension email notification', hasValue: false, required: false },
91
+ { name: 'unverify', description: 'unverifies a user account, removes all billing info', hasValue: false, required: false }
71
92
  ],
72
93
  run: command(run)
73
94
  }
package/lib/heroku.js ADDED
@@ -0,0 +1,30 @@
1
+ 'use restrict'
2
+
3
+ const got = require('got')
4
+ const apiHost = 'https://api.heroku.com'
5
+ const qs = require('querystring')
6
+
7
+ module.exports = class HerokuAPI {
8
+ constructor (token) {
9
+ this.token = token
10
+ }
11
+
12
+ request (url, options = {}) {
13
+ options.headers = Object.assign({
14
+ Authorization: `Bearer ${this.token}`,
15
+ Accept: 'application/json',
16
+ 'Content-type': 'application/x-www-form-urlencoded',
17
+ 'X-Heroku-Sudo': 'true'
18
+ })
19
+
20
+ return got(apiHost + url, options).then(res => 'done').catch(exception => 'failed')
21
+ }
22
+
23
+ unverifyUser (user) {
24
+ return this.request(`/admin/users/payment-method?${user}`, {
25
+ method: 'delete',
26
+ body: qs.stringify({ user }),
27
+ json: false
28
+ })
29
+ }
30
+ }
@@ -0,0 +1,24 @@
1
+ 'use strict'
2
+
3
+ exports.set = set
4
+
5
+ function set (notifyFlag, noNotifyFlag) {
6
+ let notify = true
7
+ if (process.env.SKYNET_NOTIFICATION && process.env.SKYNET_NOTIFICATION === 'false') {
8
+ notify = false
9
+ }
10
+
11
+ if (notifyFlag && noNotifyFlag) {
12
+ throw new Error('Flag --notify and --no-notify could not use together')
13
+ }
14
+
15
+ if (noNotifyFlag) {
16
+ notify = false
17
+ }
18
+
19
+ if (notifyFlag) {
20
+ notify = true
21
+ }
22
+
23
+ return notify
24
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@heroku/skynet",
3
- "version": "1.6.16",
3
+ "version": "1.6.18",
4
4
  "description": "use Skynet from Heroku CLI",
5
5
  "main": "index.js",
6
6
  "author": "Bob Argenbright @byt3smith",