@heroku/skynet 1.6.1 → 1.6.3

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.
package/README.md CHANGED
@@ -13,15 +13,36 @@ heroku plugins:install heroku-skynet-cli
13
13
  - Change directories into the cloned repository
14
14
  - Link the plugin with `heroku plugins:link .`
15
15
 
16
+ ### Manual testing
17
+
18
+ 1. Make sure your staging account is setup: https://github.com/heroku/engineering-docs/blob/master/guides/staging-account-setup.md
19
+ 1. Get someone to add you to the `heroku-security` team/org in [staging](https://dashboard-api-staging.herokuapp.com/teams/heroku-security/access)
20
+ 1. Make sure you have the latest ion-client installed:
21
+
22
+ ```
23
+ gem install ion-client
24
+ ```
25
+
26
+ If you get permissions errors against packagecloud, visit https://gemgate-heroku-internal-gems.herokuapp.com/setup-instructions
27
+
28
+
29
+ In skynet-cli directory, use the following:
30
+
31
+ ```
32
+ heroku plugins:link .
33
+ export SKYNET_HOST=https://heroku-skynet-staging.herokuapp.com
34
+ cloud staging
35
+ heroku login # login to the staging cloud via the cli
36
+ heroku skynet:<cmd>
37
+ ```
38
+
16
39
  ### Publishing to `npm`
17
40
  1. Send an email to `heroku-help@salesforce.com` requesting access to @heroku on npm. Include your npm username (https://www.npmjs.com/)
18
41
 
19
- 1. Install by running `npm install np`
20
-
21
42
  1. Publish the package:
22
43
 
23
44
  1. cd into the root of the plugin
24
- 1. Run `np`
45
+ 1. Run `npm run release`
25
46
  Note: You will get an error because np attempts to commit to master the
26
47
  updated version in the package.json
27
48
  Open a pr manually on a separate branch to resolve
@@ -0,0 +1,21 @@
1
+ let cli = require('heroku-cli-util')
2
+ let command = require('../../lib/command')
3
+ let SkynetAPI = require('../../lib/skynet')
4
+
5
+ async function run (context) {
6
+ const skynet = new SkynetAPI(context.auth.password)
7
+ await cli.action(`adding new category: ${cli.color.cyan(context.flags.category)}`, skynet.addCategory(context.flags.category, context.flags.description))
8
+ }
9
+
10
+ module.exports = {
11
+ topic: 'skynet',
12
+ command: 'categories:add',
13
+ description: 'adds a value to suspension categories',
14
+ help: `Examples:
15
+ $ heroku sudo skynet:categories:add -c new-category -d "this is a new category"`,
16
+ flags: [
17
+ { name: 'category', char: 'c', description: 'new category value', hasValue: true, required: true },
18
+ { name: 'description', char: 'd', description: 'new category description', hasValue: true, required: true }
19
+ ],
20
+ run: command(run)
21
+ }
@@ -0,0 +1,20 @@
1
+ let cli = require('heroku-cli-util')
2
+ let command = require('../../lib/command')
3
+ let SkynetAPI = require('../../lib/skynet')
4
+
5
+ async function run (context) {
6
+ const skynet = new SkynetAPI(context.auth.password)
7
+ await cli.action(`removing ${cli.color.cyan(context.flags.category)} from suspension categories`, skynet.removeCategory(context.flags.category))
8
+ }
9
+
10
+ module.exports = {
11
+ topic: 'skynet',
12
+ command: 'categories:remove',
13
+ description: 'removes a value from suspension categories',
14
+ help: `Examples:
15
+ $ heroku sudo skynet:categories:remove -c test-category`,
16
+ flags: [
17
+ { name: 'category', char: 'c', description: 'category to remove', hasValue: true, required: true }
18
+ ],
19
+ run: command(run)
20
+ }
@@ -1,12 +1,12 @@
1
1
  let cli = require('heroku-cli-util')
2
- let co = require('co')
2
+ let command = require('../lib/command')
3
3
  let sudo = require('../lib/sudo')
4
4
  let SkynetAPI = require('../lib/skynet')
5
5
 
6
- function * run (context) {
6
+ async function run (context) {
7
7
  sudo()
8
8
  const skynet = new SkynetAPI(context.auth.password)
9
- let response = yield skynet.categories()
9
+ let response = await skynet.categories()
10
10
  response = JSON.parse(response)
11
11
  cli.table(response, {
12
12
  columns: [
@@ -23,5 +23,5 @@ module.exports = {
23
23
  help: `Examples:
24
24
  $ heroku skynet:categories`,
25
25
  flags: [],
26
- run: cli.command(co.wrap(run))
26
+ run: command(run)
27
27
  }
@@ -1,5 +1,5 @@
1
1
  let cli = require('heroku-cli-util')
2
- let co = require('co')
2
+ let command = require('../lib/command')
3
3
  let sudo = require('../lib/sudo')
4
4
  let SkynetAPI = require('../lib/skynet')
5
5
 
@@ -26,7 +26,7 @@ function readlines (file) {
26
26
  })
27
27
  }
28
28
 
29
- function * run (context) {
29
+ async function run (context) {
30
30
  sudo()
31
31
  const skynet = new SkynetAPI(context.auth.password)
32
32
  let user = context.flags.user || process.env.HEROKU_USER
@@ -40,14 +40,14 @@ function * run (context) {
40
40
  }
41
41
 
42
42
  if (file) {
43
- let users = yield readlines(file)
44
- yield cli.action(`bulk deprovisioning for ${cli.color.cyan(users.length)} users`, skynet.bulkDeprovision(users.join(), notes, category))
43
+ let users = await readlines(file)
44
+ await cli.action(`bulk deprovisioning for ${cli.color.cyan(users.length)} users`, skynet.bulkDeprovision(users.join(), notes, category))
45
45
  } else {
46
46
  if (!user) {
47
47
  throw new Error('Required flag: --user USER or --infile FILE')
48
48
  }
49
49
 
50
- let response = yield cli.action(`deprovisioning ${cli.color.cyan(user)}`, skynet.deprovision(user, notes, category, force))
50
+ let response = await cli.action(`deprovisioning ${cli.color.cyan(user)}`, skynet.deprovision(user, notes, category, force))
51
51
  response = JSON.parse(response)
52
52
  cli.log(`${response.status}. ${response.message}`)
53
53
  }
@@ -66,5 +66,5 @@ module.exports = {
66
66
  { name: 'notes', char: 'n', description: 'suspend notes', hasValue: true, required: true },
67
67
  { name: 'bypass', description: 'bypass the whitelist', hasValue: false, required: false }
68
68
  ],
69
- run: cli.command(co.wrap(run))
69
+ run: command(run)
70
70
  }
@@ -1,5 +1,5 @@
1
1
  let cli = require('heroku-cli-util')
2
- let co = require('co')
2
+ let command = require('../../lib/command')
3
3
  let sudo = require('../../lib/sudo')
4
4
  let SkynetAPI = require('../../lib/skynet')
5
5
 
@@ -26,7 +26,7 @@ function readlines (file) {
26
26
  })
27
27
  }
28
28
 
29
- function * run (context) {
29
+ async function run (context) {
30
30
  sudo()
31
31
  const skynet = new SkynetAPI(context.auth.password)
32
32
  let app = context.flags.app
@@ -40,14 +40,14 @@ function * run (context) {
40
40
  }
41
41
 
42
42
  if (file) {
43
- let apps = yield readlines(file)
44
- yield cli.action(`bulk app-owner suspension for ${cli.color.cyan(apps.length)} apps.`, skynet.bulkSuspendAppOwner(apps.join(), notes, category))
43
+ let apps = await readlines(file)
44
+ await cli.action(`bulk app-owner suspension for ${cli.color.cyan(apps.length)} apps.`, skynet.bulkSuspendAppOwner(apps.join(), notes, category))
45
45
  } else {
46
46
  if (!app) {
47
47
  throw new Error('Required flag: --owner OWNER or --infile FILE')
48
48
  }
49
49
 
50
- let response = yield cli.action(`suspending the owner of ${cli.color.cyan(app)}`, skynet.suspendAppOwner(app, notes, category, force))
50
+ let response = await cli.action(`suspending the owner of ${cli.color.cyan(app)}`, skynet.suspendAppOwner(app, notes, category, force))
51
51
  response = JSON.parse(response)
52
52
  cli.log(`${response.status}. ${response.message}`)
53
53
  }
@@ -66,5 +66,5 @@ module.exports = {
66
66
  { name: 'notes', char: 'n', description: 'suspend notes', hasValue: true, required: true },
67
67
  { name: 'bypass', description: 'bypass the whitelist', hasValue: false, required: false }
68
68
  ],
69
- run: cli.command(co.wrap(run))
69
+ run: command(run)
70
70
  }
@@ -1,12 +1,12 @@
1
1
  let cli = require('heroku-cli-util')
2
- let co = require('co')
2
+ let command = require('../../lib/command')
3
3
  let sudo = require('../../lib/sudo')
4
4
  let SkynetAPI = require('../../lib/skynet')
5
5
 
6
- function * run (context) {
6
+ async function run (context) {
7
7
  sudo()
8
8
  const skynet = new SkynetAPI(context.auth.password)
9
- let response = yield skynet.suspendApp(
9
+ let response = await skynet.suspendApp(
10
10
  context.flags.app,
11
11
  context.flags.notes,
12
12
  context.flags.category,
@@ -53,5 +53,5 @@ module.exports = {
53
53
  required: false
54
54
  }
55
55
  ],
56
- run: cli.command(co.wrap(run))
56
+ run: command(run)
57
57
  }
@@ -1,5 +1,5 @@
1
1
  let cli = require('heroku-cli-util')
2
- let co = require('co')
2
+ let command = require('../../lib/command')
3
3
  let sudo = require('../../lib/sudo')
4
4
  let SkynetAPI = require('../../lib/skynet')
5
5
 
@@ -26,7 +26,7 @@ function readlines (file) {
26
26
  })
27
27
  }
28
28
 
29
- function * run (context) {
29
+ async function run (context) {
30
30
  sudo()
31
31
  const skynet = new SkynetAPI(context.auth.password)
32
32
  let user = context.flags.user || process.env.HEROKU_USER
@@ -41,14 +41,14 @@ function * run (context) {
41
41
  }
42
42
 
43
43
  if (file) {
44
- let users = yield readlines(file)
45
- yield cli.action(`bulk user suspension for ${cli.color.cyan(users.length)} users.`, skynet.bulkSuspendUsers(users.join(), notes, category))
44
+ let users = await readlines(file)
45
+ await cli.action(`bulk user suspension for ${cli.color.cyan(users.length)} users.`, skynet.bulkSuspendUsers(users.join(), notes, category))
46
46
  } else {
47
47
  if (!user) {
48
48
  throw new Error('Required flag: --user USER or --infile FILE')
49
49
  }
50
50
 
51
- let response = yield cli.action(`suspending ${cli.color.cyan(user)}`, skynet.suspendUser(user, notes, category, notify, force))
51
+ let response = await cli.action(`suspending ${cli.color.cyan(user)}`, skynet.suspendUser(user, notes, category, notify, force))
52
52
  response = JSON.parse(response)
53
53
  cli.log(`${response.status}. ${response.message}`)
54
54
  }
@@ -68,5 +68,5 @@ module.exports = {
68
68
  { name: 'bypass', description: 'bypass the whitelist', hasValue: false, required: false },
69
69
  { name: 'no-notify', description: 'skip user suspension email notification', hasValue: false, required: false }
70
70
  ],
71
- run: cli.command(co.wrap(run))
71
+ run: command(run)
72
72
  }
@@ -1,12 +1,12 @@
1
1
  let cli = require('heroku-cli-util')
2
- let co = require('co')
2
+ let command = require('../../lib/command')
3
3
  let sudo = require('../../lib/sudo')
4
4
  let SkynetAPI = require('../../lib/skynet')
5
5
 
6
- function * run (context) {
6
+ async function run (context) {
7
7
  sudo()
8
8
  const skynet = new SkynetAPI(context.auth.password)
9
- let response = yield skynet.unsuspendApp(context.flags.app, context.flags.notes)
9
+ let response = await skynet.unsuspendApp(context.flags.app, context.flags.notes)
10
10
  response = JSON.parse(response)
11
11
  cli.log(`suspending...${cli.color.cyan(response.status)}.\n${response.message}`)
12
12
  }
@@ -20,5 +20,5 @@ module.exports = {
20
20
  flags: [
21
21
  { name: 'app', char: 'a', description: 'app to unsuspend', hasValue: true, required: true }
22
22
  ],
23
- run: cli.command(co.wrap(run))
23
+ run: command(run)
24
24
  }
@@ -1,14 +1,14 @@
1
1
  let cli = require('heroku-cli-util')
2
- let co = require('co')
2
+ let command = require('../../lib/command')
3
3
  let sudo = require('../../lib/sudo')
4
4
  let SkynetAPI = require('../../lib/skynet')
5
5
 
6
- function * run (context) {
6
+ async function run (context) {
7
7
  sudo()
8
8
  const skynet = new SkynetAPI(context.auth.password)
9
9
  let user = context.flags.user || process.env.HEROKU_USER
10
10
 
11
- let response = yield cli.action(`unsuspending ${cli.color.cyan(user)}`, skynet.unsuspendUser(user))
11
+ let response = await cli.action(`unsuspending ${cli.color.cyan(user)}`, skynet.unsuspendUser(user))
12
12
  response = JSON.parse(response)
13
13
  cli.log(`${response.status}. ${response.message}`)
14
14
  }
@@ -22,5 +22,5 @@ module.exports = {
22
22
  flags: [
23
23
  { name: 'user', char: 'u', description: 'user to unsuspend', hasValue: true }
24
24
  ],
25
- run: cli.command(co.wrap(run))
25
+ run: command(run)
26
26
  }
@@ -1,10 +1,10 @@
1
1
  let cli = require('heroku-cli-util')
2
- let co = require('co')
2
+ let command = require('../../lib/command')
3
3
  let SkynetAPI = require('../../lib/skynet')
4
4
 
5
- function * run (context) {
5
+ async function run (context) {
6
6
  const skynet = new SkynetAPI(context.auth.password)
7
- yield cli.action(`adding ${cli.color.cyan(context.flags.userpass)} to ${cli.color.cyan(context.flags.user)}`, skynet.addUserpass(context.flags.user, context.flags.flag))
7
+ await cli.action(`adding ${cli.color.cyan(context.flags.userpass)} to ${cli.color.cyan(context.flags.user)}`, skynet.addUserpass(context.flags.user, context.flags.flag))
8
8
  }
9
9
 
10
10
  module.exports = {
@@ -17,5 +17,5 @@ module.exports = {
17
17
  { name: 'user', char: 'u', description: 'user to apply userpass flag to', hasValue: true, required: true },
18
18
  { name: 'flag', char: 'f', description: 'flag to add to the given user', hasValue: true, required: true }
19
19
  ],
20
- run: cli.command(co.wrap(run))
20
+ run: command(run)
21
21
  }
@@ -1,10 +1,10 @@
1
1
  let cli = require('heroku-cli-util')
2
- let co = require('co')
2
+ let command = require('../../lib/command')
3
3
  let SkynetAPI = require('../../lib/skynet')
4
4
 
5
- function * run (context) {
5
+ async function run (context) {
6
6
  const skynet = new SkynetAPI(context.auth.password)
7
- yield cli.action(`removing ${cli.color.cyan(context.flags.userpass)} from ${cli.color.cyan(context.flags.user)}`, skynet.removeUserpass(context.flags.user, context.flags.flag))
7
+ await cli.action(`removing ${cli.color.cyan(context.flags.userpass)} from ${cli.color.cyan(context.flags.user)}`, skynet.removeUserpass(context.flags.user, context.flags.flag))
8
8
  }
9
9
 
10
10
  module.exports = {
@@ -17,5 +17,5 @@ module.exports = {
17
17
  { name: 'user', char: 'u', description: 'user to remove user_pass from', hasValue: true, required: true },
18
18
  { name: 'flag', char: 'f', description: 'flag to remove from given user', hasValue: true, required: true }
19
19
  ],
20
- run: cli.command(co.wrap(run))
20
+ run: command(run)
21
21
  }
@@ -1,10 +1,10 @@
1
1
  let cli = require('heroku-cli-util')
2
- let co = require('co')
2
+ let command = require('../../lib/command')
3
3
  let SkynetAPI = require('../../lib/skynet')
4
4
 
5
- function * run (context) {
5
+ async function run (context) {
6
6
  const skynet = new SkynetAPI(context.auth.password)
7
- yield cli.action(
7
+ await cli.action(
8
8
  `adding ${cli.color.cyan(
9
9
  context.flags.value
10
10
  )} to whitelist with ${cli.color.cyan(context.flags.notes)}`,
@@ -34,5 +34,5 @@ module.exports = {
34
34
  required: false
35
35
  }
36
36
  ],
37
- run: cli.command(co.wrap(run))
37
+ run: command(run)
38
38
  }
@@ -1,10 +1,10 @@
1
1
  let cli = require('heroku-cli-util')
2
- let co = require('co')
2
+ let command = require('../../lib/command')
3
3
  let SkynetAPI = require('../../lib/skynet')
4
4
 
5
- function * run (context) {
5
+ async function run (context) {
6
6
  const skynet = new SkynetAPI(context.auth.password)
7
- yield cli.action(
7
+ await cli.action(
8
8
  `removing ${cli.color.cyan(context.flags.value)} from whitelist`,
9
9
  skynet.removeWhitelist(context.flags.value)
10
10
  )
@@ -25,5 +25,5 @@ module.exports = {
25
25
  required: true
26
26
  }
27
27
  ],
28
- run: cli.command(co.wrap(run))
28
+ run: command(run)
29
29
  }
package/index.js CHANGED
@@ -14,6 +14,8 @@ exports.commands = [
14
14
  require('./commands/unsuspend/user.js'),
15
15
  require('./commands/deprovision.js'),
16
16
  require('./commands/categories.js'),
17
+ require('./commands/categories/add.js'),
18
+ require('./commands/categories/remove.js'),
17
19
  require('./commands/whitelist/add.js'),
18
20
  require('./commands/whitelist/remove.js')
19
21
  ]
package/lib/command.js ADDED
@@ -0,0 +1,13 @@
1
+ let cli = require('heroku-cli-util')
2
+
3
+ module.exports = fn =>
4
+ cli.command((context, client) =>
5
+ fn(context, client).catch(err => {
6
+ if (err.body) {
7
+ console.log(JSON.stringify(err.body))
8
+ } else {
9
+ console.log(err)
10
+ }
11
+ throw err
12
+ })
13
+ )
package/lib/skynet.js CHANGED
@@ -21,12 +21,10 @@ module.exports = class SkynetAPI {
21
21
  'User-Agent': this.version
22
22
  })
23
23
 
24
- if (['POST', 'PATCH', 'DELETE'].includes(options.method)) {
25
- options.headers['Content-type'] = 'application/x-www-form-urlencoded'
24
+ if (options.form) {
25
+ options.headers['Content-Type'] = 'application/x-www-form-urlencoded'
26
26
  }
27
27
 
28
- options.json = false
29
-
30
28
  return cli.got(SKYNET_BASE_URL + url, options).then(res => res.body)
31
29
  }
32
30
 
@@ -44,7 +42,8 @@ module.exports = class SkynetAPI {
44
42
 
45
43
  return this.request(`/whitelist`, {
46
44
  method: 'POST',
47
- body: qs.stringify(body)
45
+ body: qs.stringify(body),
46
+ form: true
48
47
  })
49
48
  }
50
49
 
@@ -62,7 +61,8 @@ module.exports = class SkynetAPI {
62
61
 
63
62
  return this.request(`/userpass/remove`, {
64
63
  method: 'POST',
65
- body: qs.stringify(body)
64
+ body: qs.stringify(body),
65
+ form: true
66
66
  })
67
67
  }
68
68
 
@@ -74,7 +74,8 @@ module.exports = class SkynetAPI {
74
74
 
75
75
  return this.request(`/userpass/add`, {
76
76
  method: 'POST',
77
- body: qs.stringify(body)
77
+ body: qs.stringify(body),
78
+ form: true
78
79
  })
79
80
  }
80
81
 
@@ -89,7 +90,8 @@ module.exports = class SkynetAPI {
89
90
 
90
91
  return this.request('/suspend/app-owner', {
91
92
  method: 'POST',
92
- body: qs.stringify(body)
93
+ body: qs.stringify(body),
94
+ form: true
93
95
  })
94
96
  }
95
97
 
@@ -104,7 +106,8 @@ module.exports = class SkynetAPI {
104
106
 
105
107
  return this.request('/suspend/app', {
106
108
  method: 'POST',
107
- body: qs.stringify(body)
109
+ body: qs.stringify(body),
110
+ form: true
108
111
  })
109
112
  }
110
113
 
@@ -126,7 +129,8 @@ module.exports = class SkynetAPI {
126
129
 
127
130
  return this.request(`/suspend/user`, {
128
131
  method: 'POST',
129
- body: qs.stringify(body)
132
+ body: qs.stringify(body),
133
+ form: true
130
134
  })
131
135
  }
132
136
 
@@ -147,7 +151,8 @@ module.exports = class SkynetAPI {
147
151
 
148
152
  return this.request(`/suspend/user`, {
149
153
  method: 'POST',
150
- body: qs.stringify(body)
154
+ body: qs.stringify(body),
155
+ form: true
151
156
  })
152
157
  }
153
158
 
@@ -162,7 +167,8 @@ module.exports = class SkynetAPI {
162
167
 
163
168
  return this.request(`/suspend/app-owner`, {
164
169
  method: 'POST',
165
- body: qs.stringify(body)
170
+ body: qs.stringify(body),
171
+ form: true
166
172
  })
167
173
  }
168
174
 
@@ -177,7 +183,8 @@ module.exports = class SkynetAPI {
177
183
 
178
184
  return this.request(`/deprovision`, {
179
185
  method: 'POST',
180
- body: qs.stringify(body)
186
+ body: qs.stringify(body),
187
+ form: true
181
188
  })
182
189
  }
183
190
 
@@ -192,7 +199,27 @@ module.exports = class SkynetAPI {
192
199
 
193
200
  return this.request(`/deprovision`, {
194
201
  method: 'POST',
195
- body: qs.stringify(body)
202
+ body: qs.stringify(body),
203
+ form: true
204
+ })
205
+ }
206
+
207
+ addCategory (category, description) {
208
+ let body = {
209
+ category: category,
210
+ description: description
211
+ }
212
+
213
+ return this.request(`/categories`, {
214
+ method: 'POST',
215
+ body: JSON.stringify(body),
216
+ json: true
217
+ })
218
+ }
219
+
220
+ removeCategory (category) {
221
+ return this.request(`/categories/${category}`, {
222
+ method: 'DELETE'
196
223
  })
197
224
  }
198
225
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@heroku/skynet",
3
- "version": "1.6.1",
3
+ "version": "1.6.3",
4
4
  "description": "use Skynet from Heroku CLI",
5
5
  "main": "index.js",
6
6
  "author": "Bob Argenbright @byt3smith",
@@ -17,18 +17,19 @@
17
17
  "/commands"
18
18
  ],
19
19
  "dependencies": {
20
- "co": "^4.6.0",
21
20
  "heroku-cli-util": "~6.2.12",
22
21
  "split": "^1.0.0"
23
22
  },
24
23
  "devDependencies": {
25
24
  "mocha": "^3.4.2",
26
25
  "mockdate": "^2.0.1",
27
- "nock": "^9.0.13",
26
+ "nock": "~9.0.13",
27
+ "np": "^3.1.0",
28
28
  "standard": "^12.0.1",
29
29
  "unexpected": "^10.29.0"
30
30
  },
31
31
  "scripts": {
32
- "test": "mocha && standard"
32
+ "test": "mocha && standard",
33
+ "release": "np --no-yarn"
33
34
  }
34
35
  }