1 | #! /usr/bin/env node
|
2 |
|
3 | 'use strict'
|
4 |
|
5 | const prompt = require('cli-prompt')
|
6 |
|
7 | let api
|
8 |
|
9 | try {
|
10 | api = require('@dadi/api')
|
11 | } catch (err) {
|
12 | api = require(process.cwd())
|
13 | }
|
14 |
|
15 |
|
16 | delete console.log
|
17 |
|
18 | console.log()
|
19 | console.log('==================================')
|
20 | console.log(' DADI API Client Record Generator ')
|
21 | console.log('==================================')
|
22 | console.log()
|
23 |
|
24 | prompt.multi([
|
25 | {
|
26 | label: '-> Client identifier',
|
27 | key: 'clientId',
|
28 | default: 'api-client'
|
29 | },
|
30 | {
|
31 | label: '-> Secret access key',
|
32 | key: 'secret',
|
33 | default: 'client-secret'
|
34 | },
|
35 | {
|
36 | label: '-> Access type (admin, user)',
|
37 | key: 'accessType',
|
38 | default: 'user'
|
39 | },
|
40 | {
|
41 | label: '(!) Is this ok?',
|
42 | key: 'confirm',
|
43 | type: 'boolean'
|
44 | }
|
45 | ], options => {
|
46 | if (!options.confirm) {
|
47 | return process.exit(0)
|
48 | }
|
49 |
|
50 | delete options.confirm
|
51 |
|
52 | api.ACL.client.create(options, {
|
53 | allowAccessType: true
|
54 | }).then(response => {
|
55 | console.log()
|
56 | console.log('(*) Client created successfully:')
|
57 | console.log()
|
58 | console.log(response)
|
59 | console.log()
|
60 |
|
61 | process.exit(0)
|
62 | }).catch(error => {
|
63 | if (error.message === 'CLIENT_EXISTS') {
|
64 | console.log(`(x) The identifier ${options.clientId} already exists. Exiting...`)
|
65 | } else {
|
66 | console.log('(x) An unexpected error occurred:', error.message)
|
67 | }
|
68 |
|
69 | process.exit(0)
|
70 | })
|
71 | })
|